/** * Assignment #3, Program 1 * Program to calculate cost of a phone call * Author: Mark Allen Weiss * SSN: 000-00-0000 * Course: COP-2210 Section 8 * Date: October 7, 1998 * * CERTIFICATION OF SOLE AUTHORSHIP * I certify that this work is solely my own and * that none if it is the work of any other person. * I further certify that I have not provided any * assistance to other students enrolled in COP-2210 that * would render their CERTIFICATION OF SOLE AUTHORSHIP * invalid. I understand that violations of this pledge * may result in severe sanctions. * * * * ----------------------------------- * (Mark Allen Weiss) <--- Put your name here, and sign above */ #include #include "money.h" #include "apstring.h" // Program constants const money REGULAR_RATE = 0.40; const double NIGHT_DISCOUNT = 0.50; const double LONG_DISCOUNT = 0.15; const int MINUTES_IN_SHORT_CALL = 60; const int NIGHT_START = 1800; const int DAY_START = 800; // Watch out: 0800 is wrong! const double TAX_RATE = 0.04; // Function declarations void display_instructions( ); int get_input( apstring message ); bool is_night_call( int starting_time ); money compute_gross_cost( int starting_time, int call_length ); money compute_discounts( money gross_cost, int starting_time, int call_length ); void print_answers( money gross_cost, money net_cost ); int main( ) { // Inputs int starting_time; int call_length; // Outputs money gross_cost; money net_cost; // Read values display_instructions( ); starting_time = get_input( "Enter starting time in 24 hour format" ); call_length = get_input( "Enter the length of the call in minutes" ); // Compute answers gross_cost = compute_gross_cost( starting_time, call_length ); net_cost = compute_discounts( gross_cost, starting_time, call_length ); // Print the answers print_answers( gross_cost, net_cost ); return 0; } /** * Print instructions. */ void display_instructions( ) { cout << "This program will compute the cost of a phone call"; cout << ", given two parameters:" << endl; cout << "\t1. The starting time" << endl; cout << "\t2. The call length" << endl; cout << "The starting time is in 24-hour format (i.e. 1800 is 6PM)." << endl << endl; } /** * Print answers. */ void print_answers( money gross_cost, money net_cost ) { cout << endl; cout << "The cost before discounts is " << gross_cost << endl; cout << "The cost after discounts is " << net_cost << endl; } /** * Read an input; message is used to give a prompt. */ int get_input( apstring message ) { int value_read; cout << message << ": "; cin >> value_read; return value_read; } /** * Compute cost of phone call before discounts. */ money compute_gross_cost( int starting_time, int call_length ) { return REGULAR_RATE * call_length; } /** * Compute cost of phone call after discounts. */ money compute_discounts( money gross_cost, int starting_time, int call_length ) { money net_cost = gross_cost; if( is_night_call( starting_time ) ) net_cost -= NIGHT_DISCOUNT * net_cost; if( call_length > MINUTES_IN_SHORT_CALL ) net_cost -= LONG_DISCOUNT * net_cost; net_cost += TAX_RATE * net_cost; return net_cost; } /** * Returns true if and only if starting_time is a night call. */ bool is_night_call( int starting_time ) { return starting_time >= NIGHT_START || starting_time < DAY_START; }