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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
/*************
Program: Asg_12.cpp
Author: Alan P. Matie
Date: 27 Apr 2009
Description:
A program to compute the cost of a newly purchase vehicle. Input will be:
customer name, and the make, model, cost, and the year of the vehicle.
$1200 rebate for SUV's, 2002 and newer Ford get $500 rebate, all other
Fords get $100 rebate. Sales tax is 6%.
Customer will receive a printed receipt with their name, all vehicle
and cost data, any rebate and the total cost of the vehicle.
User may enter as many purchases as needed.
New Concepts:
Void function
Challenges:
Must use one return value function for the rebate calculation,
and one void function for the output.
Last Modified: 28 Apr 2009
**************/
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;
// Declare constants
const double TAXRATE = 0.06;
const double SUV_REBATE = 1200;
const double FORD_REBATE = 100;
const double YEAR_FORD_REBATE = 500;
// Function Prototypes
double CalcRebate(double fRebate, double sRebate, double yRebate);
double CalcStotal(double vCost, double vRebate);
double CalcTax(double subtotal, double TAXRATE);
double CalcTtlCost(double vCost, double vRebate, double sales_tax);
void PrintCustName(string custName);
void PrintVehPurch(int vYear, string vMake, string vModel);
void PrintVehCost(double vCost);
void PrintRebate(double vRebate);
void PrintTax(double sales_tax);
void PrintTotal(double totalCost);
int main()
{
// Declare variables below here
string custName, vMake, vModel, ford, suv, Ford, SUV;
double vCost, vRebate = 0, sales_tax, totalCost, subtotal;
double fRebate = 0, sRebate = 0, yRebate = 0;
char ans;
int vYear;
// Initialization Section for real number output. DO NOT MOVE!
cout <<setiosflags(ios::fixed | ios::showpoint);
cout <<setprecision(2);
// Begin your "main processing" below here
cout <<"Welcome to your new vehicle purchasing program!"<<endl<<endl;
do
{
cout << "Please enter the customers name ==> ";
cin >> custName;
cout << "Please enter the make of the vehicle purchased (ie. ford, chevy)==> ";
cin >> vMake;
cout << "Please enter the model of the vehicle (ie. sedan, suv)==> ";
cin >> vModel;
cout << "Please enter the model year of the vehicle ==> ";
cin >> vYear;
cout << "Please enter the cost of the vehicle ==> $";
cin >> vCost;
cout <<" "<<endl<<endl;
cout << " * * * * Customer Receipt * * * * "<<endl<<endl;
if ((vMake == ford) || (vMake == Ford))
{
fRebate = FORD_REBATE;
}
else
{
fRebate = 0;
}
if ((vModel == suv) || (vModel == SUV))
{
sRebate = SUV_REBATE;
}
else
{
sRebate = 0;
}
if (((vYear >= 2002) && (vMake == ford)) || ((vYear >= 2002) && (vMake == Ford)))
{
yRebate = YEAR_FORD_REBATE;
}
else
{
yRebate = 0;
}
vRebate = CalcRebate(fRebate, sRebate, yRebate);
subtotal = CalcStotal(vCost, vRebate);
sales_tax = CalcTax(subtotal, TAXRATE);
totalCost = CalcTtlCost(vCost, vRebate, sales_tax);
PrintCustName(custName);
PrintVehPurch(vYear, vMake, vModel);
PrintVehCost(vCost);
PrintRebate(vRebate);
PrintTax(sales_tax);
PrintTotal(totalCost);
cout <<" " <<endl;
cout << "Do you wish to continue? Y or N ";
cin >> ans;
cout << " "<<endl<<endl;
}while ((ans == 'Y') || (ans == 'y'));
return 0;
}
// function definitions below here
double CalcRebate(double fRebate, double sRebate, double yRebate)
{
return fRebate + sRebate + yRebate;
}
double CalcStotal(double vCost, double vRebate)
{
return vCost - vRebate;
}
double CalcTax(double subtotal, double TAXRATE)
{
return subtotal * TAXRATE;
}
double CalcTtlCost(double vCost, double vRebate, double sales_tax)
{
return vCost - vRebate + sales_tax;
}
void PrintCustName(string custName)
{
cout << "Customer Name: "<<custName<<endl;
}
void PrintVehPurch(int vYear, string vMake, string vModel)
{
cout << "Vehicle Purchased: "<<vYear << " "<<vMake << " "<< vModel<<endl;
}
void PrintVehCost(double vCost)
{
cout << "Vehicle Cost: $" <<vCost <<endl;
}
void PrintRebate(double vRebate)
{
cout << "Rebate: $"<<vRebate <<endl;
}
void PrintTax(double sales_tax)
{
cout << "Sales Tax: $"<<sales_tax <<endl;
}
void PrintTotal(double totalCost)
{
cout << "Total Cost: $"<<totalCost <<endl;
}
| |