Question
Write a C++ program that computes the cost of a long-distance call. The cost of the call is determined according to the following rate schedule:
Write a C++ program that computes the cost of a long-distance call.
The cost of the call is determined according to the following rate schedule:
a. Any call started between 8:00 A.M. and 6:00 P.M., Monday through Friday, is billed at a rate of $0.40 per minute.
b. Any call starting before 8:00 A.M. or after 6:00 P.M., Monday through Friday, is charged at a rate of $0.25 per minute.
c. Any call started on a Saturday or Sunday is charged at a rate of $0.15 per minute.
The input will consist of the day of the week, the time the call started, and the length of the call in minutes. The output will be the cost of the call. The time is to be input in 24-hour notation, so the time 1:30 P.M. is input as (must be the following format:) 13:30
The day of the week will be read as one of the following pairs of character values, which are stored in two variables of type char: Mo Tu We Th Fr Sa Su
Be sure to allow the user to use either uppercase or lowercase letters or a combination of the two. The number of minutes will be input as a value of type int.
Format your output to two decimal places.
Define the following functions (value returning functions, Cally-by-Value):
validateUserInputTime(): validates the user's time input (hours and minutes should be positive numbers only including zero), and returns TRUE or FALSE.
validateUserInputDay(): validates the user's day input (only characters are allowed: Mo Tu We Th Fr Sa Su), and returns TRUE or FALSE. Allow uppercase and lowercase input.
validateUserInputCallLength(): validates the user's call length input (only positive integers are allowed), and returns TRUE or FALSE.
calculateTotalCost(): calculate the total cost of a call, and returns the total cost.
Below is my work. It has an error.
#include
int hours, mins, minutes; char day1, day2, choice;
void main() {
do { cout >hours>> cout>mins>>;
cout > day1, day2;
cout > minutes;
if (((day1=='S'||day1 =='s')&&(day2 =='a'||day2=='A'))||(((day1=='S'|| day1=='s')&&(day2=='u'||day2=='U'))) { cout =8&&hours
} else { cout
cout>choice; }
while(choice=='y'||choice=='Y');
return 0;
}
Output should be as below
OUTPUTS:
**************************************************************************************
Enter the time the call starts in 24-hour rotation: -13:10
Invalid time input.
Please try again.
Enter the time the call starts in 24-hour rotation:
**************************************************************************************
Enter the time the call starts in 24-hour rotation: a:77
Invalid time input.
Please try again.
Enter the time the call starts in 24-hour rotation:
**************************************************************************************
Enter the time the call starts in 24-hour rotation: 13:10
Enter the first two letters of the day of the week: ss
Invalid day input.
Please try again.
Enter the first two letters of the day of the week:
**************************************************************************************
Enter the time the call starts in 24-hour rotation: 13:10
Enter the first two letters of the day of the week: 1s
Invalid day input.
Please try again.
Enter the first two letters of the day of the week:
**************************************************************************************
Enter the time the call starts in 24-hour rotation: 13:10
Enter the first two letters of the day of the week: Mo
Enter the length of the call in minutes: -10
Invalid minute input.
Please try again.
Enter the length of the call in minutes:
**************************************************************************************
Enter the time the call starts in 24-hour rotation: 13:10
Enter the first two letters of the day of the week: Mo
Enter the length of the call in minutes: a1
Invalid minute input.
Please try again.
Enter the length of the call in minutes:
**************************************************************************************
Enter the time the call starts in 24-hour rotation: 13:10
Enter the first two letters of the day of the week: Mo
Enter the length of the call in minutes: 10
Cost of the call: $4.00
Do you want to repeat the program (y)? y
**************************************************************************************
Enter the time the call starts in 24-hour rotation: 20:10
Enter the first two letters of the day of the week: Fr
Enter the length of the call in minutes: 10
Cost of the call: $2.50
Do you want to repeat the program (y)? y
**************************************************************************************
Enter the time the call starts in 24-hour rotation: 10:10
Enter the first two letters of the day of the week: Su
Enter the length of the call in minutes: 10
Cost of the call: $1.50
Do you want to repeat the program (y)? n
Expert Answer
Anonymous answered this
Was this answer helpful?
0
1
8,522 answers
Here is the code for you:
#include
//validateUserInputTime(): validates the user's time input (hours and minutes should be //positive numbers only including zero), and returns TRUE or FALSE. bool validateUserInputTime(int hours, int minutes) { if(hours 23 || minutes 59) return false; return true; }
//validateUserInputDay(): validates the user's day input (only characters are allowed: //Mo Tu We Th Fr Sa Su), and returns TRUE or FALSE. Allow uppercase and lowercase input. bool validateUserInputDay(string weekDay) { weekDay = tolower(weekDay[0]) + tolower(weekDay[1]); if(!weekDay.compare("mo")) return true; else if(!weekDay.compare("tu")) return true; else if(!weekDay.compare("we")) return true; else if(!weekDay.compare("th")) return true; else if(!weekDay.compare("fr")) return true; else if(!weekDay.compare("sa")) return true; else if(!weekDay.compare("su")) return true; return false; }
//validateUserInputCallLength(): validates the user's call length input //(only positive integers are allowed), and returns TRUE or FALSE. bool validateUserInputCallLength(int callLength) { if(callLength
//calculateTotalCost(): calculate the total cost of a call, and returns the total cost. double calculateTotalCost(int callLength, string weekDay, int hours, int minutes) { if(!weekDay.compare("sa") && !weekDay.compare("su")) { if(hours 5) return 0.25 * callLength; else return 0.40 * callLength; } else return 0.15 * callLength; }
int main() { int hours, minutes, callLength; char temp, repeat; string weekDay; while(true) { cout > hours; if(!validateUserInputTime(hours, 0)) { cout > temp; cin >> minutes; if(!validateUserInputTime(hours, minutes)) { cout > weekDay; if(!validateUserInputDay(weekDay)) { cout > callLength; if(!validateUserInputCallLength(callLength)) { cout > repeat; if(repeat == 'y' || repeat == 'Y') return 0; } }
Please help as the answer I was given does not compile.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started