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.
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.
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
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
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.
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;