Problem: Write a 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 7:00 A.M. and 9:00 P.M., Monday through Friday, is billed at a rate of $0.30 per minute.
b. Any call started before 7:00 A.M. or after 9:00 P.M., Monday through Friday, is billed at a rate of $0.15 per minute.
c. Any call started on a Saturday or Sunday is billed at a rate of $0.10 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. Input will come from the input file “Project_3_input.txt” and go to “Project_3_output.txt”, which you will create.
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
The time is to be input in military-time notation, hours followed by minutes, so the time 1:30 P.M. is input as: 13 30
Be sure to allow for both uppercase and lowercase letters or a combination of the two. You MUST accept both letters, and check both letters for validity. (Think: otherwise the program would accept “Sq” if you are only checking for weekend days by looking for “S”). If an incorrect day of the week is entered, skip the part of the code that will read in start time and call length.
The number of minutes will be input as a value of type int. (You can assume that the call time is rounded up to a whole number of minutes.) Your program should include a loop that accepts call data until the end of the file is reached.
***********************************************************************
Input:
Mo 17 30 15
Sa 9 00 30
Tu 3 30 45
Sq
Fr 2101 60
**********************************************************************
This is what i have so far. can't seem to get it right using visual studio
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
const double daytime = 0.3;
const double night = 0.15;
const double weekend = 0.1;
int main ()
{
ifstream infile;
ofstream outfile;
infile.open("Project_3_input.txt");
outfile.open("Project_3_output.txt");
char day[3];
int num_day;
int time;
int length;
double cost;
infile >> day >> time >> length;
if((day=="Mo")||(day=="mo"))
{num_day = 1;}
else if((day=="Tu")||(day=="tu"))
{num_day = 2;}
else if((day=="We")||(day=="we"))
{num_day = 3;}
else if((day=="Th")||(day=="th"))
{num_day = 4;}
else if((day=="Fr")||(day=="fr"))
{num_day = 5;}
else if((day=="Sa")||(day=="sa"))
{num_day = 6;}
else if((day=="Su")||(day=="su"))
{num_day = 7;}
else if (infile.fail())
{cout<<"Error opening file" <<endl;}
else
{infile.ignore();}
if(((time>700)&&(time<2100))&&(num_day<=5))
{cost = length*daytime;}
else if((time<=700)||(time>=2100)&&(num_day<=5))
{cost = length*night;}
else cost = length*weekend;
cout<< cost;
infile.close();
outfile.close();
return 0;
}
|