Sunday, July 12, 2009

C++ Help Please!?

So i have to design a class and have it contain this stuff, and I am having a hard time figuring it out. Any ideas?


I have to take this class and I'm supposed to be able to implement the class and write a test program that creates two Rectangle objects. Assign width 5 and height 50 to the first object and width 3.5 and height 35.9 to the second object. Display the properties of both objects and find their areas and perimeters.





This is what I have so far, but I do not know how to implement the class with the given parameters:





#include %26lt;iostream%26gt;


using namespace std;





class Rectangle


{


public:


Rectangle():height(1),width(1){}


Rectangle(int h, int w):height(h),width(w){}


inline double getArea()const


{


return height * width;


}





inline double getPerimeter()const


{


return (height * 2.0) + (width * 2.0);


}





private:


double height;


double width;


};





Any help is appreciated.

C++ Help Please!?
i made some corrections





class Rectangle


{


public:


Rectangle()


{


hieght= 0;


width = 0;


}





Rectangle(double h, double w)


{


hieght = h;


width = w;


}





double getHieght() // retrive the hieght to print in main


{


return hieght;


}





double getWidth() // retrive the width to print in main


{


return width;


}





double getArea()const


{


return height * width;


}





double getPerimeter()


{


return ((length * 2) + (width * 2));


}





private:


double height;


double width;


};








secondly





in the main part





define two objects





Rectangle rectangle1;


Rectangle rectangle 2;





rectangle1 = new Rectangle(5,50);


rectangle1 = new Rectangle(3.5,35.9);








cout%26lt;%26lt;rectangle1.getPerimeter(); and so on....


cout%26lt;%26lt;rectangle2.getPerimeter(); .....





GOOD luck





note: I'm afrid i forgot some parantheses so please double check on them :)


No comments:

Post a Comment