TheBigBossCJ
2010-04-03 03:44:24 UTC
The set_length() and set_width() functions should require the user to enter length or width data values greater than zero and less than or equal to 20.0. These functions should examine the data entered by the user, and accept the data only if it is in the specified range (0 < data <= 20.0). If the data is not in this range, the user should be reminded of the allowed data range and prompted to enter the data again. This cycle should repeat until the user enters a correct data value. This can be accomplished by using a do while loop in each set() function.
The get() functions should be declared using the const keyword to ensure that these functions can not change private member data of the rectangle class.
Add a draw() function to your rectangle class that draws a solid rectangle of the correct length and width. Since the length and width are floating point numbers, truncate the length and width values for the purpose of drawing the rectangle (for example, if length = 6.3 and width = 11.5, draw a rectangle that is 6 by 11 characters in size). Truncation can be achieved by converting the floating point value to an integer value. Use any character you like to draw the rectangle. Here is an example of a rectangle drawn with + signs:
+++++++++++++
+++++++++++++
+++++++++++++
+++++++++++++
Write a short demonstration program that uses the rectangle class you have created. The program should create a rectangle object, then prompt the user to enter new values for the length and width. Use the set() functions and the user’s entries to change the private data of the rectangle object you created. Use the functions perimeter() and area() to display their results. Finally, call the draw() function to display the resulting rectangle.
============
Code
#include
using namespace std;
class rectangle
{
private:
double length;
double width;
public:
void theLen(double length);
void theWid(double width);
double calculateArea ();
double calculatePerimeter();
};
void rectangle::theLen(double L)
{
length=L;
}
void rectangle::theWid(double W)
{
width=W;
}
double rectangle::calculateArea()
{
double A;
A=length*width;
return A;
}
double rectangle::calculatePerimeter()
{
double P;
P=(length+width)*2;
return P;
}
int main()
{
double length, Width;
rectangle objectX;
cout << "Enter The Length Of The Rectangle: ";
cin >> length;
objectX.theLen(length);
cout << "Enter The Width Of Rectangle: ";
cin >> Width;
objectX.theWid(Width);
cout <<"The area of the rectangle is : "<< objectX.calculateArea() << endl;
cout <<"The Perimeter is: " <
fflush(stdin);
cin.get();
return 0 ;
}
Problem is I cant figure out haw draw the rectangle nor get in truncate floating paoint value to an int???