473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Need help with hw...one by one

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
0 1608

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

Similar topics

0
by: Sofia | last post by:
My name is Sofia and I have for many years been running a personals site, together with my partner, on a non-profit basis. The site is currently not running due to us emigrating, but during its...
7
by: Mike Kamermans | last post by:
I hope someone can help me, because what I'm going through at the moment trying to edit XML documents is enough to make me want to never edit XML again. I'm looking for an XML editor that has a...
15
by: drdoubt | last post by:
using namespace std In my C++ program, even after applying , I need to use the std namespace with the scope resolution operator, like, std::cout, std::vector. This I found a little bit...
9
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
0
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.