Use C++ \You are given a C++ program 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: nction 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: o   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: o   #define MAX_AREA 900 o   #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: o   A – room’s built-up area 80% - 100% o   B – room’s built-up area 60% - 79% o   C – room’s built-up area less than 60%

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

Use C++

\You are given a C++ program 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:

nction 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:

o   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:

o   #define MAX_AREA 900

o   #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:

o   A – room’s built-up area 80% - 100%

o   B – room’s built-up area 60% - 79%

o   C – room’s built-up area less than 60%

 

 

#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;

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';

}
// 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;
}

Expert Solution
steps

Step by step

Solved in 2 steps

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