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: prompt user to enter a number then add loop that checks a list of...
c++ code: prompt user to enter a number then add loop that checks a list of numbers then display numbers that are higher or equal to the user's input.
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++ code a program should prompt the user for the name of the output file. The...
C++ code a program should prompt the user for the name of the output file. The file should be opened for write operations. Values calculated by the program will be written to this file. The program must verify that the file opened correctly. If the file did not open, an error message should be printed and the user should be prompted again. This should continue until the user supplies a valid filename.
Please note that this problem have to use sstream library in c++ (1) Prompt the user...
Please note that this problem have to use sstream library in 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...
C++ Code Writing prompt: Grade Calculation: Write a program that asks the user to enter in...
C++ Code Writing prompt: Grade Calculation: Write a program that asks the user to enter in a number greater than or equal to zero and less than or equal to 100. If they do not you should alert them and end the program. Next, determine the letter grade associated with the number. For example, A is any grade between 90 and 100. Report the letter grade to the user.
​​​​​​​in c code Add an intro screen Ask the user for their name, what type of...
​​​​​​​in c code Add an intro screen Ask the user for their name, what type of cookie they would like to order and how many. The types are sugar, chocolate chip, and peanut butter. Assign a cost to each cookie. Show total for cookie purchase and ask if the would like to place another order. Include at least one function and one loop. Add one extra feature. For example, a sample execution of your code would be as follows: Cookie...
Using map - java - eclipse Prompt the user for the skillset to add. A skillset...
Using map - java - eclipse Prompt the user for the skillset to add. A skillset can be any String. Examples of skillsets are: “java” “software design”, “databases”, etc. Add the skillset to the logged in user’s skillsets and then provide a response to the logged in user indicating that their skillset has been added (e.g. “Java has been added to your skillsets.”). You don’t have to display any additional messages if the user added a duplicate skillset. In this...
1. Write a program in C++ to find the factorial of a number. Prompt the user...
1. Write a program in C++ to find the factorial of a number. Prompt the user for a number and compute the factorial by using the following expression. Use for loops to write your solution code. Factorial of n = n! = 1×2×3×...×n; where n is the user input. Sample Output: Find the factorial of a number: ------------------------------------ Input a number to find the factorial: 5 The factorial of the given number is: 120 2. Code problem 1 using While...
IN C ++ PLEASE CODE FOR BUBBLE SORT---Add code to sort the bowlers. You have to...
IN C ++ PLEASE CODE FOR BUBBLE SORT---Add code to sort the bowlers. You have to sort their parallel data also. Print the sorted bowlers and all their info . You can use a bubble sort or a shell sort. Make sure to adjust your code depending on whether or not you put data starting in row zero or row one. Sort by Average across, lowest to highest.  The highest average should then be on the last row.. When you sort...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT