In: Computer Science
Code in c++, do not use loops, make it as simple as it can be. Thanks!
Background Well it has finally happened; AMC’s “The Walking Dead” has become a reality. The zombie apocalypse took place. It has been a couple of years since we have started to “rebuild” our society, and now is the time for you to be able to shine. We have come across technology that will allow for us to get back to life as it once was in the early 2000’s. Yes, we are still going to be 17 years back but it’s better than nothing. With all the Computer Scientists and Engineers that survived in the area, everything is almost back to normal except for the use of cell phones. People have been able to start-up businesses again, and we are trying to become as we once were. People work and get paid and of course we want the commodities that we once had. In a venture of remembering how people were glued to their cell phones you have decided to start a service. Why not!? You found a warehouse that had all the cell phones that you can distribute to those around in the area, and you have been working with others to get an infrastructure back. You now just have to come up with a quick system to be able to get people hooked before they get used to not having their phones anymore. With the fact that you must have a quick turn-around, you are putting together a simple plan and will later expand on the idea. You have everything ready to go and to sign people up, but you still need the billing to be generated. This is what you must work on now. You are only going to give users the options of two types of service, regular and premium.
To compute the rates you have the following established: 1. Regular service - $6.00 plus first 50 minutes free. Charges for over 50 minutes are $0.20 per minute. 2. Premium service - $15.00 plus: a. For calls made from 6:00am to 6:00pm, the first 75 minutes are free; charges for over 75 minutes are $0.10 per minute. b. For calls made from 6:00pm to 6:00am, the first 100 minutes are free; charges for over 100 minutes are $0.05 per minutes. Task Your task at the moment is to calculate and print out the bill for your customers. Your program should: 1. prompt the user to enter an account number, 2. a service code (type char), a. A service code of r or R means regular service b. A service code of p or P means premium service c. Treat any other character as an error 3. the number of minutes the service was used. Your program should output the account number, type of service, number of minutes the telephone service was used, and the amount due from the user. For the premium service, the customer may be using the service during the day and the night. Therefore, to calculate the bill, you must ask the user to input the number of minutes the service was used during the day and the number of minutes the service was used during the night. Concepts to follow: 1. Assign values to all constant variables that are associated with charges and number of minutes provided in the problem description. 2. The only information the user enters are: account number, type of service, minutes used, and day/night time minutes used based on the plan they have. 3. Remember you are dealing with money therefore should only have 2 decimal places. 4. You must use both a switch statement AND if/else, if/else if’s, or if’s as you see fit. 5. Keep in mind to check for input validation. If validation is incorrect you should have an error message and “kill” your program. 6. Do not use loops
I have solved your question. I have not used for loops and all the points of your question have been taken care of. I have also made the code as simple as possible. I have also kept the variable names easy and I have also added comments for your understanding of difficult parts. The code is working perfectly fine as expected with all desired outputs. I have also typed in the code here instead of taking screenshots, so that it is easier for you to copy and paste.
Please do kindly click on the thumbs up button. Thank you very much.
#include<iostream>
#include<process.h> //this header file is used for exit(0)
function
using namespace std;
int main()
{
char service_code;int mins,mins_day,mins_night;int acct_no;
int ch; //ch stands for choice
float amt=0;
int backup_mins_night,backup_mins_day,backup_mins; //used to create
a copy of the mins variables for displaying output, as the original
variables get modified while doing calculations.
cout<<"Enter account no. ";
cin>>acct_no;
cout<<"Enter Service code ";
cin>>service_code;
if(service_code=='r' or service_code=='R')
{
ch=1;
cout<<"Enter number of mins the service was used ";
cin>>mins;
backup_mins=mins;
}
else if(service_code=='p' or service_code=='P')
{
ch=2;
cout<<"Enter number of mins the service was used in day
";
cin>>mins_day;
backup_mins_day=mins_day;
cout<<"Enter number of mins the service was used in night
";
cin>>mins_night;
backup_mins_night=mins_night;
}
else
{ ch=3;
cout<<"Error";
exit(0); //exit program
}
switch(ch)
{
case 1: amt=6;
mins=mins-50;
if(mins>0)
{
amt=amt+mins*0.20;
}
break;
case 2: amt=15;
if(mins_day!=0)
{
mins_day=mins_day-75;
if(mins_day>0)
{
amt=amt+mins_day*0.10;
}
}
if(mins_night!=0)
{
mins_night=mins_night-100;
if(mins_night>0)
{
amt=amt+mins_night*0.05;
}
}
break;
}
cout<<"The account no. is
"<<acct_no<<endl;
if(ch==1)
{
cout<<"the type of service used is
"<<"regular"<<endl;
cout<<"the number of mins the service was used is
"<<backup_mins<<endl;
}
else if(ch==2)
{
cout<<"the type of service used is
"<<"premium"<<endl;
cout<<"the number of mins the service was used is
"<<backup_mins_day+backup_mins_night<<endl;
}
printf("Amount due is %.2f ", amt); //rounding to 2 decimal
places
return 0;
}