I need a program wrote in C++ with an explanation after each line of code to sol
ID: 3537487 • Letter: I
Question
I need a program wrote in C++ with an explanation after each line of code to solve the problem below.
An Internet service provider has three different subscription packages for it customers:
Package A: For $9.95 per month 10 hours of access are provided. Additional hours are $2.00 per hour.
Package B: For $14.95 per month 20 hours of access are provided. Additional hours are $1.00 per hour.
Package C: For $19.95 per month for unlimited access is provided.
Write a program that calculates a customer%u2019s monthly bill. It should ask customers id, which package the customer has purchased, and how many hours were used. It should then display the total amount due.
Get the above part to work first. Use the following data to test your program:
98324 C 20
78273 A 8
52323 A 30
72872 B 20
13423 B 35
99872 C 21
Now, we need a little more information. Modify the above program so that it also displays how much money Package A customers would save if they purchased packages B or C, and how much money Package B customers would save if they purchased Package C. If there would be no savings, no message should be printed.
Hint: Write two functions %u2018SavingsOnB%u2019 and %u2018SavingsOnC%u2019. When calculate Package A, you will then call both functions. The functions will print out the savings or the function will print nothing.
Same for Package B, call SavingsOnC.
Label ALL output
Use functions, comments, nice program format(indent)
MUST READ TO AN OUTFILE AS WELL AS VIEW ON CONSOLE AND BE BASIC SIMPLY PROGRAMMING FOLLOWING ABOVE SPECS EXACTLY!!! Have any questions please ask....thanks!!
I have the following code....I just need function for customer id's and read to an outfile......
#include <iostream>
using namespace std;
int main()
{int hours;
char pack;
double totA,totB,totC;
cout<<"Make a Selection ";
cout<<"(A)Package A ";
cout<<"(B)Package B ";
cout<<"(C)Package C ";
cout<<"Enter your selection: ";
cin>>pack;
cout<<"Enter hours: ";
cin>>hours;
if(hours>744)
cout<<"That's more hours then in a month!! ";
else
{ if(hours<10)
totA=9.95;
else
totA=9.95+(hours-10)*2;
if(hours<20)
totB=14.95;
else
totB=14.95+(hours-20);
totC=19.95;
}
switch (pack)
{case 'A':cout<<"Monthly Bill: $"<<totA<<endl;
cout<<"if had chosen package B would have saved $"<<totA-totB<<endl;
cout<<"if had chosen package C would have saved $"<<totA-totC<<endl;
break;
case 'B':cout<<"Monthly Bill: $"<<totB<<endl;
cout<<"if had chosen package C would have saved $"<<totB-totC<<endl;
break;
case 'C':cout<<"Monthly Bill: $"<<totC<<endl;
break;
}
return 0;
}
Explanation / Answer
#include <iostream>
#include <iostream>
#include <fstream>
using namespace std;
double SavingsOnC(int hours,double B_cost)
{
return (B_cost -19.95 );
}
double SavingsOnB(int hours, double A_cost)
{
if(hours >20)
return (A_cost - 14.95-(hours-20));
return 0.0;
}
int main()
{
int hours;
int customer_id;
char pack;
ofstream outfile("out.txt");
double totA,totB,totC;
cout<<" Enter customer_id ";
cin >> customer_id;
cout<<"Make a Selection ";
cout<<"(A)Package A ";
cout<<"(B)Package B ";
cout<<"(C)Package C ";
cout<<"Enter your selection: ";
cin>>pack;
cout<<"Enter hours: ";
cin>>hours;
if(hours>744)
{
cout<<"That's more hours then in a month!! ";
return 0;
}
switch (pack)
{
case 'A':
{
if(hours <10) totA = 9.95;
else totA = 9.95 + (hours-10)*2;
cout<<"Monthly Bill: $"<<totA<<endl;
outfile<<"Monthly Bill: $"<<totA<<endl;
double savings_on_B = SavingsOnB(hours,totA);
if(savings_on_B>0)
cout<<"if had chosen package B would have saved $"<<savings_on_B<<endl;
outfile<<"if had chosen package B would have saved $"<<savings_on_B<<endl;
double savings_on_C = SavingsOnC(hours,totA);
if(savings_on_C>0)
cout<<"if had chosen package C would have saved $"<<savings_on_C<<endl;
outfile<<"if had chosen package C would have saved $"<<savings_on_C<<endl;
}
break;
case 'B':
{
if(hours <20) totB = 14.95;
else totB = 14.95+(hours-20);
cout<<"Monthly Bill: $"<<totB<<endl;
outfile<<"Monthly Bill: $"<<totB<<endl;
double savings_on_C = SavingsOnC(hours,totB);
if(savings_on_C >0)
cout<<"if had chosen package C would have saved $"<<savings_on_C<<endl;
outfile<<"if had chosen package C would have saved $"<<savings_on_C<<endl;
}
break;
case 'C':
{
cout<<"Monthly Bill: $"<< (19.95) <<endl;
outfile<<"Monthly Bill: $"<< (19.95) <<endl;
}
break;
}
outfile.close();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.