hello all
i don't know what is the problem with this code
when i choose a p for prof ........all the objects be prof objects
and when i choose s for student all objects be student objects
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
class person
{
protected:
int id;
string name;
public:
person() : id(0), name("")
{
}
virtual void GetData()
{
cout << "ID:";
cin >> id;
cout << "Name:";
cin >> name;
}
virtual void ShowData()
{
cout << "ID:" << id << "\nName" << name;
}
};
class prof : public person
{
protected:
int students;
int years;
public:
prof()
{
person();
students = 0;
years = 0;
}
void GetData()
{
person::GetData();
cout << "\nStudents No.:";
cin >> students;
cout << "\nYears No.:";
cin >> years;
}
void ShowData()
{
person::ShowData();
cout << "\nStudents No.:" << students << "\nYears No.:" << years;
}
};
class student : public person
{
protected:
int AVGGrade;
int year;
public:
student()
{
person();
AVGGrade = 1;
year = 1;
}
void GetData()
{
person::GetData();
cout << "\nStudent Grade.:";
cin >> AVGGrade;
cout << "\nYear No.:";
cin >> year;
}
void ShowData()
{
person::ShowData();
cout << "\nStudent AVGG.:" << AVGGrade << "\nYear No.:" << year;
}
};
int main(int argc, char* argv[])
{
vector<person*> arr;
person *ptr;
char c;
do
{
cin >> c;
if (c == 'e')
break;
switch (c)
{
case 'p':
ptr = new prof;
arr.push_back(ptr);
(arr.front())->GetData();
break;
case 's':
ptr = new student;
arr.push_back(ptr);
(arr.front())->GetData();
}
}
while (true);
for (int i = 0; i < arr.size();i++)
arr[i]->ShowData();
return 0;
}