does my coding complete with my requirements given

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;
}
Last edited on
Topic archived. No new replies allowed.