Lab 7   - Rectangle class-   (Lec. 7) 1.) Create a new project and name it:    Rectangle /* OUTPUT: Enter the...

70.2K

Verified Solution

Question

Programming

Lab 7   - Rectangleclass-   (Lec. 7)

1.) Create a new project and

name it:    Rectangle

/* OUTPUT:

Enter the width of the court: 60

Enter the length of the court: 120

The width of the court is 60 feet.

The length of the court is 120 feet.

The area of the court is 7200 square feet.

Press any key to continue . . . */

2.) Create the following 3 files:

  • Rectangle.h
  • Rectangle.cpp
  • Source.cpp

3.) Write a program that produces

this output:

Rectangle.h

4.)In the Rectangle.h file, write a class specificationfor a Rectangle class.

           2 private data members:      _width (int)and _length (int)

           7 public member functions:

      Defaultconstructor - Assigns ‘safe’ values to the data members.

     Descructor

     setWidth – An int value, passed from main(), is assignedto _width.

     setLength - An int value, passed from main(), is assignedto _length.

     getWidth – Returns the object’s width.

     getLength – Returns the object’s length.

      getArea– Calculates the area of the Rectangle object and returns thevalue.

Rectangle.cpp

5.) In the Rectangle.cpp file, write a functionimplementation for each function

prototype listed in the Rectangle class specification.

Source.cpp

6.)In main(), declare an object of Rectangletype, andname it:    tennisCourt

7.) In main(), declare three variables ofdouble data type, and

               and name them:   width,length and area

6.) Prompt the user to enter a width and length (seeoutput).

7.) Read in the user’s inputs and assign them to the datamembers of tennisCourt,

            by using the ‘set’ member functions.

8.)Then assign the tennis court’s width,length and area to variable inmain() by

            using the ‘get’ member functions.

9.)Display the width, length, and area. (see output)

Answer & Explanation Solved by verified expert
3.8 Ratings (593 Votes)
    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students