Hi all! So, the other day I posted asking for help on writing a program to meet the following criteria:
Problem: Write an application in C++ that calculates the vehicle registration fee.
Input: The program should read the required inputs from a file to calculate the fee. You can use the attached file as your input (VehicleInput.txt). Allow the program to read multiple inputs from the file using while loop and eof() function.
Output: A breakdown of the registration fee and the total registration fee for each vehicle. Output should be properly formatted. Allow the program to save the output for all vehicles in a single text file.
Rules for fee calculation:
All vehicles will have a VIN number, make, model, and year. Trucks will also have weight as the input.
All new cars and SUVs will have a base fee of $100.00, buses will have a base fee of $200.00, and trucks will have a base fee of $500.00.
Trucks above 12,000 LBS will have a surcharge of 22% added to the base fee. This will make up the new base fee for the trucks above 12,000 LBS.
Depending upon the age of the vehicle, base fee will be reduced by 10% for each year up to a maximum of 7 years. For example if the year of the vehicle is 2015, then base fee will reduce by 50% (2020 – 2015 = 5 Years and 10% for every year).
There is a 6.5% tax added to the base fee.
There is $2.00 additional highway fund that is added to the fee.
Submission (One MS Word document containing the following deliverables):
Algorithms
An algorithm for every function.
Constants
All constants defined for this application.
Source Code
Implement above application in C++ and include your source code under this section.
Input File Contents
Copy the contents of your input file under this section. Your input file should contain at least 5 vehicles. See VehicleInput.txt file.
Output File Contents
Copy the contents of your output file under this section
* Please be sure to follow good coding practices (modular code with pre-defined and user defined functions, comments, indentations, readable code)
I took a lot of the suggestions that were made and looked back at previous codes that I have written as well. Here is the code that I have come up with now:
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
|
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int basefee(bool type[], double fee);
int year{}, weight{};
string vin, brand, model, type;
double fee{};
int main()
{
ifstream inFile;
inFile.open("VehicleInput.txt");
while (!inFile.eof())
{
inFile >> vin >> brand >> model >> year >> type >> weight;
string type[4] = {"car","suv","bus","truck"};
void basefee();
double yeardisc = 2020 - year;
if (int year <= 2020)
fee = basefee() - (.1 * (yeardisc));
else if (yeardisc <= 7)
fee = basefee() - (.1 * (yeardisc));
else fee = basefee();
}
ofstream outFile;
outFile.open("VehicleRegFee.txt");
}
//calculates basefee based on type
int basefee(bool type[], double fee)
{
if (type[0] = "car")
fee = 100;
else if (type[1] = "suv")
fee = 100;
else if (type[2] = "bus")
fee = 200;
else if (type[3] = "truck")
fee = 500;
else fee = 0;
}
|
Any pointers on what needs improvement?