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…
For each new class entry that is taken, you will write out the information to a file. The file can be any .txt file name of your choosing. The file should be appended to each time the program runs (see app mode). The format of the file should be as follows:
Begin each new line or record with the name of the class room
Next, add the attendance for the first entry
Follow that with the total possible attendance for the first entry
Continue adding each attendance and possible attendance for the subsequent entries until you reach the last one
That’s it. Be sure to format this file so you can also read it later.
Remember, the program continues doing everything that it did before, plus these enhancements. Match your program with the sample output as shown below.
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
… the file for the example above might look like this …
Whitby Hall room 111 72 75 92 75 75 75
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.
the previous assignment is posted below.
#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;
}
#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 };
char menu[6]={"Leigh Hall room 312","College of Arts and Sciences room 41","Kolbe Hall room 133","Whitby Hall room 111","Ayer Hall room 30","Quit"};
fstream myfile;
myfile.open("Hall_Info.txt");
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])
defvalues[choice-1]=defvalues[choice-1]-capacities[choice-1];
myfile<<message<<":Has\n"<<atten<<"attendes"<<"
\ntotal possible attendes for entry:"<<
defvalues[choice-1];
break;
case 2: capacities[choice - 1] = checkClass((char*)"College of Arts and Sciences room", defvalues[choice - 1]);
defvalues[choice-1]=defvalues[choice-1]-capacities[choice-1];
myfile<<message<<":Has\n"<<atten<<"attendes"<<" \ntotal possible attendes for entry:" << defvalues[choice-1];
break;
case 3: capacities[choice - 1] = checkClass((char*)"Kolbe Hall
room", defvalues[choice - 1]);
defvalues[choice-1]=defvalues[choice-1]-capacities[choice-1];
myfile<<message<<":Has\n"<<atten<<"attendes"<<"
\ntotal possible attendes for entry:" <<
defvalues[choice-1];
break;
case 4: capacities[choice - 1] = checkClass((char*)"Whitby Hall
room", defvalues[choice - 1]);
defvalues[choice-1]=defvalues[choice-1]-capacities[choice-1];
myfile<<message<<":Has\n"<<atten<<"attendes"<<"
\ntotal possible attendes for entry:"<<
defvalues[choice-1];
break;
case 5: capacities[choice - 1] = checkClass((char*)"Ayer Hall
room", defvalues[choice - 1]);
defvalues[choice-1]=defvalues[choice-1]-capacities[choice-1];
<<message<<":Has\n"<<atten<<"attendes"<<"
\ntotal possible attendes for entry:"<<
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;
}