Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

Please assist with the beloow question : Question 3 (15 marks) C++ program that the Traffic Department can use when the owner of a car pays all his...

Please assist with the beloow question :

Question 3 (15 marks)

C++ program that the Traffic Department can use when the owner of a car pays all his outstanding road fines. The Traffic Department has a file called Fines.dat that keeps the registration number and the road fine due for each traffic offence, one per line.

Your program should request the registration number from the user, read the contents of file Fines.dat (shown below) line by line; if the road fine matches the registration number, display the fine and calculate the total amount due for that registration number. At the same time all the remaining registration numbers and road fines should be written to a new file called OutStandingFines.dat.

Run your program to calculate the road fines owed by a car with registration number ABC123. 

Fines.dat: ABC123 400 DEC234 340 ABC123 500 GED345 600 ABC123 240 GEE600 120 GED345 230 GEE600 470 ABC123 120

NB: You should not count the number of lines in the file to determine how many times the file should be accessed.

Sample output: Please enter registration number: ABC123 Fines: R400.00 R500.00 R240.00 R120.00 Total fine due R1260.00

Process returned 0 (0x0)  execution time : 4.309 s

I have done below but NOT working :

#include <iostream>

#include <iostream>

#include <fstream>

#include <cstdlib>

using namespace std;

int main()

{

   string vehicleReg;

   double fines[9];

   cout << "Enter the vehicle registration number: " << endl;

   cin>>vehicleReg;

   ifstream in_stream;

   in_stream.open("fines.dat");

   if(in_stream.fail())

   {

       cout << "Failed to open input file!" << endl;

       exit(0);

   }

   else

   {

       cout << "Input file" << endl << endl;

       while(in_stream >> vehicleReg)

       {

           cout << vehicleReg << 't';

           for (int i = 0; i < 9; i++)

           {

               in_stream >> fines[i];

               cout << fines[i] << 't';

           }

           cout << endl;

       }

   }

   ofstream out_stream;

   out_stream.open("fines.dat");

   if(out_stream.fail())

   {

       cout << "Failed to open output file! " << endl;

       exit(0);

   }

   in_stream.close();

   out_stream.close();

   //read and display contents of output file

   //as an input file

   in_stream.open("fines.dat");

   if(in_stream.fail())

   {

       cout << "Failed to open input file" << endl;

       exit(0);

   }

   else

   {

       cout << endl <<"Vehicle outstanding fines OutStandinFines.dat:" << endl

       << endl;

       while(in_stream >> vehicleReg)

       {

           cout << vehicleReg << endl;

       }

   }

   in_stream.close();

   out_stream.close();

   return 0;

}

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question