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
|
/*
* Author: Jeanine Haenel
* Class: CS362
* Assignment: Week 1, Program 1
* Program Description: Program reads data from REGISTER.txt.
* Input: REGISTER.txt
* Processing:
* Output: HOUSEHOLDS.txt, VEHICLES.txt
*/
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
//CONSTANTS
const string FILENAME = "REGISTER.txt";
const int CURRENT_YEAR = 2013;
const float AUTO_ROAD_FEE = 24.00;
const float CYCLE_ROAD_FEE = 12.00;
const int FULL = 20; //line counter, when reaches 20, redisplays header
const float LICENSE_PERCENT = .0025; //percentage of msrp for license fee
const float AGE_RANGE1 = 5; //age range 1 for car or motorcycle
const float RANGE1_PERCENT_MSRP_AUTO = .03; //percentage of msrp for car
const float RANGE1_PERCENT_AGE_AUTO = .0015; //percentage of msrp for car per age
const float RANGE1_PERCENT_MSRP_CYCLE = .025; //percentage of msrp for motorcycle
const float RANGE1_PERCENT_AGE_CYCLE = .0009; //percentage of msrp for motorcycle per age
const float AGE_RANGE2_MIN = 6; //minimum for age range 2, car or motorcycle
const float AGE_RANGE2_MAX = 10; //max for age range 2, car or motorcycle
const float RANGE2_PERCENT_MSRP_AUTO = .0275; //percentage of msrp for car
const float RANGE2_PERCENT_AGE_AUTO = .0012; //percentage of msrp for car per age
const float RANGE2_PERCENT_MSRP_CYCLE = .0225; //percentage of msrp for motorcycle
const float RANGE2_PERCENT_AGE_CYCLE = .0009; //percentage of msrp for motorcycle per age
const float AGE_RANGE3_MIN = 11; //minimum for age range 3, car or motorcycle
const float AGE_RANGE3_MAX = 15; //max for age range 3, car or motorcycle
const float RANGE3_PERCENT_MSRP_AUTO = .025; //percentage of msrp for car
const float RANGE3_PERCENT_AGE_AUTO = .0009; //percentage of msrp for car per age
const float RANGE3_PERCENT_MSRP_CYCLE = .02; //percentage of msrp for motorcycle
const float RANGE3_PERCENT_AGE_CYCLE = .0009; //percentage of msrp for motorcycle per age
const float AGE_RANGE4 = 15; //age range 4 for car or motorcycle
const float AGE_RANGE4_TAX_AUTO = 20.00; //flat rate for age range 4 for car
const float AGE_RANGE4_TAX_CYCLE = 10.00; //flat rate for age range 4 for motorcycle
//FUNCTION PROTOTYPES
void getRoadFee(char type, float& roadFee);
void getTax(char type, float msrp, int age, float& tax);
int main()
{
int houseid = 0, year = 0, full = 0, age = 0, lineNum = 0;
float msrp = 0, roadFee = 0, licenseFee = 0, tax = 0, total = 0;
char type, ch;
string plate;
int noOfVehicles;
ifstream inRegister; //ifstream
inRegister.open (FILENAME.c_str()); //open file
if(!inRegister) //if not open
cout << "Error opening input file " << FILENAME << endl;
else
inRegister >> houseid; //prime read
do
{
inRegister >> type >> plate >> year >> msrp;
cout << houseid << " " << type << " " << plate << " " << year << " " << msrp << endl;
age = CURRENT_YEAR - year;
licenseFee = msrp * LICENSE_PERCENT;
getTax(type, msrp, age, tax);
getRoadFee(type, roadFee);
total = roadFee + licenseFee + tax;
inRegister >> houseid;
}while(inRegister && ch != '\n'); //while open
inRegister.close();
//display
//customer << fixed << showpoint << setprecision(2);
//customer << left << setw(14) << custCode << setw(3) << " $ " << totalUtilityCharge << endl;
//if(lineNum = FULL) //REDISPLAY HEADER
//{
// system("pause");
// system("CLS");
//function to output to screen;
// lineNum = 0; //reset to 0
//}
system("pause");
return 0;
}
void getRoadFee(char type, float& roadFee)
{
switch (type)
{
case 'A':
roadFee = AUTO_ROAD_FEE;
break;
case 'M':
roadFee = CYCLE_ROAD_FEE;
break;
}
}
void getTax(char type, float msrp, int age, float& tax)
{
if(type == 'A' && age <= AGE_RANGE1)
tax = (RANGE1_PERCENT_MSRP_AUTO * msrp) - ((RANGE1_PERCENT_AGE_AUTO * msrp) * age);
if(type == 'A' && age >= AGE_RANGE2_MIN || age <= AGE_RANGE2_MAX)
tax = (RANGE2_PERCENT_MSRP_AUTO * msrp) - ((RANGE2_PERCENT_AGE_AUTO * msrp) * age);
if(type == 'A' && age >= AGE_RANGE3_MIN || age <= AGE_RANGE3_MAX)
tax = (RANGE3_PERCENT_MSRP_AUTO * msrp) - ((RANGE3_PERCENT_AGE_AUTO * msrp) * age);
if(type == 'A' && age > AGE_RANGE4)
tax = AGE_RANGE4_TAX_AUTO;
if(type == 'M' && age <= AGE_RANGE1)
tax = (RANGE1_PERCENT_MSRP_CYCLE * msrp) - ((RANGE1_PERCENT_AGE_CYCLE * msrp) * age);
if(type == 'M' && age >= AGE_RANGE2_MIN || age <= AGE_RANGE2_MAX)
tax = (RANGE2_PERCENT_MSRP_CYCLE * msrp) - ((RANGE2_PERCENT_AGE_CYCLE * msrp) * age);
if(type == 'M' && age >= AGE_RANGE3_MIN || age <= AGE_RANGE3_MAX)
tax = (RANGE3_PERCENT_MSRP_CYCLE * msrp) - ((RANGE3_PERCENT_AGE_CYCLE * msrp) * age);
if(type == 'M' && age > AGE_RANGE4)
tax = AGE_RANGE4_TAX_CYCLE;
}
|