مرحباً بك.
يمكن تنفيذ المطلوب بالكود الآتي:
#include <iostream>
#include <cstring>
using namespace std;
struct PersonType {
char name[30];
char gender;
int age;
};
struct StudentType {
PersonType person;
int student_id;
char facutly_name[20];
int level;
};
struct EmployeeType {
PersonType person;
char company_name[20];
double salary;
};
class Person{
public:
char name[30];
char gender;
int age;
void setdata(){
cout << "Name: ";
cin >> name;
cout << "Gender: ";
cin >> gender;
cout << "Age: ";
cin >> age;
}
PersonType getdata(){
PersonType data;
strcpy(data.name, name);
data.age = age;
data.gender = gender;
return data;
}
void display(){
cout << "Name: " << name << endl;
cout << "Gender: " << gender << endl;
cout << "Age: " << age << endl;
}
};
class Student: public Person{
public:
int student_id;
char facutly_name[20];
int level;
void setdata(){
Person::setdata();
cout << "Student ID: ";
cin >> student_id;
cout << "Faculty Name: ";
cin >> facutly_name;
cout << "Level: ";
cin >> level;
}
StudentType getdata(){
StudentType data;
data.person = Person::getdata();
data.student_id = student_id;
strcpy(data.facutly_name, facutly_name);
data.level = level;
return data;
}
void display(){
Person::display();
cout << "Student ID: " << student_id << endl;
cout << "Faculty Name: " << facutly_name << endl;
cout << "Level: " << level << endl;
}
};
class Employee:Person{
public:
char company_name[20];
double salary;
void setdata(){
Person::setdata();
cout << "Company Name: ";
cin >> company_name;
cout << "Salary: ";
cin >> salary;
}
EmployeeType getdata(){
EmployeeType data;
data.person = Person::getdata();
strcpy(data.company_name, company_name);
data.salary = salary;
return data;
}
void display(){
Person::display();
cout << "Company Name: " << company_name << endl;
cout << "Salary: " << salary << endl;
}
};
int main(){
Person person;
Student student;
Employee employee;
cout << "#Person: " << endl;
person.setdata();
cout << "#Student: " << endl;
student.setdata();
cout << "#Employee: " << endl;
employee.setdata();
person.display();
student.display();
employee.display();
return 0;
}