Where to start

Discussion in 'C++' started by David, May 9, 2004.

  1. David

    David Guest

    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
     
    David, May 9, 2004
    #1
    1. Advertisements

  2. .... an empty class will do fine....... ain't that straightforward ?!
    empty class => add two attributes => add two methods => done.
     
    =?ISO-8859-1?Q?Le_G=E9ant_Vert?=, May 9, 2004
    #2
    1. Advertisements

  3. [-]
    class Rectangle {
    /*
    ** The rest of your homework here
    */
    };
     
    Juergen Heinzl, May 9, 2004
    #3
  4. David

    osmium Guest

    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*.
     
    osmium, May 9, 2004
    #4
  5. David

    Ian Guest

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

    Ian
     
    Ian, May 9, 2004
    #5
  6. 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
     
    John Harrison, May 9, 2004
    #6
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.