Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 2a: (8 points Write a C++ program that inputs the length and width of tw

ID: 3879298 • Letter: P

Question

Problem 2a: (8 points Write a C++ program that inputs the length and width of two rectangles in integers) representing a house and a garage. Write a function that uses Call-by-Value int rectArea (int len, int wid) that returns the area of a rectangle with length len and width wid. Divide the area of the garage by the area of the house and multiply by 100 to determine the percentage (int). Enter your name as a Global variable and all other variables should be local variables in main or rectArea Area = length*width Percentage = 100* GarageArea/HouseArea Length of House (ft): 50 Width of House (ft): 60 Length of Garage (ft): 10 Width of Garage (ft):20 Sample Output (Your name will replce mie) The house is 3000 square feet The garage is 200 square feet Cindy's garage is 6 percent of her house Problem 2b: (7 points) Draw the memory and run-time stack when rectArea is called. This should look similar to Fig 2.17g in the textbook and ALL of your variable names should be shown including name. Remember, local variables are stored on the stack and global variables are stored in fixed memory. You

Explanation / Answer

#include <iostream>
using namespace std;

string NAME = "Alicia"; // replace it by your name

// returning area of rectangle
int rectArea(int len, int wid)
{
return len*wid;
}

int main() {
// declaring variables
int lhouse, whouse;
int lgarage, wgarage;
  
// taking user input for house
cout << "Lenght of House (ft): ";
cin >> lhouse;
cout << "Width of House (ft): ";
cin >> whouse;
  
// taking user input for garage
cout << "Lenght of Garage (ft): ";
cin >> lgarage;
cout << "Width of Garage (ft): ";
cin >> wgarage;
  
// calculating areas of house and garage
int houseArea = rectArea(lhouse, whouse);
int garageArea = rectArea(lgarage, wgarage);
  
// printing output of first 2 lines
cout << "The house is "<< houseArea << " square feet" << endl;
cout << "The garage is "<< garageArea << " square feet" << endl;
  
// calculating percentage
int percentage = 100*garageArea/houseArea;
  
// printing final line
cout << NAME << "'s garage is " << percentage << " percent of her house";
}

/* SAMPLE OUTPUT
Lenght of House (ft): 50
Width of House (ft): 60
Lenght of Garage (ft): 10
Width of Garage (ft): 20
The house is 3000 square feet
The garage is 200 square feet
Alicia's garage is 6 percent of her house
*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote