You are given a C++ program (Test2Q1.cpp) with 10 errors (syntax errors and/ or logical errors, if any). The program is developed to determine the optimization level of apartment design built-up area. It has five (5) user-defined functions as listed below:   Study how all of the above functions were used/called inside the main function of the program. You are required to debug the errors, compile, and run the program. You are NOT ALLOWED to remove any statements in the program. You are only allowed to update the statements provided in the program and add a new statement(s) if absolutely necessary. Figure 1 is the source code of the program and Table 1 is the 3 (three) test cases that you can use to test the program to know if you have completely and correctly solved all the bugs. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 #include #include #include // Max and min of built-up area (square feet) #define MAX_AREA 900 #define MIN_AREA 600 using namespace std; // function prototypes int getInput(string, int, int); void setBuiltArea(int, int); int setRoom(string); char getLevel(int); string getStatus(); // start main function int main() { // built area dimension / size (feet / square feet) int builtWidth, builtLength, builtArea; // total occupied area for rooms (square feet) int roomArea = 0; setBuiltArea(builtWidth, builtLength); builtArea = builtWidth * builtLength; cout << endl; // set and get the total room built size/area roomArea += setRoom("living"); roomArea += setRoom("kitchen"); roomArea += setRoom("bed"); roomArea = setRoom("bath"); // percentage of built-area occupied for room float percentOccupied = static_cast(roomArea) / builtArea * 100; cout << endl; 4 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 07 98 99 100 101 102 103 104 105 106 107 108 109 cout << "Built-up area is " << builtArea << " (square feet)" << endl; cout << "Total room area is " << roomArea << " (square feet)" << endl; cout << "Free space is "<< builtArea - roomArea << " (square feet)" << endl; cout << "Percentage of occupied area for rooms: " << percentOccupied << "%" << endl; cout << "Area optimization status is " << getStatus(percentOccupied) << endl; return 0; } // implement new user-defined functions // function to get integer number input (feet) for // built area and room size int getInput(string prompt, int min, int max) { int input; do { cout << prompt; cin << input; } while(input > min && input < max); } // Function to set built-up area. Then width must be in the // range of 14 to 20 feet while the length must be in the // range of 30 to 50 feet void setBuiltArea(int width, int length) { int area; // built-up area must be in the range of // 600 to 900 square feet while (area < MIN_AREA || area > MAX_AREA) { cout << "Set the built-up area (width and length in feet)\n"; width = getInput("Width: ", 14, 20); length = getInput("Length: ", 30, 50); area = width * length; if (area < MIN_AREA) cout << "Built-up area can't less than " << MIN_AREA << " square feet\n\n"; else if (area > MAX_AREA) cout << "Built-up area can't exceed " << MAX_AREA << " square feet\n\n"; } } // Function to set room size (living, kitchen, bed, & bath). // Room width and length must be in the range of 6 to 14 feet. int setRoom(string type) { int built_area; cout << "Set the " << type << " room area (width and length in feet)\n"; int width = getInput("Width: ", 6, 14); int length = getInput("Length: ", 6, 14); built_area = width * length; cout << endl; return built_area; } // Function to determine built-area optimization level. char getLevel(int percent) { if (percent >= 80) return 'A'; else if (percent >= 60) return 'B'; else return 'C'; 5 110 111 112 113 114 115 116 117 118 119 120 121 122 123 } // Function to determine built-area optimization status. string getStatus(int percent) { string status; swicth(getLevel(percent)) { case 'A': status = "excellent"; case 'B': status = "good"; break; case 'C': status = "bad"; } return 0; }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

 You are given a C++ program (Test2Q1.cpp) with 10 errors (syntax errors and/ or logical
errors, if any). The program is developed to determine the optimization level of apartment
design built-up area. It has five (5) user-defined functions as listed below: 

 Study how all of the above functions were used/called inside the main function of the program.
You are required to debug the errors, compile, and run the program. You are NOT ALLOWED
to remove any statements in the program. You are only allowed to update the statements
provided in the program and add a new statement(s) if absolutely necessary.
Figure 1 is the source code of the program and Table 1 is the 3 (three) test cases that you can
use to test the program to know if you have completely and correctly solved all the bugs.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <string>
#include <cctype>
// Max and min of built-up area (square feet)
#define MAX_AREA 900
#define MIN_AREA 600
using namespace std;
// function prototypes
int getInput(string, int, int);
void setBuiltArea(int, int);
int setRoom(string);
char getLevel(int);
string getStatus();
// start main function
int main() {
// built area dimension / size (feet / square feet)
int builtWidth, builtLength, builtArea;
// total occupied area for rooms (square feet)
int roomArea = 0;
setBuiltArea(builtWidth, builtLength);
builtArea = builtWidth * builtLength;
cout << endl;
// set and get the total room built size/area
roomArea += setRoom("living");
roomArea += setRoom("kitchen");
roomArea += setRoom("bed");
roomArea = setRoom("bath");
// percentage of built-area occupied for room
float percentOccupied = static_cast<float>(roomArea) / builtArea * 100;
cout << endl;


4

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
07
98
99
100
101
102
103
104
105
106
107
108
109
cout << "Built-up area is " << builtArea << " (square feet)" << endl;
cout << "Total room area is " << roomArea << " (square feet)" << endl;
cout << "Free space is "<< builtArea - roomArea << " (square feet)" <<
endl;
cout << "Percentage of occupied area for rooms: " << percentOccupied <<
"%" << endl;
cout << "Area optimization status is " << getStatus(percentOccupied) <<
endl;
return 0;
}
// implement new user-defined functions
// function to get integer number input (feet) for
// built area and room size
int getInput(string prompt, int min, int max) {
int input;
do {
cout << prompt;
cin << input;
} while(input > min && input < max);
}
// Function to set built-up area. Then width must be in the
// range of 14 to 20 feet while the length must be in the
// range of 30 to 50 feet
void setBuiltArea(int width, int length) {
int area;
// built-up area must be in the range of
// 600 to 900 square feet
while (area < MIN_AREA || area > MAX_AREA) {
cout << "Set the built-up area (width and length in feet)\n";
width = getInput("Width: ", 14, 20);
length = getInput("Length: ", 30, 50);
area = width * length;
if (area < MIN_AREA)
cout << "Built-up area can't less than " << MIN_AREA << " square
feet\n\n";
else if (area > MAX_AREA)
cout << "Built-up area can't exceed " << MAX_AREA << " square
feet\n\n";
}
}
// Function to set room size (living, kitchen, bed, & bath).
// Room width and length must be in the range of 6 to 14 feet.
int setRoom(string type) {
int built_area;
cout << "Set the " << type << " room area (width and length in feet)\n";
int width = getInput("Width: ", 6, 14);
int length = getInput("Length: ", 6, 14);
built_area = width * length;
cout << endl;
return built_area;
}
// Function to determine built-area optimization level.
char getLevel(int percent) {
if (percent >= 80)
return 'A';
else if (percent >= 60)
return 'B';
else
return 'C';


5

110
111
112
113
114
115
116
117
118
119
120
121
122
123
}
// Function to determine built-area optimization status.
string getStatus(int percent) {
string status;
swicth(getLevel(percent)) {
case 'A': status = "excellent";
case 'B': status = "good"; break;
case 'C': status = "bad";
}
return 0;
}

 

Table 1: Test cases to run and test the program (user inputs are shown in red-bold text)
TEST CASE 1
Set the built-up area (width and length in feet)
Width: 14
Length: 30
Built-up area can't less than 600 square fet
Set the built-up area (width and length in feet)
Width: 14
Length: 45
Set the living room area (width and length in feet)
Width: 14
Length: 14
Set the kitchen room area (width and length in feet)
Width: 12
Length: 14
Set the bed room area (width and length in feet)
Width: 10
Length: 12
Set the bath room area (width and length in feet)
Width: 6
Length: 8
Built-up area is 630 (square feet)
Total room area is 532 (square feet)
Free space is 98 (square feet)
Percentage of occupied area for room: 84.4444
Area optimization status is excellent
TEST CASE 2
Set the built-up area (width and length in feet)
Width: 16
Length: 40
Set the living room area (width and length in feet)
Width: 10
Length: 12
Set the kitchen room area (width and length in feet)
Width: 8
Length: 10
Set the bed room area (width and length in feet)
Width: 10
5
Length: 12
Set the bath room area (width and length in feet)
Width: 8
Length: 10
Built-up area is 640 (square feet)
Total room area is 400 (square feet)
Free space is 240 (square feet)
Percentage of occupied area for room: 62.5%
Area optimization status is good
TEST CASE 3
Set the built-up area (width and length in feet)
Width: 12
Width: 22
Width: 20
Length: 28
Length: 60
Length: 50
Built-up area can't exceed 900 square feet
Set the built-up area (width and length in feet)
Width: 20
Length: 45
Set the living room area (width and length in feet)
Width: 16
Width: 10
Length: 14
Set the kitchen room area (width and length in feet)
Width: 8
Length: 10
Set the bed room area (width and length in feet)
Width: 10
Length: 12
Set the bath room area (width and length in feet)
Width: 6
Length: 4
Length: 8
Built-up area is 900 (square feet)
Total room area is 388 (square feet)
Free space is 512 (aquare feet)
Percentage of occupied area for room: 43.11114
Area optimization status is bad.
Transcribed Image Text:Table 1: Test cases to run and test the program (user inputs are shown in red-bold text) TEST CASE 1 Set the built-up area (width and length in feet) Width: 14 Length: 30 Built-up area can't less than 600 square fet Set the built-up area (width and length in feet) Width: 14 Length: 45 Set the living room area (width and length in feet) Width: 14 Length: 14 Set the kitchen room area (width and length in feet) Width: 12 Length: 14 Set the bed room area (width and length in feet) Width: 10 Length: 12 Set the bath room area (width and length in feet) Width: 6 Length: 8 Built-up area is 630 (square feet) Total room area is 532 (square feet) Free space is 98 (square feet) Percentage of occupied area for room: 84.4444 Area optimization status is excellent TEST CASE 2 Set the built-up area (width and length in feet) Width: 16 Length: 40 Set the living room area (width and length in feet) Width: 10 Length: 12 Set the kitchen room area (width and length in feet) Width: 8 Length: 10 Set the bed room area (width and length in feet) Width: 10 5 Length: 12 Set the bath room area (width and length in feet) Width: 8 Length: 10 Built-up area is 640 (square feet) Total room area is 400 (square feet) Free space is 240 (square feet) Percentage of occupied area for room: 62.5% Area optimization status is good TEST CASE 3 Set the built-up area (width and length in feet) Width: 12 Width: 22 Width: 20 Length: 28 Length: 60 Length: 50 Built-up area can't exceed 900 square feet Set the built-up area (width and length in feet) Width: 20 Length: 45 Set the living room area (width and length in feet) Width: 16 Width: 10 Length: 14 Set the kitchen room area (width and length in feet) Width: 8 Length: 10 Set the bed room area (width and length in feet) Width: 10 Length: 12 Set the bath room area (width and length in feet) Width: 6 Length: 4 Length: 8 Built-up area is 900 (square feet) Total room area is 388 (square feet) Free space is 512 (aquare feet) Percentage of occupied area for room: 43.11114 Area optimization status is bad.
Function Name
Description
setBuiltArea
Receives 2 (two) integer type parameters (width and length) to
represent the overall built-up area of an apartment
Controls the width and length of built-up area as follows:
Width must be in the range of 14 to 20 feet
o Length must be in the range of 30 to 50 feet
Controls the minimum and maximum value of built-up area
square feet (width x length) by using the following two
constants:
#define MAX_AREA 900
#define MIN_AREA 600
• Changes the value of the parameters passed to it to set the width
and length of apartment's overall built-up area
setRoom
Receives single string parameter that represents the room type
(living. kitchen, bed, or bath) inside the apartment
Controls the width and length of room's built-up area inside the
apartment (both width and length must be in the range of 6 to 14
feet)
Returns an integer value that is the built-up area of the room.
The returned value is used inside the main function to calculate
the total built-up area occupied by all rooms within the
apartment.
getInput
Called inside the setBuiltArea and setRoom functions to get
the input for width and length of apartment's overall and rooms
built-up area
Receives 3 (three) parameters that are the caption (width or
length), and the minimum and maximum values can be entered as
input
Returns integer type value represent the width or length of area
getLevel
Called inside the getStatus function
Receives single integer type that is the percentage of built-area
occupied by the rooms
Returns character value to determine the level of apartment built-
up area optimization:
A- room's built-up area 80% - 100%
B- room's built-up area 60% - 79%
C- room's built-up area less than 60%
2
getstatus
Receives single integer type parameter that is the percentage of
built-area occupied by the rooms
Percentage of built-area occupied by the rooms is calculated
inside the main function as follows:
percent occupied =
total room area
х 100
apartment's overall built-up area
Returns string type value of area optimization status based on area
optimization level (returned by getLevel function) as follows:
A - "excellent"
В -"good"
C- "bad"
Transcribed Image Text:Function Name Description setBuiltArea Receives 2 (two) integer type parameters (width and length) to represent the overall built-up area of an apartment Controls the width and length of built-up area as follows: Width must be in the range of 14 to 20 feet o Length must be in the range of 30 to 50 feet Controls the minimum and maximum value of built-up area square feet (width x length) by using the following two constants: #define MAX_AREA 900 #define MIN_AREA 600 • Changes the value of the parameters passed to it to set the width and length of apartment's overall built-up area setRoom Receives single string parameter that represents the room type (living. kitchen, bed, or bath) inside the apartment Controls the width and length of room's built-up area inside the apartment (both width and length must be in the range of 6 to 14 feet) Returns an integer value that is the built-up area of the room. The returned value is used inside the main function to calculate the total built-up area occupied by all rooms within the apartment. getInput Called inside the setBuiltArea and setRoom functions to get the input for width and length of apartment's overall and rooms built-up area Receives 3 (three) parameters that are the caption (width or length), and the minimum and maximum values can be entered as input Returns integer type value represent the width or length of area getLevel Called inside the getStatus function Receives single integer type that is the percentage of built-area occupied by the rooms Returns character value to determine the level of apartment built- up area optimization: A- room's built-up area 80% - 100% B- room's built-up area 60% - 79% C- room's built-up area less than 60% 2 getstatus Receives single integer type parameter that is the percentage of built-area occupied by the rooms Percentage of built-area occupied by the rooms is calculated inside the main function as follows: percent occupied = total room area х 100 apartment's overall built-up area Returns string type value of area optimization status based on area optimization level (returned by getLevel function) as follows: A - "excellent" В -"good" C- "bad"
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 12 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY