problem using classes

hello, im having trouble setting and initializing data to an array oject.
the point of the program is to have the dmv class display data if the id is
right, the other two classes (person and car) are to set the person's
information. any advice is welcomed, i need all the help i can get.

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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <iostream>
#include <string>
using namespace std;

class person;
class car;

class DMV
{
public:
	DMV();
	~DMV();
	void set_id(int);
	void show_data(person p, car c);

private:
	void saved_data(); //use later with fstream
	int drivers_id;
};

class person 
{
public:
	person();
	~person();
	void set_person(string, string, int);

private:
	string firstname;
	string lastname;
	int birthyear;

	friend class DMV;
};

class car
{
public:
	car();
	~car();
	void set_car(string, string, int);

private:
	string carmake;
	string carmodel;
	int caryear;

	friend class DMV;
};
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////DMV////////////////////////////////////////////////
DMV::DMV(){}
DMV::~DMV(){}

void DMV::set_id(int id)
{
	drivers_id = id;
}
void DMV::show_data(person p, car c)
{
	//CODE HERE
	cout << drivers_id << endl;
	cout << "Birth year: " << p.birthyear << endl; 
	cout << p.lastname << ", " << p.firstname << "drives a " 
		<< c.caryear << c.carmake << c.carmodel << endl;
}
void DMV::saved_data()
{}
//////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////PERSON///////////////////////////////////////////
person::person(){}
person::~person(){}

void person::set_person(string f, string l, int y)
{
	firstname = f;
	lastname = l;
	birthyear = y;
}
//////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////CAR//////////////////////////////////////////////
car::car(){}
car::~car(){}

void car::set_car(string mk, string ml, int yr)
{
	carmake = mk;
	carmodel = ml;
	caryear = yr;
}
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////

int main()
{
	int temp_id;
	DMV *a = new DMV[3]; 
	DMV show;
	a->set_id(5555);  
	person *ptrPer = &a[1];		
	car *ptrCar = &a[2];			
	ptrPer->set_person("Bill", "Hendrson", 1986); 
	ptrCar->set_car("Porsche", "911", 2012);
	
	
	cout << "enter 4-digit driver's id: ";
	cin >> temp_id; 
	cout << endl;
	if(temp_id == 5555) 
		show.show_data(person, car); 
	else
		cout << "Driver id not found." << endl;

	
	
	system("pause");
	return 0;
}
Did not check the whole thing, but you are acquiring pointers of DMV objects and treating them as car and person objects! Wrong because they don't derive from DMV. I am surprise that even compiles. What compiler are you using that allows these treacherous maneuvers??
Topic archived. No new replies allowed.