Question
EGR 125 C++ Programming for Engineers Programming Assignment #4: Class Rectangle Exploring Rectangle Objects This assignment will develop a rectangle object. Rectangles help us to
EGR 125 C++ Programming for Engineers
Programming Assignment #4: Class Rectangle
Exploring Rectangle Objects
This assignment will develop a rectangle object. Rectangles help us to determine the amount of paint needed to cover a wall. Commercial buildings are rented by the square foot, a value computed by finding the area of each room. The perimeter (distance around the outside) determines the cost of fencing a backyard. A rectangle object provides many useful applications involving measurement. As a measurement figure, a rectangle is determined by its length and width. These are the two attributes in a Rectangle object. The operations area, perimeter, and diagonal use the length and width of the rectangle to compute the surface area and the distance around the outer edge and the distance across the diagonal.
The following is a formal description of the Rectangle object type. The description includes the constructor (Rectangle) that initializes the length and width attributes of an object and access operations to update the attributes or retrieve their current values.
Class Rectangle
Data Members (Attributes):
Length
Width
Member Functions (Operations):
Rectangle Assigns 5 to both length and width of an uninitialized rectangle
Rectangle Takes initial values length and width as arguments and assigns them as the Length and Width of the rectangle
area Computes Length * Width and returns the value as the area
perimeter Computes 2 * (Length + Width) and returns the value as the perimeter
diagonal Computes the square root of (Length2 + Width2 ) and returns the value as the diagonal
setSides Takes values length and width as arguments and updates the attributes Length and Width to have the values length and width respectively
getLength Returns the current value of Length
getWidth Returns the current value of Width
print Display the dimension of rectangle on command window
TestIfValid Return true if the inputs form an invalid rectangle
Building a Swimming Pool
Use the objects of a Rectangle type to compute the cost of finishing a swimming pool. City building code requires that a 6-foot wide concrete walkway must surround the pool edge and the entire area must be enclosed by a 6-foot fence. As a problem-solving situation, we want to determine the amount and cost of the materials.
In the program design, we define the pool and its surrounding rim as two Rectangle objects called pool and walkway, respectively. The walkway object is 12 unit (ft/m) longer and 12 unit (ft/m) wider that the pool to accommodate the walkway around the pool. To simplify the problem, we assume the cost of fencing is $10.00 per linear unit (ft/m). and the cost of concrete $1.80 per square unit (ft2 /m2 ). The area and perimeter operations of the two objects determine the amount and cost of materials. The program uses the real number objects fenceLength and concreteArea to contain the length of the fence and the area of the concrete walkway. The amount of fencing is determined by the perimeter of the walkway.
fenceLength = walkway.perimeter();
The amount of concrete for the walkway is computed by subtracting the area of the pool object from the walkway object.
concreteArea = walkway.area() - pool.area();
The cost of the fence is fenceLength * 10 and the cost of the concrete is concreteArea * 1.80.
Program Requirements:
1. Creating a class: The program should define class Rectangle according to the class diagram provided.
? Use separate header and implementation files for class (rect.h and rect.cpp)
? Allow user to re-enter bad inputs with appropriate error message
2. Main Program: The main program should solve building a swimming pool.
? Prompt the user to enter the dimension of pool
? Prompt the user to enter the unit of dimension.
? Display the fence dimension.
? Display the perimeter of fence required with one digit after decimal point.
? Display the area of walkway with one digit after decimal point.
? Display the cost of fence, cost of concrete and total cost with appropriate decimal point setting.
? Display all output with appropriate unit.
3. Standard report is also required for this project (lab)
Testing your program
Case 1: pool size is 10 x 8 feet Sample output for case 1:
Case 2: pool size is 20 x 12 meter
Case 3: pool size is 25.5 x 19.6 feet
Turn in your program in a zipped folder including report to Blackboard under project 4 link.
Extra Credit Suggestions: (for a maximum of 10 additional points on the program grade)
1. Pretend you are the contractor, generate an output file as invoice to your client. Neatly display.
2. Perform 10 estimates by creating a data file with 10 pool dimensions.
3. Use your imagination
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started