By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,374 Members | 1,768 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,374 IT Pros & Developers. It's quick & easy.

Need help with hw...one by one

P: 1
Hi,

I am working on my homework...and I have to do

create a class where it can calculate the area of the rectangle while under these conditions..

1. limit the width and length ...under 20
2. use set_length, get_length, set_width, and so on..and have the user input the length and width value
3. after the calculation is done, I have to use the function draw to draw the rectangle with some sort of symbol such as +++ or ===




Thansk for your help..

edit: I think I did number 2 and 3 part...but..number 1 part....limiting the value under 20....hmmmm
here is my code




#include <iostream>
using namespace std;


class CRectangle {
int x, y;
public:
void set_values (int,int);
void set_length (int length) { this->itslength = length;}
int get_length () const { return this->itslength; }
void set_width (int width) { this->itswidth = width; }
int get_width () const { return this->itswidth; }
void DrawShape (int length, int width) const;

int area () {return (x*y);}
int perimeter () {return (2*(x+y));}
private:
int itslength;
int itswidth;
};

void CRectangle::set_values (int length, int width) {
x = length;
y = width;
};

void CRectangle::DrawShape (int length, int width) const
{
for (int i = 0; i<length; i++)
{
for (int j =0; j<width; j++)
cout << "*";
cout << endl;
}
}





int main () {
using namespace std;
int itslength, itswidth;

cout << "Please enter the width of the rectangle: ";
cin >> itslength;
cout << "Please enter the length of the rectangle: ";
cin >> itswidth;

CRectangle rect;

rect.set_values (itslength,itswidth);

cout << "area: " << rect.area();

cout << "Drawshape(): \n";
rect.DrawShape(itslength,itswidth);

return 0;
}
Apr 22 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.