Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8672395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:11:35+00:00 2026-06-12T19:11:35+00:00

I am designing and implementing a class where I have to include two initialization

  • 0

I am designing and implementing a class where I have to include two initialization operations using the class’s constructors. One is the default initialization (that I think I have done properly) and the other one is the initialization from the user inputs which is supposed to be in the constructor itself(where I still have trouble to write it). I am using separate compilation, so I show the code from the file with the class and the main function from the .cpp file. I am using Dev-C++ and part of the code is below. Thanks for your help.

#include <iostream>
#include <exception>
#include <math.h>


///#include "Exception.h"


#ifndef TRIANGLE_H
#define TRIANGLE_H

using namespace std;

class Triangle

{
   private:
       double side1;
       double side2;
       double side3;

       double angle_side1_side2;
       double angle_side1_side3;
       double angle_side2_side3;


  public:
    //default constructor with default initialization   
    Triangle::Triangle(): side1(0), side2(0), side3(0), angle_side1_side2(0), angle_side1_side3(0), angle_side2_side3(0)
       {

       }

//constructor with user inputs, but I know there is something wrong...
Triangle::Triangle(double s1, double s2, double s3)
  { 
   cout<<"enter your own values:"<<endl;
   cin>>s1>>s2>>s3;
   side1=s1;
   side2=s2;
   side3=s3;
   cout<<"the current lengths of sides of your triangle are: " <<endl;
  }

 double display_triangle_sides()
   {    
        cout<<side1<<" "<<side2<<" "<<side3<<" ";                               

   }

 double display_triangle_Area()
   {    
        double S=(side1+side2+side3)/2; //semiperimeter
        double T=sqrt(S*(S-side1)*(S-side2)*(S-side3));      //Heron formula to calculate Area of triangle

       return T;
   }
};

endif


     //*****************************main function below************************

 #include <iostream>
 #include <exception>



 #include "Untitled1.h"


 using namespace std;

 int main()
 {


  Triangle tr;


  cout<<" length of each side of the current triangle : ";
  tr.display_triangle_sides();  //I want to show here the values entered by the users



  cout<<endl<<"Here is the Area of the current triangle : " <<    tr.display_triangle_Area()<<endl;
  cout<<"type of triangle:"<<endl;
  tr.Type_of_Triangle();


   system("Pause");
   return 0;
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:11:37+00:00Added an answer on June 12, 2026 at 7:11 pm

    A constructor where the user has to enter values manually is appalling design. Are you sure you have been told to do that?

    The correct way to do this is something like this

    class Triangle
    {
        Triangle::Triangle(): side1(0), side2(0), side3(0)
        {
        }
    
        Triangle::Triangle(double s1, double s2, double s3) : side1(s1), side2(s2), side3(s3)
        { 
        }
    
        ...
    
    };
    
    int main()
    {
       double s1, s2, s3;
       cin >> s1 >> s2 >> s3;
       Triangle t(s1, s2, s3);
    
       ...
    
    }
    

    In order words you enter values in the main function, and then you pass the values to the constructor.

    The reason that your way of doing things is so bad is that it makes your Triangle constructor only useable in the specific context of the program you are writing now. You should design your classes so that they are reusable in different programs. This is probably a hard thing for you to appreciate now when you’re just beginning, since you are focused on just getting one program to work, not thinking about programs you might write in the future.

    If you really have been told that you must do this, then you are being taught by an incompetant.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: StructureMap singleton usage (A class implementing two interface) I'm currently designing a
I'm implementing enumeration using a base class that defines a variety of methods. The
Is it possible in C# to have a class that implement an interface that
I have an abstract immutable base class that defines enforces child classes to be
Suppose I have two Classes, A and B. The A class is defined as
I have a system that performs operations on lots of Things , these can
I'm designing a class library for discrete mathematics, and I can't think of a
Aloha! I have a role that I'm busy defining in a Moose class called
One of the struggles I have as android development newbie is that my classes
I'm designing and implementing .Net ORM that must support both Azure Storage (tables, queues,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.