overloading parameters concept

REQUIREMENTS :
Class Rectangle

------------------------------------------------------

-double x

-double y

-double diagonal // diagonal = sqrt(x*x + y*y)

-double area // area = x * y

-double perimeter // perimeter = 2. * x + 2. * y

-string color

------------------------------------------------------

+void setX(double) //sets member x and calls calcRect()

+void setY(double) //sets member y and calls calcRect()

+void setColor(string) //sets member color

+Rectangle() //Constructor sets all members to 0. and calls calcRect()

+Rectangle(double, double, string) //Overloaded Constructor sets x y color passed as arguments

+~Rectangle() //destructor the outputs “GoodBye” and values of x and y

+double getX(void) //returns x

+double getY(void)//returns x

+double getDiagonal(void) //returns diagonal

+double getArea(void) //returns Area

+double getPerimeter //returns perimeter

+string getColor(void) //returns color

+void calcRect(void) // calculates area, diagonal, and perimeter

+void printRect(void) // prints all values of the rectangle

-----------------------------------------------------------------------

Run it using the following main routine

#include <iostream>
#include <string>
#include <cmath>

Using namespace std;

Int main(void)
{
Rectangle a;
Rectangle b(1., 2., “Red”);

a.setX(4.); //set value of x
a.setY(6.); //set value of y
a.setColor(“Green”); //set value of color

a.printRect();
b.printRect();
return 0;

}






Here is my code




#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Rectangle
{
double x,y,diagonal,area,perimeter;
string color;
public:
void setX(double a)
{
a=x;
calcRect();
}
void setY(double b)
{
b=y;
calcRect();
}
void setColor(string col)
{
color = col;
}
~Rectangle()
{
cout<<"goodbye";
cout<<x<<y;
}
double getX(void)
{javascript:tx('output')


return x;
}
double getY(void)
{
return y;
}
double getDiagonal(void)
{
return diagonal;
}
double getArea(void)
{
return area;
}
double getPerimeter(void)
{
return perimeter;
}
string getcolor(void)
{
return(color);
}
Rectangle()
{
double x=0,y=0,diagonal=0,area=0,perimeter=0;
string color = "NULL";
}
Rectangle(double a,double b,string col)
{
x=a;
y=b;
col=color;
}
void calcRect(void)
{
area = x*y;
diagonal = sqrt(x*x+y*y);
perimeter = 2*x+2*y;
}
void printRect(void)
{
cout<<x<<y;
cout<<"diagonal of the rectanglle is "<<diagonal;
cout<<"area of the rectangle is "<<area;
cout<<"perimeter of the rectangle is "<<perimeter;
}
};
int main(void)
{
Rectangle a;
Rectangle b(1,2,"RED");
a.setX(4);
a.setY(6);
a.setColor("GREEN");
a.printRect();
b.printRect();
return 0;
}
closed account (3qX21hU5)
This thread should be moved to the beginners section of the forum since this is a programming questionrrelated to c++ also please use codetags.
And actually ask a question.
Probably trying to cheat on a test.
hey i am not cheating on any test rather trying to solve one problem given to me by my sis..... so please don't blame without knowing the reason... all the code was written by me... but i am badly in need of the result...
@zereo i already tried posting in the beginner's section..... but there was no response ... so i thought some one would help me out
@residentbiscuit
sir, the question is does my code fit into my requirements?? or have i gone wrong in my code..... please do check....
Topic archived. No new replies allowed.