Parking Ticket

So here's the thing...I'm working on a program called Parking Ticket Simulator, but for reasons that I cannot grasp, the program isn't running properly...I will be posting part of the code where I think I'm making the errors...Thanks in advance for your assistance.

instructions

Parking Ticket Simulator
For this assignment you will design a set of classes that work together to simulate a
police officer 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 fine, which is $25 for the first 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 officer 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 officer’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

P.S. I'm still learning c++, so if you see abnormalities please be nice...lol



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
  #pragma once
#include<iostream>
#include"ParkedCar.h"
#include"ParkingMeter.h"
#include"PoliceOfficer.h"
#include<string>
using namespace std;



class ParkingTicket {

private:

	int fine;
	ParkingMeter PM;
	ParkedCar PC;
	PoliceOfficer PO;


public:
	ParkingTicket();
	ParkingTicket(string aname, string abadge, string amake, string amodel, string acolor, string alicensenumber, int aparkedminutes, int aminutespurchased);
	~ParkingTicket();
	int getfine() const;
	void generateticket();
	void reportCarInfo();
	void reportfine();
	void reportOfficer();


};


ParkingTicket.cpp
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
#include"ParkingTicket.h"



ParkingTicket::ParkingTicket()
{
	fine = 0;
}

ParkingTicket::ParkingTicket(string aname, string abadge, string amake, string amodel, string acolor, string alicensenumber, int aparkedminutes, int aminutespurchased)
{
	PC.set(amake, amodel, acolor, alicensenumber, aparkedminutes);
	PM.setparkingmeter(aminutespurchased);
	PO.setOfficer(aname, abadge);
}

ParkingTicket::~ParkingTicket()
{
}

void ParkingTicket::reportCarInfo()
{
	PC.parkedcardisplay();
}

void ParkingTicket::reportfine()
{
	int illegaltime = PC.getparkedminutes() - PM.getparkingmeter();
	if (illegaltime> 0 && illegaltime <= 60) {
		fine = 25;
	}
	else {
		if (illegaltime > 60)
		{
			int temp = illegaltime;
			fine = 25;
			while (temp > 0 || temp > 60)
			{
				fine += 10;
				temp -= 60;
			}
		}
	}
		cout << "Fine: $" << getfine() << endl;
}

void ParkingTicket::reportOfficer()
{
	PO.displayofficer();
}

int ParkingTicket::getfine() const
{
	return fine;
}


void ParkingTicket::generateticket()
{
	cout << endl;
	cout << "-----------------------------" << endl;
	cout << "   ~ILLEGAL PARKING TICKET~" << endl;
	cout << "-----------------------------" << endl;
	reportCarInfo();
	reportfine();
	reportOfficer();
	cout << endl;

}


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

using namespace std;


class PoliceOfficer {


private:
	string name;
	string badge;
	ParkingMeter PM;
	ParkedCar PC;
	


public:
	PoliceOfficer();
	PoliceOfficer(string aname, string abadge, string amake, string amodel, string acolor, string alicensenumber, int aparkedminutes, int aminutespurchased);
	~PoliceOfficer();
	void setname(string);
	void setbadge(string);
	void setOfficer(string, string);

	string getname() const;
	string getbadge() const;
	void patrol();

	void displayofficer() const;
};


PoliceOfficer.cpp
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
#include"ParkedCar.h"
#include"ParkingMeter.h"
#include"ParkingTicket.h"
#include"PoliceOfficer.h"
#include<iostream>
#include<string>
using namespace std;




PoliceOfficer::PoliceOfficer()
{
	
	badge = " ";
	name = " ";

}
PoliceOfficer::PoliceOfficer(string aname, string abadge, string amake, string amodel, string acolor, string alicensenumber, int aparkedminutes, int aminutespurchased)
{
	PC.set(amake, amodel, acolor, alicensenumber, aparkedminutes);
	PM.setparkingmeter(aminutespurchased);
	setOfficer(aname, abadge);
}

PoliceOfficer::~PoliceOfficer()
{
}


void PoliceOfficer::setname(string aname) 
{
	name = aname;
}
void PoliceOfficer::setbadge(string abadge)
{
	badge = abadge;
}

void PoliceOfficer::setOfficer(string aname, string abadge)
{
	badge = abadge;
	name = aname;
}

string PoliceOfficer::getname() const 
{
	return name;
}
string PoliceOfficer::getbadge() const 
{
	return badge;
}
void PoliceOfficer::displayofficer() const
{
	cout << "Name: " << getname() << endl;
	cout << "Badge ID: " << getbadge() << endl;
}

void PoliceOfficer::patrol() 
{
	if (PC.getparkedminutes() > PM.getparkingmeter())         /*parked minutes >= minutes purchased*/
	{
		ParkingTicket PT;

		PT.generateticket();
	}
	else
	{
		cout << "No crime has been commited." << endl;
	}
}

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

using namespace std;


int main()

{
	int option;
	PoliceOfficer officer;
	ParkedCar car;
	ParkingMeter meter;
	do {
		string aname, abadge, amake, amodel, alicensenumber, acolor;
		int aminutespurchased, aparkedminutes;

		
		cout << "--------------------------------" << endl;
		cout << "   ~Parking Ticket Simulator~" << endl;
		cout << "--------------------------------" << endl;
		cout << endl;
		cout << "Vehicle Information:" << endl;
		cout << "Make: ";
		getline(cin, amake);
		cout << "Model: ";
		getline(cin, amodel);
		cout << "Color: ";
		getline(cin, acolor);
		cout << "License Number: ";
		getline(cin, alicensenumber);
		cout << "Parked Minutes: ";
		cin>> aparkedminutes;
		car.set(amake, amodel, acolor, alicensenumber, aparkedminutes);

	cout << "Minutes Purchased: ";
		cin >> aminutespurchased;
		meter.setparkingmeter(aminutespurchased);

		cout << endl;
		cout << "Officer Information:" << endl;
		cout << "Name: ";
		getline(cin, aname);
		cout << "Badge ID: ";
		getline(cin, abadge);
		officer.setOfficer(aname, abadge);

		system("cls");
		officer.patrol();
		cout << endl;
		cout << "Enter 0 to exit or any number to restart: ";
		cin >> option;
	} while (option != 0);

	system("pause");
	return 0;



}

closed account (48T7M4Gy)
You have over-complicated things a bit by having constructors with far too many (and unnecessary) attributes. For instance, PoliceOfficer only has two attributes, name and badge no. PoliceOfficer's don't have make, model etc - ParkedCars do.

Where you may be unclear and why you are doing that is because the place where objects (and their attributes) are combined is in the method, functions and reports.

But here again all you need do is combine the objects, not a great long list of attributes. The parameters are just the objects and all you need do is ask yourself the question what objects do I need to put the report together.

eg
To examine a ParkedCar object and a ParkingMeter object, and determine whether the car's time has expired
1
2
3
4
void PoliceOfficer::reportFine(ParkedCar pc, ParkingMeter pm)
{
    // code to prepare/display report goes here using gets and sets etc.
}


This is called in main something like this:

officer_plod.reportFine(some_parked_car, a_parking_meter);





The reason why i did this:
1
2
3

ParkingTicket(string aname, string abadge, string amake, string amodel, string acolor, string alicensenumber, int aparkedminutes, int aminutespurchased);


and

1
2
3
4
5
6
7
8

PoliceOfficer::PoliceOfficer(string aname, string abadge, string amake, string amodel, string acolor, string alicensenumber, int aparkedminutes, int aminutespurchased)
{
	PC.set(amake, amodel, acolor, alicensenumber, aparkedminutes);
	PM.setparkingmeter(aminutespurchased);
	setOfficer(aname, abadge);
}


was because I was under the impression that when ever i create an object inside a class I have to initialize it.

So I created the object PC type parkedcar and set() it with the information that should be entered by the police officer otherwise it will be empty because it will contain the information from the default constructor which is 0 or empty spaces...correct me if I'm wrong or mixing things up.

Edit. So every time I created a private object from another class I added the setter on the constructor...
Last edited on
If i do this
1
2
3
4
5
void PoliceOfficer::reportFine(ParkedCar pc, ParkingMeter pm)
{
    // code to prepare/display report goes here using gets and sets etc.
}


I still need:

ParkedCar PC;
ParkingMeter PM;

on the private section right?

Edit.
The generateticket function is inside parkingticket, but I need the information of the police officer, the parkedcar and the parkingmeter to create it, so i place object parameters, but how can I call the function generateticket inside policeofficer if it requieres a policeofficer object. It's kind of odd to create an object inside it's own class.

Not sure If i'm explaining myself correctly, let me know.


here's the visual version:

Inside ParkingTicket:
1
2
3
4
void ParkingTicket::generateticket(ParkedCar PC, ParkingMeter PM, PoliceOfficer PO)
{
/*code that generates a ticket */
}


Inside PoliceOfficer:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

void PoliceOfficer::patrol(ParkedCar PC, ParkingMeter PM, PoliceOfficer PO???????) 
{
	if (PC.getparkedminutes() > PM.getparkingmeter())         /*parked minutes > minutes purchased*/
	{
		ParkingTicket PT;
		PT.generateticket(PC,PM,PO???);
	}
	else
	{
		cout << "No crime has been commited." << endl;
	}
}



I'm still learning so I appreciate all the explanation you can give me. ^.^
Last edited on
closed account (48T7M4Gy)
Yes, you still need the objects to be created. But you should create them separately and that is where they remain as private members. They are only accessible outside their class via the get and set methods

You 'send' them as objects via the parameter list to the report method in the PoliceOfficer class.

The only problem I see so far is your PoliceOfficer PO ???? inclusion. The parameter list is as I showed because main should be

officer_plod.reportFine(some_parked_car, a_parking_meter);

What this means is officer_plod is ordering a report to be prepared for some_parked_car at a_parking_meter. officer_plod knows who he is so you just use name, badge in the method and dot notation for the parameters as you did.

See how you go. It appears you are advancing believe it or not. :)


closed account (48T7M4Gy)
Please remove you multiple posts.
http://www.cplusplus.com/forum/beginner/214465/
Alright, thanks. I'll see what I can do. How do I remove the post?
closed account (48T7M4Gy)
Just green tick one of them as complete and just use one will be ok
Topic archived. No new replies allowed.