Needs help in constructor

Hi guys: I am trying to create two overloading methods one with two double and the other with two integer arguments to calcuate the area but getting error needs help Thanks.


#include<string>
#include<iostream>
using namespace test;
class square
      {
      public:
              double dlength;
              double dbreath;
              int    ilength;
              int    ibreath;
              square();
              void getArea(double, double);
              void getArea(int, int);            
      };
square::square()
{
                dlength = 0.00;
                dbreath = 0.00;
                ilength = 0;
                ibreath = 0;
}

void getArea(double dl, double db)
{
     dlength = dl;
     dbreath = db;
     cout << "Area of double values is==>" << dlength * dbreath;
}

void getArea(int il, int ib)
{
     ilength = il;
     ibreath = ib;
     cout << "Area of integer values is==>" << ilength * ibreath;
}

int main()
{
    square dsq(10.20, 12.20);
    dsq.getArea();  
    square isq(7, 6);
    isq.getArea();  
}
mustish1Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
evilrixConnect With a Mentor Senior Software Engineer (Avast)Commented:
Errors fixed, comments notate changes
#include<string>
#include<iostream>

//using namespace test;
using namespace std;

class square
      {
      public:
              double dlength;
              double dbreath;
              int    ilength;
              int    ibreath;

              //square();
              square(
               double dlength,
               double dbreath,
               int    ilength,
               int    ibreath
               );

              void getArea(double, double);
              void getArea(int, int);             
      };

//square::square()
square::square(
   double dlength = 0.0,
   double dbreath = 0.0,
   int    ilength = 0,
   int    ibreath = 0
   )
   : dlength(dlength)
   , dbreath(dbreath)
   , ilength(ilength)
   , ibreath(ibreath)
{
   //dlength = 0.00;
   //dbreath = 0.00;
   //ilength = 0;
   //ibreath = 0;
}

//void getArea(double dl, double db)
void square::getArea(double dl, double db) // should this be setArea?
{
     dlength = dl;
     dbreath = db;
     cout << "Area of double values is==>" << dlength * dbreath;
}

//void getArea(int il, int ib)
void square::getArea(int il, int ib) // should this be setArea?
{
     ilength = il;
     ibreath = ib;
     cout << "Area of integer values is==>" << ilength * ibreath;
}

int main()
{
    square dsq(10.20, 12.20);
    //dsq.getArea();  
    dsq.getArea(1.1,1.1);  
    square isq(7, 6);
    //isq.getArea();  
    isq.getArea(1,1);  
    //isq.getArea();  
    isq.getArea(1,1);  
}

Open in new window

0
 
Arthur_WoodCommented:
Is this C# or Java?  It sure looks like JAVA to me.

AW
0
 
mustish1Author Commented:
I'm sorry its a C++
0
 
phoffricCommented:
What error are you getting?
0
All Courses

From novice to tech pro — start learning today.