Question

C++ PROGRAM SPECIFICATION For the assignment, we will use the previous assignment’s program that determines whether...

C++

PROGRAM SPECIFICATION

For the assignment, we will use the previous assignment’s program that determines whether a college class room is in violation of fire law regulations regarding the maximum room capacity and add more logic to that program. We will need to make the following enhancements…

  • The program should now determine the number of classes, and should do so by generating a unique, random number. Replace taking user input for the number of rooms with a computer generated number between 1 and 10.

  • Decompose the program into functions. Pass all values by value only. You will continue using the same code, only now your code should “broken out” into separate pieces. In general, you will want to have a separate function to handle the validations, handle taking inputs, handle displaying the information, etc.

  • Add a menu that displays to the user the rooms available. You will have five choices for the menu, and also include an option on the menu to quit. Reproduce the menu each time and let the user go again, or quit.

Match your program with the sample input and output (use proper formatting) as shown below:

Please choose a room from the menu

  1. Leigh Hall room 312

  2. College of Arts and Sciences room 41

  3. Kolbe Hall room 133

  4. Whitby Hall room 111

  5. Ayer Hall room 30

  6. Quit

Your choice:

(assume user enters 4…)

Whitby Hall room 111 has capacity for 75.

(assume computer randomly generates 3…)

Enter the number of attendees: 72

It is legal to hold class and there is minimal 4% capacity remaining

Enter the number of attendees: 92

The class cannot be held as planned

Enter the number of attendees: 75

It is legal to hold class and there is minimal 0% capacity remaining

Make sure that your programs follow good documentation standards and follow the requirements for assignments. Do not use namespace std.

the following is the previous code for the past assignment.

#include
using namespace std;

int main()
{
int classes,attendees,room;
while(true)
{
cout<<"How many classes would you like to enter? ";
cin>>classes;
if(classes<0)
cout<<"Invalid Input!!";
else
break;
}
while(true)
{
cout<<"Enter the room for your class 1 (1-5): ";
cin>>room;
if(room<=0 || room>5)
cout<<"Invalid Input!!";
else
break;
}
cout<<"Whitby Hall room 111 has capacity for 75.\n";
for(int i=0;i {
while(true)
{
cout<<"Enter the number of attendees: ";
cin>>attendees;
if(attendees<0 || attendees>99)
cout<<"Invalid Input!!";
else
break;
}
if(attendees<=75)
{
float percent = ((float)(75-attendees)/(float)75) * 100;
cout<<"It is legal to hold class and there is minimal "<<(int)percent<<"% capacity remaining\n";
}
else
{
cout<<"The class cannot be held as planned\n";
}

}
}


//Output

Homework Answers

Answer #1

Here is the solution to above problem in C++. Please read the code comments for more information

PLEASE GIVE A THUMBS UP!!!

C++ Code

#include<bits/stdc++.h>
using namespace std;

//to check which class user wants to have
void checkClass(string message,int capacity)
{
   cout<<message<<" has a capacity for "<<capacity<<endl;
   cout<<"Enter the number of attendes: ";
   int atten;
   cin>>atten;
   if(atten>capacity)
   {
       cout<<"The class cannot be held as planned\n";
   }
   else
   {
       float perc = 100.0-(((float)(atten)/capacity )*100);
       cout<<"It is legal to hold class and there is minimal "<<perc<<"% capacity remaining\n";
   }
  
}


int main()
{
int classes,attendees,room;
int choice; //input for user choice;
while(true)
{
   //display the menu
   cout<<"       Please choose a room from the menu\n";
   cout<<"1.Leigh Hall room 312\n";
   cout<<"2.College of Arts and Sciences room 41\n";
   cout<<"3.Kolbe Hall room 133\n";
   cout<<"4.Whitby Hall room 111\n";
   cout<<"5.Ayer Hall room 30\n";
   cout<<"6.Quit\n";
  
while(true)
{
cout<<"Enter the room for your class 1 (1-6): ";
cin>>choice;
if(choice<=0||choice>6)
   cout<<"Invalid choice\n";
else
break;
}

switch(choice)
{
   case 1: checkClass("Leigh Hall room 312",312);
       break;
   case 2: checkClass("College of Arts and Sciences room",41);
       break;
   case 3: checkClass("Kolbe Hall room",133);
       break;
   case 4: checkClass("Whitby Hall room",111);
       break;
   case 5: checkClass("Ayer Hall room",30);
       break;
   case 6: cout<<"Bye";
           return 0;;
       break;
      
}
}
return 0;
}

Screenshot of output

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a C++ program to run a menu-driven program with the following choices: Compute the factorial...
Write a C++ program to run a menu-driven program with the following choices: Compute the factorial of a number Compute the alternating factorial of a number Quit #include <iostream> using namespace std; void getValidUserInputPosNumGT0 (int *a) { int num; cout << "Enter in a positive number greater than 0... "; cin >> *a; } long double factorial (int num) { int fact = 1; while (num > 1) { fact *= num; num--; } return fact; } long double AlternatingFactorial...
In C++, create an input validation where the user enters a signed whole number and repeats...
In C++, create an input validation where the user enters a signed whole number and repeats this process until the user enters a zero. Do not accept any value with a decimal fraction or other extraneous characters, including dollar signs. The number's sign must be preserved. Some of the steps has been done for you. Fill out the program in C++. See below for the expected console output. Program: #include <iostream> using namespace std; int main(){    signed int input;...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159;...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159; //repeat until user wants to quits while(true) { //menu cout<<endl<<endl<<"Geometry Calculator"<<endl<<endl; cout<<"1. Calculate the area of a circle"<<endl; cout<<"2. Calculate the area of a triangle"<<endl; cout<<"3. Quit"<<endl<<endl; //prompt for choice cout<<"Enter your choice(1-3): "; cin>>choice; cout<<endl; //if choice is circle if(choice==1) { cout<<"What is the radius of the circle? "; cin>>radius; //calculating area area=PI*radius*radius; cout<<endl<<"The area of the circle is "<<fixed<<setprecision(3)<<area<<endl; } //if choice...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors. b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class...
/* Program Name: BadDate.java Function: This program determines if a date entered by the user is...
/* Program Name: BadDate.java Function: This program determines if a date entered by the user is valid. Input: Interactive Output: Valid date is printed or user is alerted that an invalid date was entered. */ import java.util.Scanner; public class BadDate { public static void main(String args[]) { // Declare variables Scanner userInput = new Scanner (System.in); String yearString; String monthString; String dayString; int year; int month; int day; boolean validDate = true; final int MIN_YEAR = 0, MIN_MONTH = 1,...
Functions displayGrades and addGrades must be rewritten so that the only parameters they take in are...
Functions displayGrades and addGrades must be rewritten so that the only parameters they take in are pointers or constant pointers. Directions: Using the following parallel array and array of vectors: // may be declared outside the main function const int NUM_STUDENTS = 3; // may only be declared within the main function string students[NUM_STUDENTS] = {"Tom","Jane","Jo"}; vector <int> grades[NUM_STUDENTS] {{78,98,88,99,77},{62,99,94,85,93}, {73,82,88,85,78}}; Be sure to compile using g++ -std=c++11 helpWithGradesPtr.cpp Write a C++ program to run a menu-driven program with the...
USING C++ Topics: Friend functions Copy constructor ----------------------------------------------------------------------------------------------------------------------------------------- Lab 3.1 Create your objects in the stack...
USING C++ Topics: Friend functions Copy constructor ----------------------------------------------------------------------------------------------------------------------------------------- Lab 3.1 Create your objects in the stack (not on the heap). Add a friend function, kilotopound, which will convert kilograms to pounds. Change your weight mutator to ask whether weight is input in kilograms or pounds. If it is kilograms, call the friend function kilotopound to convert it to pounds and return pounds. There are 2.2 pounds in one kilogram. Create an object on the stack with the following information:     ...
MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment:...
MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: In cryptography, encryption is the process of encoding a message or information in such a way that only authorized parties can access it. In this lab you will write a program to decode a message that has been encrypted using two different encryption algorithms. Detailed specifications: Define an...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts,...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts, it will present a welcome screen. You will ask the user for their first name and what class they are using the program for (remember that this is a string that has spaces in it), then you will print the following message: NAME, welcome to your Magic Number program. I hope it helps you with your CSCI 1410 class! Note that "NAME" and "CSCI...
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in...
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in airplane const int COLS = 4; void menu(); //displays options void displaySeats(char[][COLS]); void reserveSeat(char [ROWS][COLS]); int main() { int number=0; //holder variable char seatChar[ROWS][COLS]; for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { seatChar[i][j] = '-'; } } int choice; //input from menu bool repeat = true; //needed for switch loop while (repeat...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT