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
|
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <cmath>
#define CURRENTYEAR 2021
#define HIGHWAYTAX 2
using namespace std;
int getYearDifference(int cuyear,int year){
return cuyear-year;
}
int getreductionpercentage(int cuyear,int year){
return 10*(cuyear-year);
}
int getbasefees(string type){
if(type=="Truck"){
return 500;
}
else if(type=="CAR" || type=="SUV"){
return 100;
}
else
return 200;
}
int main(){
ifstream file("VehicleInput.txt");
ofstream outfile("OutputFile.numbers");
outfile<<"Types of Vehicle,Base Fees,New Base fees IF any surcharge,fees reduction in %, Base fees after reduction,TAX,HIghway Charges,Total Base fees\n";
string str;
while (getline(file, str))
{
stringstream check1(str);
string token;
string lineargs[6];
int index=0;
int basefees;
while(getline(check1, token, ' '))
{
cout<<token<<" ";
lineargs[index]=token;
index++;
}
cout<<"\n";
outfile<<lineargs[0]+",";
basefees=getbasefees(lineargs[0]);
outfile<<basefees<<",";
cout<<"Base charge is "<<basefees<<endl;
if(basefees==500){
stringstream con(lineargs[5]);
int weight = 0;
con >> weight;
if(weight>1200){
basefees=(basefees*22)/100+basefees;
outfile<<basefees<<",";
cout<<"New base fees is after adding 22% surcharge ::"<<basefees<<endl;
}
else
outfile<<"NO Change,";
}
else
outfile<<"NO Surcharge,";
stringstream con(lineargs[4]);
int year = 0;
con >> year;
if(getYearDifference(CURRENTYEAR,year)>=7){
int feesred=70;
outfile<<feesred<<",";
cout<<"Base fees reduction in % is "<<feesred<<" because of age "<<(CURRENTYEAR-year)<<endl;
basefees=(basefees*(100-feesred))/100;
outfile<<basefees<<",";
cout<<"After Reduction new base fees is "<<basefees<<endl;
}
else if(getYearDifference(CURRENTYEAR,year)>=1){
int feesred=getreductionpercentage(CURRENTYEAR,year);
outfile<<feesred<<",";
cout<<"Base fees reduction in % is "<<feesred<<" because of age "<<(CURRENTYEAR-year)<<endl;
basefees=(basefees*(100-feesred))/100;
outfile<<basefees<<",";
cout<<"After Reduction new base fees is "<<basefees<<endl;
}
else{
outfile<<"NA,NA,";
cout<<"NO Base fees reduction because of age 0"<<endl;
}
int tax=(basefees*6.5)/100;
cout<<"Tax Added to base fees is "<<tax<<endl;
cout<<"Highway Tax is "<<HIGHWAYTAX<<endl;
basefees=basefees+tax+HIGHWAYTAX;
outfile<<tax<<",";
outfile<<HIGHWAYTAX<<",";
outfile<<basefees<<",\n";
cout<<"Final BASE Fees after adding TAX and Highway charges is "<<basefees<<endl;
cout<<"************************"<<endl;
}
outfile.close();
}
|