class inheritance project need explanation

I am currently taking a c++ and was jusy recently given an assignment using class inheritance. was wondering if anyone could help explain what im doin wrong.

Define a base class person that will contain universal information, including name, address, birth date, gender and identification (student, worker etc). Derive from this class the following classes:
Student
Worker
Student_worker

Write a program that asks user to input information (student, worker etc) and creates a list of persons. Give user choice to view list by gender and by identification( list of people who are students, list of people who are workers etc).

im getting alot of undeclared identifier errors. sorry all i would ask my prof but she doesn't speak english too good. lol


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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include "Person.h"

Person::Person(void)
{
	name = "";
	bday = 00000000;
	ad_num = 000;
	stName = "";
	gender = '';
}

Person::Person(string n, char g, int dob, string st, int ad, string id)
{
	name = n;
	ID = id;
	gender = g;
	bday = dob;
	stName = st;
	ad_num = ad;

}
void Person::input()
{
	cout<<"Enter Name and Title"<<endl;
	cin>>name>>ID;
	cout<<"Enter Gender M/F"<<endl;
	cin>>gender;
	cout<<"Enter date of Birth in this format: (MMDDYYYY)"<<endl;
	cin>>bday;
	cout<<"Enter address in this format (### StreetName)"<<endl;
	cin>>ad_num>>stName;
}

void Person::print()
{
	cout<<name
		<<ID
		<<bday
		<<ad_num>>stName
		<<gender;
}

Person::~Person(void)
{
}

#pragma once
#include<iostream>
#include<string>
using namespace std;

class Person
{
public:
	Person();
	~Person();
string get_name(string name)
{
	return name;
}

void set_name(string n)
{
	name = n;
}
Person();
Person(string, int a, char);
void input();
void print();


protected:
	string ID;
	int bday;
	int ad_num;
	string stName;
	char gender;
	


};

#pragma once
#include "Person.h"

class Worker :
	public Person
{
public:
	Worker(void);
	Worker(string 3,string 4);
	Worker::Worker():Person()
	{
		company = "";
	}

private:
	string company;

	~Worker(void);
};

#include "Worker.h"

Worker::Worker(void)
{
}

Worker::~Worker(void)
{
}

#pragma once
#include "Person.h"

class Student :
	public Person
{
public:
	Student(void);
	Student(string 5,string 6);
	Student::Student():Person()
	{
		school = "";
	}

private:
	string school;

	~Student(void);
};

#include "Student.h"

Student::Student(void)
{
}

Student::~Student(void)
{
}

#pragma once
#include "Student.h"

class Student_Worker :
	public Student, public Worker
{
public:
	Student_Worker(void);
	Student_Worker(string 1, string 2);
	Student_Worker::Student_Worker():Worker()
	{};
		
	~Student_Worker(void);
};

#include "Student_Worker.h"

Student_Worker::Student_Worker(void)
{
}

Student_Worker::~Student_Worker(void)
{
}

#include "Person.h"
#include<iostream>
#include<string>
using namespace std;

void main()
{
	Person* t[5];
	t[0]= new Person;
	t[1]=new Person;
	t[2]=new Worker;
	t[3]=new Worker;
	t[4]=new Student_Worker;

	for(int i=0; i<5; i++)
	{
		t[i]->print();
		delete t[i];
	}
}
closed account (S6k9GNh0)
Could you post the errors? I'm too lazy to figure it out by myself.
im getting alot of undeclared identifier errors. sorry all i would ask my prof but she doesn't speak english too good. lol

Evidently, you don't speak english too "well" either. But that's beside the point. I noticed that you are dynamically allocating a Worker and Student_Worker class. I don't see a #include "Worker.h" or #include "Student_Worker.h". Your main function has dependencies on those classes and therefore your main.cpp will also have to include the header files where those classes are declared.
1
2
3
4
5
6
7
8
9
10
11
12
class Student_Worker :
	public Student, public Worker
{
public:
	Student_Worker(void);
	Student_Worker(string 1, string 2);
	//Student_Worker::Student_Worker():Worker()
	//{}; this doesn't belong here, and the default constructors will be used by default, so you
 // don't even need to define a default constructor.
		
	~Student_Worker(void);
};


and if you want the print of the corresponding class to be used, you must declare it virtual.
Last edited on
closed account (S6k9GNh0)
You guys work too hard :$
Topic archived. No new replies allowed.