Question

In: Computer Science

This code needs to be in C++, please. Step 1: Add code to prompt the user...

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:

  • The length of the room cannot be less than 5 feet
  • The width of the room cannot be less than 5 feet
  • The user's menu selection for the amount of shade should be 1, 2, or 3.

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?

  1. Little Shade
  2. Moderate Shade
  3. Abundant Shade

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?

  1. Little Shade
  2. Moderate Shade
  3. Abundant Shade

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

Solutions

Expert Solution

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


Related Solutions

C code please (1) Prompt the user to enter a string of their choosing. Store the...
C code please (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be more shuttle flights and...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                       ...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names             Quit If the user selects Guess-number, your program needs to call a user-defined function called int guess-number ( ). Use random number generator to generate a number between 1 – 100. Prompt the user to guess the generated number and print the following messages. Print the guessed number in main (): Guess a number: 76 96: Too large 10 Too small 70 Close...
Prompt the user for their name, get and store the user input. Prompt the user for...
Prompt the user for their name, get and store the user input. Prompt the user for their age, get and store the user input. We will assume that the user will enter a positive integer and will do no error checking for valid input. Determine and store a movie ticket price based on the user's age. If their age is 12 or under, the ticket price is $5. If their age is between 13 and 64, inclusive, the ticket price...
IN C This assignment is to write a program that will prompt the user to enter...
IN C This assignment is to write a program that will prompt the user to enter a character, e.g., a percent sign (%), and then the number of percent signs (%) they want on a line. Your program should first read a character from the keyboard, excluding whitespaces; and then print a message indicating that the number must be in the range 1 to 79 (including both ends) if the user enters a number outside of that range. Your program...
use c++ (1) Prompt the user for a title for data. Output the title. (1 pt)...
use c++ (1) Prompt the user for a title for data. Output the title. (1 pt) Ex: Enter a title for the data: Number of Novels Authored You entered: Number of Novels Authored (2) Prompt the user for the headers of two columns of a table. Output the column headers. (1 pt) Ex: Enter the column 1 header: Author name You entered: Author name Enter the column 2 header: Number of novels You entered: Number of novels (3) Prompt the...
use c++ (1) Prompt the user for a string that contains two strings separated by a...
use c++ (1) Prompt the user for a string that contains two strings separated by a comma. (1 pt) Examples of strings that can be accepted: Jill, Allen Jill , Allen Jill,Allen Ex: Enter input string: Jill, Allen (2) Print an error message if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two strings. (2 pts) Ex:...
code in c++ using the code given add a hexadecimal to binary converter and add a...
code in c++ using the code given add a hexadecimal to binary converter and add a binary to hexadecimal converter #include <iostream> #include <string> #include<cmath> #include<string> using namespace std; int main() { string again; do { int userChoice; cout << "Press 2 for Decimal to Binary"<< endl; cout << "Press 1 for Binary to Decimal: "; cin >> userChoice; if (userChoice == 1) { long n; cout << "enter binary number" << endl; cin>>n; int decnum=0, i=0, remainder; while(n!=0) {...
Step by step in python please Write a program this will read a file (prompt for...
Step by step in python please Write a program this will read a file (prompt for name) containing a series of numbers (one number per line), where each number represents the radii of different circles. Have your program output a file (prompt for name) containing a table listing: the number of the circle (the order in the file) the radius of the circle the circumference the area of the circle the diameter of the circle Use different functions to calculate...
Reuse the code to prompt the user for a specific day, test whether it is within...
Reuse the code to prompt the user for a specific day, test whether it is within range, and then output the estimated concrete strength from the fitted curve using polyval. Run your function from the command window for 2 different days to test the functioning of your code. The program should preferably loop until the user asks to exit. where x = days y = rain (mm) x = [0 1 2 3 7 14 28]; y = [0 4...
Add an item to a Text File / C++ the program will prompt for a filename...
Add an item to a Text File / C++ the program will prompt for a filename AND then prompt for a text file item. text file items always contain an unknown amount of spaces, (see getline). Allow the user to put both the filename and the extensions, like groceries.txt or retirementToDo.clist Don't add any directory information to the filenames, use them as typed. If the file does exist, the item will be APPENDED to the end of the file. If...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT