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
|
#include<iostream>
#include <fstream>
#include<string>
#include <sstream>
#include <cmath>
#define CURRENTYEAR 2021
#define HIGHWAYTAX 2
using namespace std;
int getYearDifference(int currentyear,int year){
return currentyear-year;
}
int getreductionpercentage(int currentyear,int year){
return 10*(currentyear-year);
}
int getbasefees(string type){
if(type == "TRUCK"){
return 500;
}
else if(type == "CAR" || type == "SUV"){
return 100;
}
else
return 200;
}
int main(){
ifstream inFile("VehicleInput.txt");
ofstream outFile("VehicleOutput.txt");
outFile<<"Type of Vehicle, Base Fee, New base fee with surcharge, Percent reduction, Base fees after reduction, Tax, Highway fee, Total Base fee\n";
string str;
while (getline(inFile, str))
{
stringstream check1(str);
string token;
string lineargs[6];
int index=0;
int basefees;
int surcharge;
while(getline(check1, token, ' '))
{
cout<<token<<" ";
lineargs[index]=token;
index++;
}
cout<<" "<<endl;
outFile<<lineargs[0]<<",";
basefees=getbasefees(lineargs[0]);
outFile<< "Base fee: " << basefees<<",";
cout<<"Base fee: "<<basefees<<endl;
if(basefees==500){
stringstream con(lineargs[5]);
int weight = 0;
con >> weight;
if(weight>1200){
surcharge = (500*22)/100 + basefees;
outFile << surcharge;
cout << "Base fee after surcharge: " << surcharge << endl;
}
else
cout << "NO Surcharge" << endl;
}
stringstream con(lineargs[3]);
int year = 0;
con >> year;
if(getYearDifference(CURRENTYEAR,year) >= 7){
int reducedFees= 70;
outFile<<"Percent reduction: " << reducedFees<<",";
cout<<"Percent reduction: "<<reducedFees << "% "<<endl;
basefees=(basefees*(100-reducedFees))/100;
outFile<<basefees<<",";
cout<<"Reduced base fee: "<<basefees<<endl;
}
else if(getYearDifference(CURRENTYEAR,year)>=1){
int reducedFees=getreductionpercentage(CURRENTYEAR,year);
outFile<<"Percent reduction:" << reducedFees<< ",";
cout<<"Percent reduction: "<<reducedFees<<"% "<<(CURRENTYEAR-year)<<endl;
basefees=(basefees*(100-reducedFees))/100;
outFile<<"Reduced base fee" << basefees<<",";
cout<<"Reduced base fee: "<<basefees<<endl;
}
else{
outFile<<"NA, NA,";
cout<<"NO reduction"<<endl;
}
float tax=(basefees*6.5)/100;
cout<<"Tax: "<<tax<<endl;
cout<<"Highway Tax: "<<HIGHWAYTAX<<endl;
basefees=basefees+tax+HIGHWAYTAX;
outFile<<"Tax: "<<tax<<",";
outFile<<"Highway Tax: " <<HIGHWAYTAX<<",";
outFile<<"Total base fee: "<<basefees<<",\n";
cout<<"Total base fee: "<<basefees<<endl;
cout<<"--------------------------------------------------"<<endl;
}
outFile.close();
}
|