Question

In: Computer Science

Code in c++, do not use loops, make it as simple as it can be. Thanks!...

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

Solutions

Expert Solution

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


Related Solutions

C++ Code While Loops. Ask user for file and open file. Do priming read and make...
C++ Code While Loops. Ask user for file and open file. Do priming read and make a while loop that: 1. Reads in numbers. 2. Counts how many there is. 3. Also for every 10 numbers in the file, print out the average of those 10 numbers. Ex: (If 20 numbers in the file. "With 10 numbers the average is .... and With 20 numbers the average is" and EX for a file with 5 numbers "There are 5 numbers...
Code in Python. You can only use while loops NOT for loops. Program 1: cost_living In...
Code in Python. You can only use while loops NOT for loops. Program 1: cost_living In 2020 the average cost of living/month (excluding housing) for a family of 4 in Pittsburgh was $3850 per month. Write a program to print the first year in which the cost of living/month is over $4450 given that it will rise at a rate of 2.1% per year. (Note:  this program requires no input). Program 2: discount A discount store is having a sale where...
CODE MUST BE IN C++ (please use for loop) write a program that loops a number...
CODE MUST BE IN C++ (please use for loop) write a program that loops a number from 1 to 10 thousand and keeps updating a count variable (count variable starts at 0 ) according to these rules: n1 = 14 n2 = 54 n3 = 123 if the number is divisible by n1, increase count by 1 if the number is divisible by n2, increase count by 2 if the number is divisible by n3, increase count by 3 if...
Please use simple terms so I can understand better. thanks! Why do cells need to multiply?...
Please use simple terms so I can understand better. thanks! Why do cells need to multiply? Discuss a few reasons. Try to do this without using the word “reproduction” or “reproduce”. Define homologous chromosomes Discuss the chromosomal number of cells before mitosis and after mitosis Is mitosis involved in asexual reproduction? What are telomeres and why are they important? How does cytokinesis (cytoplasmic division) differ in animal cells vs plant cells? Define oncogene, proto-oncogene, neoplasm, tumor, and metastasis
THE STRING MATCH PROBLEM C++ only. Must use loops. Please do not use sequence of if...
THE STRING MATCH PROBLEM C++ only. Must use loops. Please do not use sequence of if statements. . Given 2 strings, a and b, set result to the number of the positions where they contain the same length 2 substring. So "xxcaazz" and "xxbaaz" yields 3, since the "xx", "aa", and "az" substrings appear in the same place in both strings. • for input of "xxcaazz", "xxbaaz" → 3 • for input of "abc", "abc" → 2 • for input...
Solve this question in C++ language. DO NOT use loops. Use recursive function. Keep the program...
Solve this question in C++ language. DO NOT use loops. Use recursive function. Keep the program simple. Q (5) Suppose you have been given the task to design a text editor which will take any multiline text from user and then display the statistics like total number of characters i.e., characters_count (excluding the white space and punctuations), words_count, and redundant_words_count. Create a structure named Text_Editor having four type members namely inserted_text (of type string), characters_count (of type unsigned int), words_count...
I need the code for following in C++ working for Visual studio please. Thanks Use a...
I need the code for following in C++ working for Visual studio please. Thanks Use a Struct to create a structure for a Player. The Player will have the following data that it needs maintain: Struct Player int health int level string playerName double gameComplete bool isGodMode Create the 2 functions that will do the following: 1) initialize(string aPlayerName) which takes in a playername string and creates a Player struct health= 100 level= 1 playerName = aPlayerName gameComplete = 0...
C++ Code while loops. 1. Ask for file name and open file. 2. Do a priming...
C++ Code while loops. 1. Ask for file name and open file. 2. Do a priming read and make a while loop that A) Reads in numbers B) Sums them up. C) Counts how many there are. D) Prints "With 10 numbers, the average is blank.." every 10 numbers. So with every 10 numbers read in print the average. 3. After the loop calculate average of all numbers and print it. So for example once the file is open the...
(C++) Why does my code not continue looping? it only loops twice. Can someone take a...
(C++) Why does my code not continue looping? it only loops twice. Can someone take a look at my code so far: #include <iostream> #include <cmath> #include <cstdlib> #include <string> #include <ctime> using namespace std; void cls(void); void cls(void) { system("cls||clear"); return; } int main() { int BankBalance = 0; char quit; int wager = 0; int inputWager = 0; int sum = 0; int diceRoll = 0; int rollPoint = 0; int point = 0; int dice1 = 0;...
C language only please and please make a simple code Write a function that will find...
C language only please and please make a simple code Write a function that will find whether there exist two integers that sum to the target integer. The function is to “return” three values.First, return “1” if the integers were found,return “-1” if your search was not successful.If you find two integers which add up to the target value, you should return their respective index position inside the array. Suggested prototype:int TwoSumFunction(int arr[], int size, int target, int*index1, int* index2);Inside...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT