Parking ticket cycle between headers

Hello and thank you there seems to be a problem with the code below, when i go and compile the program says that "PC\Desktop\Program 7 Test\ParkingTicket.h [Error] #include nested too deeply" but i'm not seeing where or how to fix the problem any help will be appreciated code below.

Main
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
 #include<iostream>
#include<cmath>
#include<string>
#include "ParkedCar.h"
#include "ParkingMeter.h"
#include "ParkingTicket.h"
#include "PoliceOfficer.h"

using namespace std;

int main()
{
    string carMake;
    string carModel;
    string carColor;
    string carLicenseNum;  
    int numMinutesParked;                 
    int purchasedParkingMins;             
    string lastName;                      
    string firstName;                 
    string badgeNum; 

    cout << "Enter information for each object below.\n" << endl;
    cout << "CAR:\n" << endl;
    cout << "Make: ";
    cin >> carMake;
    cout << "Model: ";
    cin >> carModel;
    cout << "Color: ";
    cin >> carColor;
    cout << "License Number: ";
    cin >> carLicenseNum;

    do
    {
        cout << "Number of minutes car has been parked: ";
        cin >> numMinutesParked;
    }
    while (numMinutesParked < 0);

    ParkedCar car1(carMake, carModel, carColor, carLicenseNum, numMinutesParked);  
    cout << "\nMETER:\n" << endl; 

    do
    {
        cout << "Number of minutes purchased: ";
        cin >> purchasedParkingMins;
    }
    while (purchasedParkingMins < 0);

    ParkingMeter meter1(purchasedParkingMins);

    cout << "\nPOLICE OFFICER:\n" << endl;          
    cout << "First Name: ";
    cin >> firstName;
    cout << "Last Name: ";
    cin >> lastName;
    cout << "Badge Number: ";
    cin >> badgeNum;

    PoliceOfficer officer1(lastName, firstName, badgeNum);     

    if (officer1.isTicketNeccessary(car1, meter1) == true)        
    {
        ParkingTicket ticket1(car1, meter1, officer1);           
        ticket1.print();                                         
    }
    else                                                         
    {
        cout << "\n* No ticket issued. *" << endl;
    }

    return 0;
}


ParkedCar.h
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
#ifndef PARKINGCAR_H
#define PARKINGCAR_H

  #include <iostream>
#include "ParkingMeter.h"
#include "ParkingTicket.h"

using namespace std;

class ParkedCar
        {
            public:
            carMake = "";
            carModel = "";
            carColor = "";
            carLicenseNum = "";
            numMinutesParked = 0;
        }

        ParkedCar(string cMake, string cModel, string cColor, string cLicenseNum, int cNumMinParked)
        {
            carMake = cMake;
            carModel = cModel;
            carColor = cColor;
            carLicenseNum = cLicenseNum;
            numMinutesParked = cNumMinParked;
        }

        int getNumParkedMinutes() const
        {
            return numMinutesParked;
        }

        void print() 
        {
            cout << "- Car -\n" << endl;
            cout << "Make: " << carMake << endl;
            cout << "Model: " << carModel << endl;
            cout << "Color: " << carColor << endl;
            cout << "License Number: " << carLicenseNum << endl;
        }
};
#endif 


ParkingMeter.h
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
  #include <iostream>

using namespace std;

class ParkingMeter
{
    private:
        int purchasedParkingMins;                     

    public:
        ParkingMeter()                                
        {
            purchasedParkingMins = 0;
        }

        ParkingMeter(int purchasedMinutes)            
        {
            purchasedParkingMins = purchasedMinutes;
        }

        int getPurchasedParkingMins() const           
        {
            return purchasedParkingMins;
        }

        void print()                                  
        {
            cout << "- Meter -\n" << endl;
            cout << "Number of minutes purchased : " << purchasedParkingMins << endl;
        }
};


ParkingTicket.h
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
#ifndef PARKINGTICKET_H
#define PARKINGTICKET_H

  #include <iostream>
#include "ParkedCar.h"
#include "ParkingMeter.h"
#include "PoliceOfficer.h"

using namespace std;

class ParkingTicket
{
    private:
        ParkedCar car;                    
        ParkingMeter meter;               
        PoliceOfficer officer;            
        int fineAmount;                   

    public:
        ParkingTicket(ParkedCar &carT, ParkingMeter &meterT, PoliceOfficer &officerT)         
        {
            car = carT;                              
            meter = meterT;
            officer = officerT;
            fineAmount = calcFineAmount();
        }

        int calcFineAmount()               
        {
            return (25 + 10 * (ceil((car.getNumParkedMinutes()- meter.getPurchasedParkingMins())/60.0) - 1));
        }

        void print()        
        {
            cout << "\n\n***** TICKET INFORMATION *****" << endl;
            cout << "-------------------------------------" << endl;
            car.print();
            cout << "-------------------------------------" << endl;
            officer.print();
            cout << "-------------------------------------" << endl;
            cout << "- Fine -\n\n" << "Amount: $" << fineAmount << endl;
            cout << "-------------------------------------" << endl;
        }
};
#endif 


PoliceOfficer.h
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
  #include <iostream>
#include <string>
#include <vector>
#include "ParkedCar.h"
#include "ParkingMeter.h"
#include "ParkingTicket.h"

using namespace std;

class PoliceOfficer
{
    private:
        string lastName;                        
        string firstName;                       
        string badgeNum;                        

    public:
        PoliceOfficer()                         
        {
            lastName = "";
            firstName = "";
            badgeNum = "";
        }

        PoliceOfficer(string lName, string fName, string bNum)         
        {
            lastName = lName;
            firstName = fName;
            badgeNum = bNum;
        }

        bool isTicketNeccessary(ParkedCar& c, ParkingMeter& m)       
        {
            if ((m.getPurchasedParkingMins() - c.getNumParkedMinutes()) < 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        void print()                                    
        {
            cout << "- Police Officer -\n" << endl;
            cout << "First Name: " << firstName << endl;
            cout << "Last Name: " << lastName << endl;
            cout << "Badge Number: " << badgeNum << endl;
        }
};



Sorry i know it a lot of code again thank you for any help.
Last edited on
You have recursive includes.
parkedcar.h includes parkingticket.h
parkingticket.h includes parkedcar.h

parkingticket.h includes policeofficer.h
policeofficer.h includes parkingticket.h

You have no include guards which prevent a header file from being included more than one time.
https://en.wikipedia.org/wiki/Include_guard

Hello AnimeByDay,

First thing I noticed is the "ParkedCar.h" file should be "ParkedCar.cpp" as it is not a header file, but an implementation file. Which means that you are missing the "ParkedCar.h" file along with the ".cpp" files to go with your other classes. BTW the "ParkedCar" has a closing "};" that does not need to be there.

With what you have posted I can not compile your program and I have more errors than the one you have described.

Glad to help, but I need more to be able to duplicate your problem.

Andy
OK thank you completely forgot about the guards i added them in but now im getting a lot of not declared in scope errors can anyone help with this and Andy m pretty sure it should be a header mainly because that is what the teacher wants.

Mainly something like this: 12 13 C:\Users\AnimeByDay's PC\Desktop\Program 7 Test\ParkedCar.h [Error] 'carMake' was not declared in this scope

Any help with this would be appreciated
Last edited on
You need to look carefully are the order of includes and which ones are truly necessary within other headers.

For example, why does parkedcar.h include parkingmeter.h and parkingticket.h? It requires neither.

Why is isTicketNeccessary() a member of PoliceOfficer class? If you move this function elsewhere, you can remove parkedcar.h and parkingmeter.h from policeoffice.h. parkingticket.h can also be removed. It is not referenced in policeoffice.h.

If another object is only a reference or a pointer, you can get away with declaring the class as forward.
 
class ParkingMeter;  // Forward reference 


@Handy Andy - I believe parkedcar.h is indeed a header file. It looks like
10
11
12
class ParkedCar
{
public:

accidentally got deleted.


Last edited on
thanks for the help, but ticket necessary() is there because the police officer is the one who should make that judgment no? thank you tho but if i was to move it where can i move it also yea sorry i did forget to add in the class and public: part in the code.

on another note im still getting stuff like "'carMake' was not declared in the scope" for this it cant just pull the needed info from another file (sorry if you cant this is literally the first time working with multiply files)

also stuff like this "'carMake' does not name a type" but again why isn't it getting info from other header/main file. ie. string carMake in the main file??

thanks for all the help!

Also here is some more info in case you needed it

14. Parking Ticket Simulator
For this assignment you will design a set of classes that work together to simulate a
police of cer issuing a parking ticket. The classes you should design are:
* The ParkedCar Class: This class should simulate a parked car. The class s
responsibilities are:
To know the car s make, model, color, license number, and the number of
minutes that the car has been parked
* The ParkingMeter Class: This class should simulate a parking meter. The class s
only responsibility is:
To know the number of minutes of parking time that has been purchased
* The ParkingTicket Class: This class should simulate a parking ticket. The
class s responsibilities are:
To report the make, model, color, and license number of the illegally
parked car
To report the amount of the ne, which is $25 for the rst hour or part of an
hour that the car is illegally parked, plus $10 for every additional hour or
part of an hour that the car is illegally parked
To report the name and badge number of the police of cer issuing the
ticket
* The PoliceOfficer Class: This class should simulate a police officer inspecting
parked cars. The class s responsibilities are:
To know the police of cer s name and badge number
To examine a ParkedCar object and a ParkingMeter object, and determine
whether the car s time has expired
To issue a parking ticket (generate a ParkingTicket object) if the car s time
has expired
Write a program that demonstrates how these classes collaborate.
Last edited on
still getting stuff like "'carMake' was not declared in the scope" for this it cant just pull the needed info from another file

No it can't.
Your PoliceOfficer class looks OK - you declare a bunch of member variables and then refer to them in the constructor, etc.
But in your ParkedCar class, you're referring to variables that don't exist. You've declared variables with the same names in your main function but they're different variables in a different scope and not accessible inside ParkedCar. If you rewrite this class using the same template you used for PoliceOfficer, those errors should disappear. To be replaced by other ones, no doubt, but at least you'll be one step closer.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class ParkedCar
        {
            public:
             carMake = "";
             carModel = "";
             carColor = "";
             carLicenseNum = "";
             numMinutesParked = 0;

            // Declare these as private member variables inside class.
            private:
                string carMake;
                string carModel;
                string carColor;
                string carLicenseNum;
                int numMinutesParked;
Topic archived. No new replies allowed.