In: Computer Science
This code needs to be in C++, please.
Step 1: Add code to prompt the user to enter the name of the room that they are entering information for. Validate the input of the name of the room so that an error is shown if the user does not enter a name for the room. The user must be given an unlimited amount of attempts to enter a name for the room.
Step 2: Add Input Validation to the code using the following rules:
If the user's input is invalid, the program should display an appropriate error message and prompt the user to re-enter their input. The user should be given an unlimited amount of attempts to enter valid input
Step 3: Add code to have the program ask the user if they would like to enter information about another room after the information for a previous room has been processed and displayed. The user should be able to enter a "y" or "Y" to indicate that they want to enter information about another room. See the Sample Input and Output for how to format this.
Step 4: After the user has indicated that they do not wish to enter information about another room, the program should output the number of rooms that have been entered and then stop executing.
Sample Input and Output (user input is in bold) - The output of your program should match the formatting and spacing exactly as shown
Please enter the name of the room: Guest
Bedroom
Please enter the length of the room (in feet):
15.5
Please enter the width of the room (in feet):
10
What is the amount of shade that this room receives?
Please select from the options above: 3
Air Conditioning Window Unit Cooling Capacity
Room Name: Guest Bedroom
Room Area (in square feet): 155.0
Amount of Shade: Abundant
BTUs Per Hour needed: 4,950
Would you like to enter information for another room (Y/N)? Y
Please enter the name of the room:
Kitchen
Please enter the length of the room (in feet):
20
Please enter the width of the room (in feet):
15
What is the amount of shade that this room receives?
Please select from the options above: 2
Air Conditioning Window Unit Cooling Capacity
Room Name: Kitchen
Room Area (in square feet): 300.0
Amount of Shade: Moderate
BTUs Per Hour needed: 10,000
Would you like to enter information for another room (Y/N)? N
The total number of rooms processed was: 2
here is a code with output snippet for above problem.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int count =0; // to count the number of rooms
// choice is to store the choice of user for entering more record
char choice = 'y';
// while loop until the choice is yes
while (choice == 'y' || choice =='Y')
{
count++;
string room_name;
cout<<"Please enter the name of the room : ";
getline(cin, room_name);
cout<<endl;
double len; // len variable to store the length of the room
double wid; // wid variable to store the width of the room
// create a label uplen in case user entered invalid length
uplen:
cout<<"Please enter the length of the room (inj feet): ";
cin>>len;
if(len <5) // check for the validity of length
{
cout<<endl<<"Invalid room length please enter again";
goto uplen;
}
// create a label upwid in case user entered invalid width
upwid:
cout<<endl<<"Please enter the width of the room (in feet): ";
cin>>wid;
if(wid <5) // check for the validity of the width
{
cout<<endl<<"Invalid room width please enter again";
goto upwid;
}
cout<<endl<<"What is the amount of shade that this room receives? "<<endl;
cout<<"Little Shade"<<endl<<"Moderate Shade"<<endl<<"Abundant Shade"<<endl;
cout<<"Please select the option above";
// op variable is to store the option ie 1 2 or 3
int op;
cin>>op;
// print the output to the console with recorded information
cout<<"Air Conditioning Window Unit Cooling Capacity"<<endl;
cout<<"Room name : "<<room_name<<endl;
cout<<"Room Area ( in square feet ): "<<double(len*wid)<<endl;
cout<<"Amount of shade: ";
if(op == 1)
cout<<"Little";
else if(op ==2)
cout<<"Moderate";
else
cout<<"Abundant";
// ask the user if needs to enter more info
cout<<endl<<"Would you like to enter information for another room (Y/N)?";
cin>>choice;
char ch = cin.get();
}
cout<<endl<<"The total number of rooms processed was: "<<count;
return 0;
}
I actually dont know how to calculate btus per hour neede also you have not mentioned it ... once you tell me i can do it but the code is otherwise complete .
here is the output snippet