Question

In: Computer Science

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

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.

Solutions

Expert Solution

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


  
  
  
  


Related Solutions

C++ For the assignment, we will use the previous assignment’s program that determines whether a college...
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...
C++ For the assignment, we will use the previous assignment’s program that determines whether a college...
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...
Use Excel to answer. A college admission officer for an MBA program determines that historically candidates...
Use Excel to answer. A college admission officer for an MBA program determines that historically candidates have undergraduate grade averages that are normally distributed with standard deviation of .45. A random sample of 25 applications from the current year yields a sample mean grade point average of 2.90. Find a 95% confidence interval for the population mean, μ. (Round the boundaries to 2 decimal places.) Based on the same sample results, a statistician computes a confidence interval for the population...
Programming Assignment #2, Processes Write a C program (time_shm.c) that determines the amount of time necessary...
Programming Assignment #2, Processes Write a C program (time_shm.c) that determines the amount of time necessary to run a command from the command line. This program will be run as ./time <command [args...]> and will report the amount of elapsed time to run the specified command. This will involve using fork() and execvp() functions, as well as the gettimeofday() function to determine the elapsed time. It will also require the use of two different IPC mechanisms. The general strategy is...
Write a program that determines whether an input string is a palindrome; that is, whether it...
Write a program that determines whether an input string is a palindrome; that is, whether it can be read the same way forward and backward. At each point, you can read only one character of the input string; do not use an array to first store this string and then analyze it (except, possibly, in a stack implementation). Consider using multiple stacks. In Pseudocode please
This C++ assignment asks to write a function that determines if a C-string begins with a...
This C++ assignment asks to write a function that determines if a C-string begins with a specified prefix. It should have the following signature: bool starts(char *str, char *prefix) It should return true if str begins with prefix, false if not. It should return false if prefix is longer than str. See the table below for some examples of what your function should return for various cases: str prefix returns airplanes air true airplanes abc false airplanes plane false airplanes...
Program Assignment 1 C++ please Instructions This assignment will require the use of three arrays, which...
Program Assignment 1 C++ please Instructions This assignment will require the use of three arrays, which will be used in parallel. Create a program that keeps track of the sales of BBQ sauces for a company. The company makes several different types of sauces, Original, Sticky Sweet, Spicy, Sweet Heat, Hickory Bourbon and Smokey Mesquite. One array will contain the names of the different BBQ sauces. This array will be initialized from a text file with the 6 different names....
c++ program You are to use a Heap data structure for this assignment I currently work...
c++ program You are to use a Heap data structure for this assignment I currently work for an investment/insurance company and I’m looking for clients to call, ones with funds.  I need to have a schedule that shows the list of customers to call and the order to be called.  The list of customers names and phone numbers are in the file ‘NamesAndPhoneV2.txt’.  A second file contains a net worth value for each client.  The files are separated for security and protection reasons, but...
designing a multithreaded application in C that determines whether the solution to a Sudoku puzzle is...
designing a multithreaded application in C that determines whether the solution to a Sudoku puzzle is valid A Sudoku puzzle uses a 9×9 grid in which each column and row, as well as each of the nine 3×3 subgrids, must contain all of the digits 1 to 9. main.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <pthread.h> int puzzle[PUZZLE_SIZE+1][PUZZLE_SIZE+1]; int status_map[NUMBER_OF_THREADS];    parameters* worker_params[NUMBER_OF_THREADS]; pthread_t workers[NUMBER_OF_THREADS]; int main(int argc, char** argv) {    //Read the sudoku solution from  the file specified...
Compute in excel A college admission officer for an MBA program determines that historically candidates have...
Compute in excel A college admission officer for an MBA program determines that historically candidates have undergraduate grade averages that are normally distributed with standard deviation of .45. A random sample of 25 applications from the current year yields a sample mean grade point average of 2.90. (i) Find a 95% confidence interval for the population mean, μ. (Round the boundaries to 2 decimal places.) (ii) Based on the same sample results, a statistician computes a confidence interval for the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT