Create a program using n loop, that displays the registration information for me
ID: 3797381 • Letter: C
Question
Create a program using n loop, that displays the registration information for medical conferences. The price per person depends on the number of people a hospital registers (For example if a hospital registers 5 people then the amount owed by that hospital is $552.50) The following chart shows the charges per registrant: Number of Registrants 1-3 Charge Per Person $129.50 Number of Registrants 4-10 Charge Per Person $110.50 Number of Registrants 11 or more Charge Per Person $84.00 The program should allow the user to enter the number registered for as many hospitals as desired One of the easiest ways to write this program uses a sentinel of some sort (make sure the user knows how to stop the program loop). The program should display the total number of people registered, the total charge and the average per registrant. (For example, if one company registers 5 people and a second company registers 2 people, then the total number of people registered is 7. The total is $811.50, and the average charge per registrant is $115.93).Explanation / Answer
Code:
#include<iostream>
using namespace std;
class Registration
{
int hospital;
int no_of_reg;
float charge;
public:
Registration(){ hospital=no_of_reg=0;
charge=0.0;
}
void setValues(int h,int r){ hospital=h; no_of_reg=r;
if(r>=1 && r<=3) charge=129.50;
else if(r>3 && r<=10) charge=110.50;
else charge=84.0;
}
void getValues(int &h,int &r, float &c)
{
h=hospital;
r=no_of_reg;
c=charge;
}
};
int main(void)
{
Registration *r=new Registration[20];
int i=0,n;
int count=0;
cout<<"Enter hospital number and registration number(-1,-1 to exit):";
cin>>i>>n;
while(i!=-1)
{
r[count].setValues(i,n);
count++;
cout<<"Enter hospital number and registration number(-1.-1 to exit):";
cin>>i>>n;
}
int h=0,reg=0;
float c=0.0;
int total_registrations=0;
float tot_charge=0.0, tot_avg;
for(int j=0;j<count;j++)
{
r[j].getValues(h,reg,c);
total_registrations+=reg;
tot_charge= tot_charge + (reg*c);
cout<<"Hospital:"<<h<<", Number of registrations:"<<reg<<endl;
}
tot_avg= tot_charge/total_registrations;
cout<<"The total number of registrations:"<<total_registrations<<endl;
cout<<"Total charge:"<<tot_charge<<endl;
cout<<"Average charge:"<<tot_avg<<endl;
return 0;
}
Output:
Enter hospital number and registration number(-1,-1 to exit):1 5
Enter hospital number and registration number(-1.-1 to exit):2 2
Enter hospital number and registration number(-1.-1 to exit):-1 -1
Hospital:1, Number of registrations:5
Hospital:2, Number of registrations:2
The total number of registrations:7
Total charge:811.5
Average charge:115.929
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.