In: Computer Science
C++
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…
Convert all of the function’s parameters from pass by value to pass by reference.
Accumulate totals for each of the class rooms that we are using for this program. When the program ends (user choice of 6), display those totals for each class room before you return 0 in main.
Create local scope variables in main for the totals, and return them back to main for displaying them.
You should reuse code (the same function) for determining percentage of capacity remaining.
Match your program with the sample output as shown below.
… the following now displays after user entry to quit …
For Leigh Hall room 312:
Your total is 687 out of 700 and there is minimal 1.86% capacity remaining
For College of Arts and Sciences room 41:
Your total is 220 out of 225 and there is minimal 2.23% capacity remaining
…
…
…
Remember that your program still has the same functionality as before, has a menu, etc. Make sure that your programs follow good documentation standards and follow the requirements for assignments. Reference the rubric standards on Brightspace. Do not use namespace std!!!!!!!!!!!!!!!!!.
previous program below:
#include
using namespace std;
//to check which class user wants to have
void checkClass(string message,int capacity)
{
cout< 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 "<
}
}
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;
}
the code that i put in here is the previous program that was used in the previous assignment.
C++ program for the provided problem statement
/*
* C++ program to calculate the percentage of space remaining based
on the user input
* Local variables and Arrays are declared in the main
function
* In C/C++, arrays are always passed by reference
* User input (attendees) is reflected in the main function.
*/
#include <iostream>
#include <string.h>
#include <iomanip>
using namespace std;
// this function will ask for the number of attendees
// If the user provides correct input then it will calculate and
display the percentage of space remaining in the Class Room
int checkClass(char classRoom[], int& maxCapacity)
{
// take user input for attendes
int attendes;
cout<< "\nEnter the number of attendes: ";
cin >> attendes;
// check if provided input is less than or equal to max Capacity of
class room
// if yes then calculate percentage of space remaining
// otherwise display error message
if (attendes <= maxCapacity)
{
float percentage = 100-((attendes*100)/(float)maxCapacity);
cout << "It is legal to hold class and there is minimal
"<< fixed << setprecision(2) << percentage
<< "% capacity remaining.\n\n";
}
else
{
cout << "The class cannot be held as planned !!\n\n";
}
return attendes;
}
// main function
int main()
{
// declare local variables
int choice=0;
// it holds maximum capacity of each class room
int maxClassRoomCapacities[5] = {312, 41, 133, 111, 30};
// it will hold user provided capacity of each class room
int attendesCapacities[5] = {0};
//display the menu to the user
while(choice != 6)
{
cout << " Please choose a room from the menu\n";
cout << "\t1.Leigh Hall room 312\n";
cout << "\t2.College of Arts and Sciences room 41\n";
cout << "\t3.Kolbe Hall room 133\n";
cout << "\t4.Whitby Hall room 111\n";
cout << "\t5.Ayer Hall room 30\n";
cout << "\t6.Quit\n";
while (true)
{
cout << "\nEnter your choice: ";
cin >> choice;
if(choice<1 || choice>6){
cout << "Invalid choice !!\n";
}else{
break;
}
}
if(choice == 1){
attendesCapacities[choice-1] = checkClass((char*)"Leigh Hall room
312", maxClassRoomCapacities[choice-1]);
}
else if(choice == 2){
attendesCapacities[choice-1] = checkClass((char*)"College of Arts
and Sciences room", maxClassRoomCapacities[choice-1]);
}
else if(choice == 3){
attendesCapacities[choice-1] = checkClass((char*)"Kolbe Hall room",
maxClassRoomCapacities[choice-1]);
}
else if(choice == 4){
attendesCapacities[choice-1] = checkClass((char*)"Whitby Hall
room", maxClassRoomCapacities[choice-1]);
}
else if(choice == 5){
attendesCapacities[choice-1] = checkClass((char*)"Ayer Hall room",
maxClassRoomCapacities[choice -1]);
}
else{
cout << "\nFor Leigh Hall room 312:\nYour total is " <<
attendesCapacities[0] << " out of " <<
maxClassRoomCapacities[0]
<< " and there is minimal " <<
100-((attendesCapacities[0]*100)/(float)maxClassRoomCapacities[0])
<< "% capacity remaining.\n";
cout << "\nFor College of Arts and Sciences room 41:\nYour
total is " << attendesCapacities[1] << " out of "
<< maxClassRoomCapacities[1]
<< " and there is minimal " <<
100-((attendesCapacities[1]*100)/(float)maxClassRoomCapacities[1])
<< "% capacity remaining.\n";
cout << "\nFor Kolbe Hall room 133:\nYour total is " <<
attendesCapacities[2] << " out of " <<
maxClassRoomCapacities[2]
<< " and there is minimal " <<
100-((attendesCapacities[2]*100) /
(float)maxClassRoomCapacities[2]) << "% capacity
remaining.\n";
cout << "\nFor Whitby Hall room 111:\nYour total is "
<< attendesCapacities[3] << " out of " <<
maxClassRoomCapacities[3]
<< " and there is minimal " <<
100-((attendesCapacities[3]*100) /
(float)maxClassRoomCapacities[3]) << "% capacity
remaining.\n";
cout << "\nFor Ayer Hall room 30:\nYour total is " <<
attendesCapacities[4] << " out of " <<
maxClassRoomCapacities[4]
<< " and there is minimal " <<
100-((attendesCapacities[4]*100) /
(float)maxClassRoomCapacities[4]) << "% capacity
remaining.\n";
return 0;
}
}
return 0;
}
C++ Program
Screenshots
C++ Program Output Screenshots