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
Leigh Hall room 312
College of Arts and Sciences room 41
Kolbe Hall room 133
Whitby Hall room 111
Ayer Hall room 30
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
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
Get Answers For Free
Most questions answered within 1 hours.