Rewriting the DMV system

I'm Trying to write a program that can calculate registration fees using text files and to print it all on a text file. Here are the directions,
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.txtPreview the document). 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 2013, then base fee will reduce by 50% (2018 – 2013 = 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.
Here's the program I got so far:
#include <iostream>
#include <string>
#include <fstream>
#include <cmath>
#include <sstream>
using namespace std;
int main()
{ // Declare file stream variables
ifstream inData;
ofstream outData;
// Declare variables that will store the information that is read from the file
string VIN, carMaker, carModel, carType, carYear;
string truck = "TRUCK";
string line;
int carWeight;
double basefee;
double tax = 0.065;
double highwayfee = 2.0;
int carAge;
double discount;

// Associate input and output file strings with actual files
inData.open("VehicleInput.txt");
outData.open("VehicleOutput.txt");

//read the file
while (getline(inData, line))
{





//Process the information
istringstream extractor(line);
extractor >> VIN;
extractor >> carMaker;
extractor >> carModel;
extractor >> carType;
extractor >> carYear;
extractor >> carWeight;
carWeight = 0;
carAge = 2018 - carYear;
discount = carAge * 0.1;

if (carAge >= 7)
{
discount = 0.7;
}

if ((carType == "CAR") || (carType == "SUV"))
{
basefee = (((100.0 * tax) - (100 * discount)) + 100);
}
if (carType == "BUS")
{
basefee = (((200.0 * tax) - (100 * discount)) + 200.0);
}
if (carType == "TRUCK")
{
basefee = (((500.0 * (0.22 + tax)) - (500 * discount)) + 500.0);
}


// Write information to the file
outData << " " << VIN << " " << carMaker << " " << carModel << " " << carYear; // << carWeight << endl;
if (carWeight > 0) outData << carWeight;
outData << "$ " << basefee << endl;

// VIN carMaker Model year { weight } cost
}






inData.close();
outData.close();




return 0;
}
what's happening is that every time I compile the program does not recognize the " - " sign and says that its a global operator and when I run the program it copies all the lines in the input.txt file twice and does this in the output.txt file:
AB54H77HG553DHJ8J8 TOYOTA CAMRY CAR
AB54H77HG553DHJ8J8 TOYOTA CAMRY CAR 2.3342e-313in US dollars
C745D4S78SSSWERDDF NISSAN PATHFINDER SUV
C745D4S78SSSWERDDF NISSAN PATHFINDER SUV 2.3342e-313in US dollars
WAGGT345ADFGGGS234 ATLANTIC EXPRESS BUS
WAGGT345ADFGGGS234 ATLANTIC EXPRESS BUS 2.3342e-313in US dollars
LKU338NGTH0988J77H KENWORTH T800 TRUCK20000
LKU338NGTH0988J77H KENWORTH T800 TRUCK20000 2.3342e-313in US dollars
TNNH75RDG88J0R6669 FORD FOCUS CAR
TNNH75RDG88J0R6669 FORD FOCUS CAR 2.3342e-313in US dollars
The subtraction sign it does not like is in this equation: carAge = 2018 - carYear. What am I missing? Any and all help is appreciated!
Last edited on
> Problem: Write an application in C++ that calculates the vehicle registration fee.
How much C++?

Your approach so far?

With classes?
1
2
3
class vehicle {
    // member vars and functions
};


With inheritance?
1
2
3
4
5
6
7
8
9
10
11
12
13
class vehicle {
    // member vars and functions common to all
    // some functions virtual or pure virtual
};
class car : public vehicle {
    // specialisations unique to car
};
class bus : public vehicle {
    // specialisations unique to bus
};
class truck : public vehicle {
    // specialisations unique to truck
};


> When I put it through the program the outData loops infinitely.
> I am also having a hard time with factoring in car weight.
Only trucks have a weight, so you need some care when reading the file.

Here's an example.
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
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <cmath>
using namespace std;
int main()
{
    ifstream inData;
    string VehicleIdentificationNumber;
    string carMaker;
    string carModel;
    string carType;
    string carYear;
    int carWeight;

    // Associate inut and output file strams with actual files
    inData.open("foo.txt");
    string inputline;

    while ( getline(inData,inputline) ) {
        cout << "Read:" << inputline << endl;
        istringstream is(inputline);
        is >> VehicleIdentificationNumber;
        is >> carMaker;
        is >> carModel;
        is >> carYear;
        is >> carType;
        if ( carType == "TRUCK" ) {
            is >> carWeight;
        }
        if ( !is.bad() ) {
            cout << "Parse OK" << endl;
        }
    }
}


Your first steps being
- put all your vehicle variables into a struct.
- make lines 23 to 33 into a function.
I found a way to factor out the weight but now I have different problems with this program. Thank you for your help!
Edit your post again, and put the [code][/code] tags around your code (the <> format tool on the right).

Better yet, reply with a new post, with the new code.
Then we can see how you're progressing.
Topic archived. No new replies allowed.