Link to home
Start Free TrialLog in
Avatar of pacman32689
pacman32689

asked on

ParkingTicket class not playing nice with others

Hi again experts. I have now added a ParkingTicket class to my project to write the poor car who goes overtime a hefty ticket. However, When I try to compile the entire sucker, i get about 4 errors, telling me that ParkedCar is not a type inside my ParkingTicket.h file. The parking ticket should use the computeFine method when called and display all the information about the car, the fine amount, and the officer's badge number and name. The officer is what I have to have done by next week, so for now I have a static name and number.

 Thank you experts, I am new to object oriented programming in C++ and am a bit lost as to understanding why it isn't recognizing my use of the ParkedCar class. Am I not suppose to call the class in that way?
Driver:
 
#include <iostream>
#include "ParkedCar.h"
#include "ParkingMeter.h"
#include "ParkingTicket.h"
 
using namespace std;
 
int main()
{
	ParkedCar car1;
	ParkingMeter meter1;
	meter1.setTime(100);
	car1.setMake("Ford");
	car1.setModel("Taurus");
	car1.setColor("Maroon");
	car1.setLicence(1337);
	car1.setMinutes(25);
	ParkingTicket ticket1(car1,25,"Lou",92);
	ticket1.setMinutesIllegalPark(15);
	cout << ticket1.getMinutesIllegalPark() << endl;
}	
 
ParkedCar.h
 
#ifndef PARKEDCAR_H
#define PARKEDCAR_H
 
class ParkedCar
{
	private:
		char make[30];
		char model[30];
		char color[30];
		int licenceNumber;
		int minutesParked;
	public:
		ParkedCar();
		ParkedCar(const char* make1, const char* model1, const char* color1, int licenceNumber1, int minutesParked1);
		const char* getMake();
		const char* getModel();
		const char* getColor();
		int getLicenceNumber();
		int getMinutesParked();
		void setMake(const char * make1);
		void setModel(const char* model1);
		void setColor(const char* color1);
		void setLicence(int licenceNumber1);
		void setMinutes(int minutesParked1); 
};
#endif		
 
ParkedCar.cpp
 
#include <iostream>
#include "ParkedCar.h"
 
ParkedCar::ParkedCar()
{
	make[0] = '\0';
	model[0] = '\0';
	color[0] = '\0';
	licenceNumber = 0;
	minutesParked = '\0';
}	
ParkedCar::ParkedCar(const char* make1, const char* model1, const char* color1, int licenceNumber1, int minutesParked1)
{
	licenceNumber = licenceNumber1;
	minutesParked = minutesParked1;
}
const char* ParkedCar::getMake()
{
	return make;
}
 
const char* ParkedCar::getModel()
{
	return model;
}
 
const char* ParkedCar::getColor()
{
	return color;
}
 
int ParkedCar::getLicenceNumber()
{
	return licenceNumber;
}
 
int  ParkedCar::getMinutesParked()
{
	return minutesParked;
}
void ParkedCar::setMake(const char* make1)
{
	strcpy(make,make1);
}
void ParkedCar::setModel(const char* model1)
{
	strcpy(model,model1);
}
void ParkedCar::setColor(const char* color1)
{
	strcpy(color,color1);
}
void ParkedCar::setLicence(int licenceNumber1)
{
	licenceNumber = licenceNumber1;
}
void ParkedCar::setMinutes(int minutesParked1)
{
	minutesParked = minutesParked1;
}
	
ParkingMeter.h
 
#ifndef PARKINGMETER_H
#define PARKINGMETER_H
 
class ParkingMeter
{
	private:
		int timePurchased;
	public:
		ParkingMeter();
		ParkingMeter(int timePurchased);
		void setTime(int time);
		int getTime();
		
};
#endif
 
ParkingMeter.cpp
 
#include <iostream>
#include "ParkingMeter.h"
 
ParkingMeter::ParkingMeter()
{
	timePurchased = 0;
}
ParkingMeter::ParkingMeter(int time)
{
		timePurchased = time;
}
 
int ParkingMeter::getTime()
{
	return timePurchased;
}
 
void ParkingMeter::setTime(int time)
{
	timePurchased = time;
}
 
ParkingTicket.h
 
#ifndef PARKINGTICKET_H
#define PARKINGTICKET_H
 
class ParkingTicket
{
	private:
			ParkedCar car1;
			int minutesIllegalPark;
	public: 
			ParkingTicket();
			ParkingTicket(ParkedCar,int minutes,char*,int);
			void computeFine(ParkedCar,int,char*,int);
			int getMinutesIllegalPark();
			void setMinutesIllegalPark(int minutes);
};
#endif			
 
ParkingTicket.cpp
 
#include "ParkingTicket.h"
#include <iostream>
 
ParkingTicket::ParkingTicket()
{
	minutesIllegalPark = 0;
}
ParkingTicket::ParkingTicket(ParkedCar car1,int minutesIllegalPark,char* officer,int badgeNumber)
 
	
{
		computeFine(ParkedCar car1,int minutesIllegalPark,char* officerName,int badgeNumber);
}
 
void ParkingTicket::getMinutesIllegalPark()
{
	return minutesIllegalPark;
}
 
void ParkingTicket::setMinutesIllegalPark(int minutes)
{
	minutesIllegalPark = minutes;
}
 
void ParkingTicket::computeFine(ParkedCar car1,int minutesIllegalPark,char* officerName,int badgeNumber)
{
	int fineAmount;
	
	if( minutesIllegalPark <= 15)
	{
		fineAmount = 25;
	}
	else
	{
		fineAmount = 25 + 5(minutesIllegalPark - 15)
	}
	
	cout << car1.getMake() << endl;
	cout << car1.getModel() << endl;
	cout << car1.getColor() << endl;
	cout << car1.getLicenceNumber() << endl;
	cout << fineAmount << endl;
	cout << officerName << endl;
	cout << badeNumber << endl;
}

Open in new window

Avatar of Anthony2000
Anthony2000
Flag of United States of America image

I think if you are having a problem with the compiler not being able to find the ParkedCar class. When you define the ParkingTicket you refer to ParkedCar class, but in some cpp files the compiler will not find the definition of ParkedCar. I see in main that you include all the necessary header files. But in ParkingTicket.cpp you only include ParkingTicket.h.

The way I usually solve this, is to include the header files for any classes I use in the header file I am using the classes in.

So, in ParkingTicket.h add the include for ParkedCar.h. and then check all your other header files for any other dependencies like this.

Does this help?
Your compiler will compile each .cpp separately, if while compiling it cannot find a definition for a class, it will give you the error you are seeing.
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pacman32689
pacman32689

ASKER

Sorry, I had fixed those earlier and forgot to update. I figured it out though, thanks for the help!
Thanks
>> I figured it out though, thanks for the help!

Note that the problem that directly caused this error :

        4 errors, telling me that ParkedCar is not a type inside my ParkingTicket.h file.

was the missing include (as jkr pointed out).