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



Trending nowThis is a popular solution!
Step by stepSolved in 5 steps with 12 images

- In this assignment you will be responsible for writing several string validation and manipulationfunctions. The assumption will be that you are writing functions that will take input from a form andmanipulate or validate the information entered before it is processed into a database. A database is acollection of information but the information in the database must always be entered in a specificformat. Your responsibility will be to take data entered into a program and be sure it is writtencorrectly before it is entered into the database.Each function will have to have a specific name and heading. Each function will also need to includea docstring, the correct logic, and the proper return. Each function will be given a specific set ofpreconditions and postconditions/returns. A precondition is something you may assume to be truewhen the function is executed. A post condition is something you need to be sure is completed whenthe function is executed. Be sure to test each one of your…arrow_forwardInstructions: For each Exercise below, write your code in an IDE and run your code within the IDE as well. Once you have satisfied the Exercise requirements, paste your code below under the corresponding Exercise. Exercise 1: Please perform in C++ Write a program using a function which will accept two integers as an argument and return sum. Call this function from the main function and print the results in the main function! This is a nice and easy warm up to functions! ● ●arrow_forwardWrite a C++ program with two user defined functions. The first function named "functionWithArray" takes two user input arguments of character types and return True if first argument is smaller than the second argument (alphabetically) and returns False otherwise. Write the second function named "functionWithPointers" which behaves like the first functions but uses pointers to receive the arguments. You may assume that both character arrays contain only lower-case letters, and no blanks or other non- alphabetic characters. Write a suitable Main function to test these two functions. Sample Output: Enter First String: C++Programming Enter Second String: JavaProgramming According to functionWithArrays: 'c++programming' is smaller than 'javaprogramming'. According to functionWithPointers: 'c++programming' is smaller than 'javaprogramming'.arrow_forward
- Can you help me with a UML program please? I have a hard time understanding it Suppose you work at a robot company that has started building tiny disc-shaped vacuum cleaners that drive around people's houses and vacuum up debris. You are tasked with coding a program for the operation of this robot. Use that list of functions to inform your UML diagram. Using any program (like Draw.io or LucidChart) that creates UML diagrams, draft a UML diagram that is not too simple. Create your unique diagram. What interesting things can your robot do.? Be sure to follow the following Assure your symbols match the actions in your diagram (diamond shapes in decisions for instance). Check that your diagram is readable, and lines and text don't cross each other. Assure the diagram doesn't have too many lines crossing so it becomes confusing.arrow_forwardUsing C++ Using your own creativity, make a set of function templates that have these features: This function must return a value. A function template with 1 template parameter, T. And, any other parameters you want. A function template with 2 template parameters, T1 and T2. And, any other parameters you want Within main (): Call your template functions and demonstrate how they work. Construct objects and show off your amazing programming skills!arrow_forwardWhich of the following are advantages of inline function declarations in C++ or the "Pragma Priority (x)" in Ada? they do not save push/pop variable overhead on the stack when it is called there is a lookup time required at runtime which is the same as an external function call during compile tim. Please type answer no write by hend.arrow_forward
- All lines of code in your program can be reached and executed when I run your program define two functions and they have a "meaningful purpose" to your program. Each function must have more than three statements or lines of code. At least one function defines a parameter and you use this parameter in a meaningful way At least one function returns a value back to the code that is calling it and it is used in a meaningful wayarrow_forwardLocal declarations are those that are stored in the computer's memory, but how are they stored? Using local declarations is unnecessary if the same goal can be accomplished without them. When reference parameters may be used in any function, why bother with value parameters? When it comes to processing programme data, how important are value parameters?arrow_forwardI am learning c++, and I am really confused about the bool command. Please explain to me how the bool command used and when should I use it! thanks.arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





