Where to start

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David

    Where to start

    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


  • Le Géant Vert

    #2
    Re: Where to start

    David wrote:
    [color=blue]
    >Don't know where to start
    >
    >
    >[/color]
    .... an empty class will do fine....... ain't that straightforward ?!
    empty class => add two attributes => add two methods => done.

    Comment

    • Juergen Heinzl

      #3
      Re: Where to start

      In article <UQenc.419691$o R5.121352@pd7tw 3no>, David wrote:[color=blue]
      > 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[/color]
      [-]
      class Rectangle {
      /*
      ** The rest of your homework here
      */
      };

      Comment

      • osmium

        #4
        Re: Where to start

        David writes:
        [color=blue]
        > Don't know where to start
        >
        > Create a class Rectangle The class has attributes length and width, each[/color]
        of[color=blue]
        > 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[/color]

        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*.


        Comment

        • Ian

          #5
          Re: Where to start

          David wrote:[color=blue]
          > Don't know where to start
          >[/color]
          Not here![color=blue]
          >
          >
          > 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
          >[/color]
          This looks like a homework problem, read you notes or text book and post
          an attempt, you will get more help that way.

          Ian


          Comment

          • John Harrison

            #6
            Re: Where to start


            "David" <d_pal@shaw.c a> wrote in message
            news:UQenc.4196 91$oR5.121352@p d7tw3no...[color=blue]
            > Don't know where to start
            >
            >
            >
            > Problem:
            >
            > Create a class Rectangle The class has attributes length and width, each[/color]
            of[color=blue]
            > 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
            >[/color]

            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


            Comment

            Working...