Where to start

D

David

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
 
?

=?ISO-8859-1?Q?Le_G=E9ant_Vert?=

David said:
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.
 
J

Juergen Heinzl

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
*/
};
 
O

osmium

David said:
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*.
 
I

Ian

David said:
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
 
J

John Harrison

David said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top