In: Computer Science
n this exercise, you create a program for the sales manager at Computer Haven, a small business that offers motivational seminars to local companies. Figure 7-53 shows the charge for attending a seminar. Notice that the charge per person depends on the number of people the company registers. For example, the cost for four registrants is $400; the cost for two registrants is $300. The program should allow the sales manager to enter the number of registrants for as many companies as needed. When the sales manager has finished entering the data, the program should calculate and display the total number of people registered, the total charge for those registrants, and the average charge per registrant. For example, if one company registers four people and another company registers two people, the total number of people registered is six, the total charge is $700, and the average charge per registrant is $116.67. Number of people a company registers . Charge per person ($)
1 – 3 150
4 – 9 100
10 or more 90
fig 7-53
a.Create an IPO chart for the problem, and then desk-check the algorithm appropriately.b.List the input, processing, and output items, as well as the algorithm, in a chart similar to the one shown earlier in Figure 7-42. Then code the algorithm into a program.c.Desk-check the program using the same data used to desk-check the algorithm.d.If necessary, create a new project named Advanced25 Project, and save it in the Cpp8\Chap07 folder. Enter your C++ instructions into a source file named Advanced25.cpp. Also enter appropriate comments and any additional instructions required by the compiler. Display the average charge with two decimal places
Below is the code for given problem with proper commenting, just copy and run the program :
#include <iostream>
using namespace std;
class SalesManager{
private:
int num_of_attendees;
public:
//mutators to set the value
void setNumberofAttendies(int num_of_attendees)
{
this->num_of_attendees = num_of_attendees;
}
//accessors to get the value
int getNumberofAtendees()
{
return num_of_attendees;
}
};
//main function, from where execution start
int main()
{
int num_of_companies;
int attendees;
int total_attendees = 0;
cout<<"Welcome to the computer Heaven\n";
cout<<"Total no of companies : ";
cin >> num_of_companies;
//no of object is equal to no of companies
SalesManager sm[num_of_companies];
for(int i=1; i<=num_of_companies; i++)
{
cout<<"For Company "<<i<<" ---> ";
cout<<"Total num of attendees : ";
cin >> attendees;
if(attendees < 0)
{
cout<<"People count can not be negative";
i--;
}
else
{
//setting the number of attendies
sm[i-1].setNumberofAttendies(attendees);
//getting the number of attendees value
total_attendees += sm[i-1].getNumberofAtendees();
}
}
int total_charge;
int average_charge;
cout<<"Total Attendees :
"<<total_attendees<<"\n";
//If-Else statements to calculate total charge
if(total_attendees>0 && total_attendees<=3)
{
total_charge = total_charge * 150;
}
else if( total_attendees>3 &&
total_attendees<=9)
{
total_charge = total_attendees * 100;
}
else
{
total_charge = total_attendees * 90;
}
cout<<"Total Charge :
"<<total_charge<<"\n";
average_charge = total_charge/total_attendees;
cout<<"Average Charge : "<<average_charge;
return 0;
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Output :
------------------------------------------------------------------------------------------------------------------------------------------------------------------
IPO Chart :