The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 408 Weeks Ago, 1 Day Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
CREATING A CLASS IN C++ In this lab, you create a programmer-defined class and then use it in a C++ program. The program should create two Rectangle objects and find their area and perimeter. Use the Circle class that you worked with in Exercise 10-1 as a guide.
Â
1. Open the class file named Rectangle.cpp using Notepad or the text editor of your choice.
Â
2. In the Rectangle class, create two private attributes named length and width. Both length and width should be data type double.
Â
3. Write public set methods to set the values for length and width.
Â
4. Write public get methods to retrieve the values for length and width.
Â
5. Write a public calculateArea()method and a public calculatePerimeter() method to calculate and return the area of the rectangle and the perimeter of the rectangle.
Â
6. Save this class file, Rectangle.cpp, in a directory of your choice and then open the file named MyRectangleClassProgram.cpp.
Â
7. In the MyRectangleClassProgram, create two Rectangle objects named rectangleOne and rectangleTwo using the default constructor as you saw in MyEmployeeClassProgram.cpp.
Â
8. Set the length of rectangleOne to 4.0 and the width to 6.0. Set the length of rectangleTwo to 9.0 and the width to 7.0.
Â
9. Print the value of rectangleOne’s perimeter and area, and then print the value of rectangleTwo’s perimeter and area.
Â
10. Save MyRectangleClassProgram.cpp in the same directory as Rectangle.cpp.
Â
11. Compile the source code file MyRectangleClassProgram.cpp.
Â
12. Execute the program.
Â
13. Record the output below
Â
Â
Â
Â
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------acq-----------uis-----------iti-----------on -----------of -----------my -----------pos-----------ted----------- so-----------lut-----------ion-----------.Pl-----------eas-----------e p-----------ing----------- me----------- on-----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be-----------