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.
#include <iostream>
#include <string.h>
//to check which class user wants to have
/*
* Arrays Are never passes by value. These are already passed by
reference
* capacity (formal argument) is not altered within the function.
Hence it is not reflected in the actual argument
* changing return type to cater to the requirement of returning
total back to main.
*/
int checkClass(char message[], int& capacity)
{
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 - ((atten * 100) /
(float)capacity);
cout << "It is legal to hold
class and there is minimal " << perc << " capacity
remaining\n";
}
return atten;
}
int main()
{
int classes, attendees, room;
int choice; //input for user choice;
//LOCAL VARIABLES DECLARED IN MAIN//
int defvalues[] = { 312, 41, 133, 111, 30 };
int capacities[5] = { 0 };
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: capacities[choice - 1] =
checkClass((char*)"Leigh Hall room 312",
defvalues[choice-1]);
break;
case 2: capacities[choice - 1] =
checkClass((char*)"College of Arts and Sciences room",
defvalues[choice - 1]);
break;
case 3: capacities[choice - 1] =
checkClass((char*)"Kolbe Hall room", defvalues[choice - 1]);
break;
case 4: capacities[choice - 1] =
checkClass((char*)"Whitby Hall room", defvalues[choice - 1]);
break;
case 5: capacities[choice - 1] =
checkClass((char*)"Ayer Hall room", defvalues[choice - 1]);
break;
case 6:
cout <<
"\nFor Leigh Hall room 312:\nYour total is " << capacities[0]
<< " out of" << defvalues[0]
<< " and there is minimal " << 100 -
((capacities[0] * 100) / (float)defvalues[0]) << " capacity
remaining";
cout <<
"\nFor College of Arts and Sciences room:\nYour total is " <<
capacities[1] << " out of " << defvalues[1]
<< " and there is minimal " << 100 -
((capacities[1] * 100) / (float)defvalues[1]) << " capacity
remaining";
cout <<
"\nKolbe Hall room:\nYour total is " << capacities[2]
<< " out of" << defvalues[2]
<< " and there is minimal " << 100 -
((capacities[2] * 100) / (float)defvalues[2]) << " capacity
remaining";
cout <<
"\nWhitby Hall room:\nYour total is " << capacities[3]
<< " out of" << defvalues[3]
<< " and there is minimal " << 100 -
((capacities[3] * 100) / (float)defvalues[3]) << " capacity
remaining";
cout <<
"\nAyer Hall room:\nYour total is " << capacities[4] <<
" out of" << defvalues[4]
<< " and there is minimal " << 100 -
((capacities[4] * 100) / (float)defvalues[4]) << " capacity
remaining";
cout <<
"\nBye";
return 0;
}
}
return 0;
}