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

Where to start

P: n/a
Don't know where to start

Problem:

Create a class Rectangle The class has attributes length and width, each of
which defaults to 1. It has member functions that calculate the perimeter
and the area of the rectangle. It has set and get function for both length
and width. The set functions should verify that length and width are each
floating point numbers larger than 0.0 and less than 20.0
Jul 22 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
David wrote:
Don't know where to start

.... an empty class will do fine....... ain't that straightforward ?!
empty class => add two attributes => add two methods => done.
Jul 22 '05 #2

P: n/a
In article <UQenc.419691$oR5.121352@pd7tw3no>, David wrote:
Don't know where to start

Problem:

Create a class Rectangle The class has attributes length and width, each of
which defaults to 1. It has member functions that calculate the perimeter
and the area of the rectangle. It has set and get function for both length
and width. The set functions should verify that length and width are each
floating point numbers larger than 0.0 and less than 20.0

[-]
class Rectangle {
/*
** The rest of your homework here
*/
};
Jul 22 '05 #3

P: n/a
David writes:
Don't know where to start

Create a class Rectangle The class has attributes length and width, each of which defaults to 1. It has member functions that calculate the perimeter
and the area of the rectangle. It has set and get function for both length
and width. The set functions should verify that length and width are each
floating point numbers larger than 0.0 and less than 20.0


Gee you missed a lot didn't you? Try this:

class Rectangle
{
public:
// prototypes of member functions go here
private:
// data go here
};
// functions go here. I think there are seven of them.

int main()
{
Rectangle rect(3.0, 4.0); /* rect is an *object* as
specified by the *class* Rectangle.
Rectangle is a type, rect is a variable */
// experiment with several permutations of the various functions
including the constructor.
}

I would think that, for consistency, the constructor would check for values
within the specified range *too*.
Jul 22 '05 #4

P: n/a
Ian
David wrote:
Don't know where to start
Not here!

Problem:

Create a class Rectangle The class has attributes length and width, each of
which defaults to 1. It has member functions that calculate the perimeter
and the area of the rectangle. It has set and get function for both length
and width. The set functions should verify that length and width are each
floating point numbers larger than 0.0 and less than 20.0

This looks like a homework problem, read you notes or text book and post
an attempt, you will get more help that way.

Ian
Jul 22 '05 #5

P: n/a

"David" <d_***@shaw.ca> wrote in message
news:UQenc.419691$oR5.121352@pd7tw3no...
Don't know where to start

Problem:

Create a class Rectangle The class has attributes length and width, each of which defaults to 1. It has member functions that calculate the perimeter
and the area of the rectangle. It has set and get function for both length
and width. The set functions should verify that length and width are each
floating point numbers larger than 0.0 and less than 20.0


Have you actually attended any classes or read any books? Honestly it's
really hard to imagine a C++ assignment that is much simpler.

Here's the deal, have a go yourself. Sounds like you will get some things
wrong, maybe you will get everything wrong. But that doesn't matter. When
you have had a go and get stuck come back here and post the code you have
written, then you will get help with it.

Alternatively at least say what you are stuck on, then at least we'd have a
question to answer, rather than just a request to do your homework for you.

john
Jul 22 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.