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).
#include<iostream>
#include<string>
using namespace std;
enum Identification
{Idstudent=0, Idworker=1, Idstudentworker=2};
class person
{
public:
int id_name;
void output (string _name, string _address, string _birthdate, char _gender);
person(){};
string name;
string address;
string birthdate;
char gender;
Identification id;
void input();
Identification getid() {return id;}
string getname() {return name;}
string getaddress() {return address;}
string getbirthdate() {return birthdate;}
char getgender() {return gender;}
Identification getid() const {return id;}
int getid_name() {return id_name;}
};
void person::output (string _name, string _address, string _birthdate, char _gender)
{
cout<< " name “<<_name<<” address “<<_address<<” birthdate “<<_birthdate<<” gender “<<_gender<<endl;
}
void person::input()
{
cout<< " enter the name, address, birthdate, gender " <<endl;
cin>>name>>address>>birthdate>>gender;
cout<< " what are they doing?? if student enter 0, if worker enter 1, if both enter 2 " <<endl;
cin>>id_name;
}
class student:public person{};
class worker:public person{};
class studentworker:public person{};
void main()
{
int allchoice;
char genderchoice;
int b[3];
char c[3];
int choice;
enum Identification id;
person abc[3];
for (int i=0; i<3; i++)
{
abc.input();
}
for (int i=0; i<3; i++)
{
abc.output (abc.getname(), abc.getaddress(), abc.getbirthdate(), abc.getgender());
}
cout<< " Do you want to search from gender or ID? “<<endl;
cout<< " gender enter '1' “<<endl;
cout<< " id enter '2' “<<endl;
cin>>allchoice;
if(allchoice==1)
{
cout<< " pls enter the group that you want to search. “<<endl;
cin>>genderchoice;
for (int i=0; i<3; i++)
{
c=abc.getgender();
if(c==genderchoice)
{
abc.output (abc.getname(), abc.getaddress(), abc.getbirthdate(), abc.getgender());
}
}
}
else
{
cout<< " pls enter the group that you want to search.if student enter 0, if worker enter 1, if both enter 2 " <<endl;
cin>>choice;
for (int i=0; i<3; i++)
{
b=abc.getid_name();
if(b==choice)
{
abc.output (abc.getname(), abc.getaddress(), abc.getbirthdate(), abc.getgender());
}
}
}
}