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

#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;
}


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...
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
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...
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...
C program //In this assignment, we will find the smallest positive integer that // can be...
C program //In this assignment, we will find the smallest positive integer that // can be expressed as a sum of two positive cube numbers in two distinct ways. // More specifically, we want to find the smallest n such that n == i1*i1*i1 + j1*j1*j1, // n == i2*i2*i2 + j2*j2*j2, and (i1, j1) and (i2, j2) are not the same in the sense that // not only (i1, j1) not euqal to (i2, j2), but also (i1, j1)...
You are on a diet and you are writing a javascript program that determines whether or...
You are on a diet and you are writing a javascript program that determines whether or not you can treat yourself to an ice cream. Your program takes as input: 1. Number of calories you have taken so far that day. 2. Number of calories you are expecting to take later on that day (excluding the potential ice cream) 3. Number of calories you have burnt (or are expecting to burn) with exercise that day. 4. What is your goal...
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....
For this assignment I need to use information from a previous assignment which I will paste...
For this assignment I need to use information from a previous assignment which I will paste here: #ifndef TODO #define TODO #include <string> using std::string; const int MAXLIST = 10; struct myToDo {     string description;     string dueDate;     int priority; }; bool addToList(const MyToDo &td); bool addToList(string description, string date, int priority); bool getNextItem(MyToDo &td); bool getNextItem(string &description, string &date, int &priority); bool getByPriority(MyToDo list[], int priority int &count); void printToDo(); #endif #include <iostream> #include "ToDo.h" using namespace std; myToDo ToDoList[MAXLIST];...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT