/** * Assignment #2, Program 3 * Program to calculate housing costs * Author: Mark Allen Weiss * SSN: 000-00-0000 * Course: COP-2210 Section 8 * Date: September 28, 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 int YEARS = 5; // Function declarations void display_instructions( ); double get_input( apstring message, int house_num ); money compute_house_cost( money initial_cost, money annual_fuel_cost, double tax_rate ); void print_heading( ); void print_cost( money initial_cost, money annual_fuel_cost, double tax_rate, money total_cost ); int main( ) { // Inputs money initial_cost1, initial_cost2, initial_cost3; money annual_fuel_cost1, annual_fuel_cost2, annual_fuel_cost3; double tax_rate1, tax_rate2, tax_rate3; // Outputs money total_cost1, total_cost2, total_cost3; // Read values display_instructions( ); initial_cost1 = get_input( "initial house cost", 1 ); annual_fuel_cost1 = get_input( "annual fuel cost", 1 ); tax_rate1 = get_input( "tax rate (1% is represented as .01)", 1 ); initial_cost2 = get_input( "initial house cost", 2 ); annual_fuel_cost2 = get_input( "annual fuel cost", 2 ); tax_rate2 = get_input( "tax rate (1% is represented as .01)", 2 ); initial_cost3 = get_input( "initial house cost", 3 ); annual_fuel_cost3 = get_input( "annual fuel cost", 3 ); tax_rate3 = get_input( "tax rate (1% is represented as .01)", 3 ); // Compute answers total_cost1 = compute_house_cost( initial_cost1, annual_fuel_cost1, tax_rate1 ); total_cost2 = compute_house_cost( initial_cost2, annual_fuel_cost2, tax_rate2 ); total_cost3 = compute_house_cost( initial_cost3, annual_fuel_cost3, tax_rate3 ); // Print the answers print_heading( ); print_cost( initial_cost1, annual_fuel_cost1, tax_rate1, total_cost1 ); print_cost( initial_cost2, annual_fuel_cost2, tax_rate2, total_cost2 ); print_cost( initial_cost3, annual_fuel_cost3, tax_rate3, total_cost3 ); return 0; } /** * Print instructions. */ void display_instructions( ) { cout << "This program will compute the total house cost for three houses." << endl; cout << "Each house cost consists of three parameters:" << endl; cout << "\t1. An initial house cost" << endl; cout << "\t2. Annual fuel cost" << endl; cout << "\t3. The tax rate." << endl; cout << "The cost is computed over " << YEARS << " years." << endl << endl; } /** * Print answers. */ void print_cost( money initial_cost, money annual_fuel_cost, double tax_rate, money total_cost ) { cout << initial_cost << " \t\t" << annual_fuel_cost << " \t\t" << tax_rate << " \t\t" << total_cost << endl; } /** * Read an input; message is used to give a prompt. */ double get_input( apstring message, int house_num ) { double value_read; cout << "Please enter " << message << " for house " << house_num << ": "; cin >> value_read; return value_read; } /** * Compute the total housing cost. */ money compute_house_cost( money initial_cost, money annual_fuel_cost, double tax_rate ) { return annual_fuel_cost * YEARS + initial_cost + initial_cost * tax_rate * YEARS; } /** * Print a heading for the table. */ void print_heading( ) { cout << "Initial house cost" << "\t" << "Annual fuel cost" << "\t" << "Tax rate" << "\t" << "Total cost" << endl; }