Can someone help me process this file please

Hello all,

This is my first big project in college as a computer scientist involving everything that I have ever learned and is the first time im using classes in a big way.

So I am supposed to get ALL input into my program from a file. Everything is supposed to be processed and determined by this file. I have never done file processing of this nature where no human interaction is accepted to simulate this "parking lot".

I am not sure how to extract the exact words I need to in order to have the right classes interact with those words. Some are words, numbers, times, etc. This is proving very difficult for me. The code that I have provided is bare minimum. I just wanted to see how I would even begin reading the file, which I have done so now. Now that I have read the file with the member function, I am clueless on how to take out the pieces that I need and send them all to different places

without further notice, here is the main function and the class I am trying to use to process this file.

Main Function

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
#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
#include <cstring>
#include "ParkedCar.h"
#include "ParkingMeter.h"
#include "ParkingTicket.h"
#include "PoliceOfficer.h"
#include "ProcessFiles.h"

using namespace std;

int main ()
{
   const int ARRAY_SIZE = 25;
	fstream inFile("parking.txt", ios::in);
   ProcessFiles fileArray;

	if (inFile.fail () )
	{
		cout << "Error, could not open parking.txt";
	}

   while (inFile.good ())
   {
      fileArray.setArraySize(ARRAY_SIZE);
      fileArray.setArray(inFile, ARRAY_SIZE);
   }



   //ProcessFiles makeFile;

   inFile.close();

	system ("pause");
	return 0;
}


Header File

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
#ifndef PROCESSFILES_H
#define PROCESSFILES_H
#include <fstream>
#include <iostream>

using namespace std;

class ProcessFiles
{
	private:     // Holds size of the array created by constructor
      char *fileArray;

	public:

    // default constructor
	ProcessFiles ()
   {
      cout << "this is ProcessFiles default contructor\n\n";
   }

   void setArraySize(int);
   void setArray(fstream &, int);

};
#endif 


.cpp File

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
#include "ProcessFiles.h"
#include <fstream>
#include <string>
#include <iostream>
#include <istream>

using namespace std;

void ProcessFiles::setArraySize(int size)
{
   cout << "This is the ProcessFiles setArraySize member function\n\n";

   fileArray = new char [size];
}

void ProcessFiles::setArray(fstream &file, int size)
{
   string holdData;
   
   while (file.good())
   {
         file >> holdData;
         cout << holdData << " ";
         cout << endl;
   }

   cout << endl << endl;
}
Last edited on
Here is the file that I am supposed to be processing

enter 3 06:30 Ford Fiesta Maroon 38MAG4 120
enter 10 06:30 Chevy Cruze Black 15LAW8 13
in Andy 6497 06:30
enter 2 06:31 Honda Accord Silver 29RBD3 20
exit 10 06:52
out Andy 07:30
enter 4 07:30 Nissan Sentra Purple 15RTR2 30
in Sue 3887 07:30
exit 2 07:39
exit 4 07:50
out Sue 09:30
in Tom 4975 09:30
exit 3 10:20

I am required to have 4 different classes.
One for the parked car
One for the police officer
One for the parking meter
One for the parking ticket.

Parked car is responsible for keeping track of
Make (15 alphanumeric characters, no spaces)
Model (20 alphanumeric characters, no spaces)
Color (10 alphanumeric characters, no spaces)
License Number (6 alphanumeric characters, no spaces)
Parking Time (military time)

Parking Meter Class: responsible for amount of time paid that has been purchased (in minutes)

 Parking Ticket Class: responsible for creating a parking ticket containing the
Make
Model
Color
License Number
Fine
Officer Name
Officer Badge Number

Police Officer Class: Responsible for determining if a car should get a ticket and generating that ticket. The class is responsible for knowing:
Officer Name (10 alphanumeric characters, no spaces)
Officer Badge Number
Clock In Time
There are a lot of ways to organize this... Think of your scenario as different objects in a play... all having their own behavior and data.

One way to do this, would be to have a car 'superclass', which has connections to all the data that can possibly be associated to it.

That said, you can have the car class have member variables that are pointers to the other three classes.

If the car was ticketed, for example, you would instantiate a Ticket class with PoliceOfficerName BadgeNum...etc data members and assign it to a pointer the car class TicketPtr or p_Ticket pointer. If the car did not get a ticket, this member variable pointer will be == NULL in the car class.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Class CTicket
{
public:
    string PoliceOfficerName;
    string BadgeNum;
     .
     .
     .
};

Class Car
{
public:
    int ti_hh;             // time in - hour
    int ti_mm;           // time in - minute
    int ti_ss;             // time in - secs
  .
  .
    CTicket *p_tkt;    // a pointer to class CTicket.
    CFine *p_fine;     // a pointer to class Fine
  .
  .
  .
};


Order is important. If you have all kinds of pointers to your other home-grown classes in your car class in your first-defined class, the compiler will not have any idea what these pointers are pointing at. So put your sub-class definitions at the top, above the car class.

hth
Last edited on
Topic archived. No new replies allowed.