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.
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
**************************************************************************************
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
**************************************************************************************
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?
n
#include<iostream>
#include<string>
#include<sstream>
using namespace std;
//declaration of all functions
bool validatevalidateUserInputTime(string time);
bool validateUserInputDay(char a, char b);
bool validateUserInputCallLength(int minute);
float calculateTotalCost(string time, char a, char b, int minute);
int main() {
string time;
char a, b;
int minute;
char choice = 'y';
while (choice == 'y') {
cout << "**************************************************************************************" <<endl ;
cout << "Enter the time the call starts in 24-hour rotation:\n";
cin >> time;
if (!validatevalidateUserInputTime(time)) {
cout << "Invalid time input\n";
cout << "Please try again\n\n";
continue;
}
cout << "Enter the first two letters of the day of the week:\n";
cin >> a >> b;
if (!validateUserInputDay(a,b)) {
cout << "Invalid day input\n";
cout << "Please try again\n\n";
continue;
}
cout << "Enter the length of the call in minutes:\n";
cin >> minute;
if (!validateUserInputCallLength(minute)) {
cout << "Invalid minute input\n";
cout << "Please try again\n\n";
continue;
}
cout << "Cost of the call: $" << calculateTotalCost(time, a, b, minute) << endl;
cout << "Do you want to repeat the program ? (y/n)" << endl;
cin >> choice;
}
return 0;
}
bool validatevalidateUserInputTime(string time) {
//NOTE
//inorder to use string correctly, there is a new data type size_t already defined for string class
//don't bother much about it
//it is an unsigned int type which is specially defined for storing size
size_t pos;
//find is a prdefined function for string class and below it will return position of : in time string
//i will then sepearte time and minute to check it's validity
pos = time.find(':');
if (pos != string::npos) {
string hour, minute;
hour = time.substr(0, pos); //sepearting hour
minute = time.substr(++pos); //separating minute
//NOTE: we are using string stream class technique to convert string into integer so that we can compare it range
stringstream ss(hour);
int int_hour, int_minute;
ss >> int_hour; //converted to integer you can use your own technique
ss.str("");
ss.clear();
ss << minute;
ss >> int_minute;
if ((int_hour >= 0 && int_hour <= 24) && (int_minute >= 0 && int_minute <= 60)) //comparing range of entered time
return true;
else
return false;
}
else
return false;
}
bool validateUserInputDay(char a, char b) {
string str;
str.push_back(a);
str.push_back(b);
//trying all possible formate of date
if (str == "mo" || str == "Mo" || str == "mO" || str == "MO" ||
str == "tu" || str == "Tu" || str == "tU" || str == "TU" ||
str == "we" || str == "We" || str == "wE" || str == "WE" ||
str == "th" || str == "Th" || str == "tH" || str == "TH" ||
str == "fr" || str == "Fr" || str == "fR" || str == "FR" ||
str == "sa" || str == "Sa" || str == "sA" || str == "SA" ||
str == "su" || str == "Su" || str == "sU" || str == "SU" ) {
return true;
}
else {
return false;
}
}
bool validateUserInputCallLength(int minute) {
//here i considered 0 also if u dont want then write code in if as minute > 0
if (minute >= 0)
return true;
else
return false;
}
float calculateTotalCost(string time, char a, char b, int minute) {
//this part of code is for extracting hour and minute same as above
size_t pos;
pos = time.find(':');
string hr, mn;
hr = time.substr(0, pos);
mn = time.substr(++pos);
stringstream ss(hr);
int int_hour, int_minute;
ss >> int_hour;
ss.str("");
ss.clear();
ss << minute;
ss >> int_minute;
//knowing the entered day
string day;
day.push_back(a);
day.push_back(b);
float cost = 0;
if (day == "sa" || day == "sA" || day == "Sa" || day == "SA" ||
day == "su" || day == "sU" || day == "Su" || day == "SU" ) {
cost = minute * .15;
return cost;
}
else {
if (int_hour >= 8 && int_hour < 18) {
cost = minute * .40;
return cost;
}
else {
cost = minute * .25;
return cost;
}
}
}
//if you are unable to understand any part of code then please comment
//I will respond as soon as i can
//thanks
//sample output

a C++ program that computes the cost of a long-distance call. The cost of the call...
C++ PROGRAM Write a program that converts from 24-hour notation to 12-hour notation. For example, it should convert 14:25 to 2:25 PM. The input is given as two integers. There should be at least three functions, one for input, one to do the conversion, and two for output (one for 12-hour time and another for 24-hour time). Record the AM/PM information as a value of type char, ‘A’ for AM and ‘P’ for PM. Thus, the function for doing the...
In C++ Write a program that will calculate the cost of a phone call as follows: The first 10 minutes are charged at a flat rate of $0.99 for the entire 10 minutes (Not 99 cents a minute - but 99 cents for the first 10 minutes total). Every minute after the initial 10 minutes will be charged at $0.10 per minute. Input the number of minutes talked as an integer. Using an IF/ELSE structure, check for an entry of...
Write a program in C An international airport offers long term parking at the following rates: First 60 minutes is free; 61-80 minutes $4; Each additional 20 minutes $2; And $18 max. per day (24 hours). Write a program longterm_parking.c that calculates and prints the charges for parking at the long term parking garage. 1. The user enters the number of total hours and minutes; the program prints the charge. 2. If the input is invalid, print a message and...
PLEASE WRITE CODE FOR C++ ! Time Validation, Leap Year and Money Growth PartA: Validate Day and Time Write a program that reads a values for hour and minute from the input test file timeData.txt . The data read for valid hour and valid minute entries. Assume you are working with a 24 hour time format. Your program should use functions called validateHour and validateMinutes. Below is a sample of the format to use for your output file timeValidation.txt : ...
Distance Walked Write a program to calculate how many mile, feet, and inches a person walks a day, given the stride length in inches (the stride length is measured from heel to heel and determines how far walk with each step], the number of steps per minute, and the minutes that person walks a day. Note that 1 mile is 5280 feet and 1 feet is 12 inches. In your program, there should be the follo constants: final Int FEET_PER_MILE...
Time Displacement (12-hour format) Write a program that requests the current time and a waiting time as two integers for the number of hours and the number of minutes to wait. The program then outputs what the time will be after the waiting period. Use 24-hour notation for the input time and 12-hour notation for the output time. Include a loop that lets the user repeat this calculation for additional input values until the user says she or he wants...
Write a C# program that prints a calendar for a given year. Call this program calendar. This program needs to use Switch Case in order to call the methods and format to print each month. The program prompts the user for two inputs: 1) The year for which you are generating the calendar. 2) The day of the week that January first is on, you will use the following notation to set the day of the week: ...
Write a program that reads a string from the keyboard and tests whether it contains a valid time. Display the time as described below if it is valid, otherwise display a message as described below. The input date should have the format hh:mm:ss (where hh = hour, mm = minutes and ss = seconds in a 24 hour clock, for example 23:47:55). Here are the input errors (exceptions) that your program should detect and deal with: Receive the input from...
Write a C# program that prints a calendar for a given year. Call this program calendar. The program prompts the user for two inputs: 1) The year for which you are generating the calendar. 2) The day of the week that January first is on, you will use the following notation to set the day of the week: 0 Sunday 1 Monday 2 Tuesday 3 Wednesday 4 Thursday 5 Friday 6 Saturday Your program should...
POD 3: Tick Tock Instructions There are 24 hours in a day, but we all think about them differently. Some people and places in the world work with a 24-hour clock that goes from 0:00 to 23:59, while others work with a 12-hour clock that goes from 12.00AM to 11:59PM 24-hour clock 0.00 (midnight) 1200 (noon) 23:59 (one minute before midnight), A COLLAPSE 12-hour clock: *12.00 AM" (midnight) *12:00 PM" (noon) "11:59 PM" (one minute before midnight), You are going...