Expand|Select|Wrap|Line Numbers
- #include <iostream>
- #include <ctype.h>
- using namespace std;
- class Person
- {
- private:
- char fname[10];
- char lname[10];
- char gender;
- int age;
- int ssn;
- public:
- Person();
- ~Person(){}
- void getinfo();
- };
- Person::Person()
- {
- int i;
- for (i=0;i<10;++i)
- {
- fname[i]=0;
- lname[i]=0;
- }
- gender=0;
- age=0;
- ssn=0;
- }
- void Person::getinfo()
- {
- cout<<"Enter the first name of your person: "<<endl;
- cin>>fname;
- cout<<"Enter the last name of your person: "<<endl;
- cin>>lname;
- cout<<"Enter the gender of your person: "<<endl;
- cin>>gender;
- gender=toupper(gender);
- cout<<"Enter the age of your person: "<<endl;
- cin>>age;
- cout<<"Enter the social security number of your person: "<<endl;
- cin>>ssn;
- }
- class Student:public Person
- {
- private:
- float GPA;
- char major[40];
- int hours;
- char school[40];
- public:
- Student();
- ~Student(){};
- void getinfo();
- };
- Student::Student()
- {
- int i;
- for (i=0;i<40;++i)
- {
- major[i]=0;
- school[i]=0;
- }
- GPA=0.0;
- hours=0;
- }
- void Student::getinfo()
- {
- Person::getinfo();
- cout<<"Enter the GPA of the student: "<<endl;
- cin>>GPA;
- cout<<"Enter the hours completed by the student: "<<endl;
- cin>>hours;
- cout<<"Enter the major of the student: "<<endl;
- cin>>major;
- cout<<"Enter the school the student attends: "<<endl;
- cin>>school;
- }
- class Worker:public Person
- {
- private:
- char occupation[20];
- char company[20];
- float salary;
- public:
- Worker();
- ~Worker(){};
- void getinfo();
- };
- Worker::Worker()
- {
- int i;
- for (i=0;i<20;++i)
- {
- occupation[i]=0;
- company[i]=0;
- }
- salary=0.0;
- }
- void Worker::getinfo()
- {
- Person::getinfo();
- cout<<"Enter the occupation of the worker: "<<endl;
- cin>>occupation;
- cout<<"Enter the company: "<<endl;
- cin>>company;
- cout<<"Enter the salary of the worker: "<<endl;
- cin>>salary;
- }
- class Student_Worker:public Worker,public Student
- {
- private:
- char slip[10];
- public:
- Student_Worker();
- ~Student_Worker(){};
- void getinfo();
- };
- Student_Worker::Student_Worker()
- {
- int i;
- for (i=0;i<10;++i)
- {
- slip[i]=0;
- }
- }
- void Student_Worker::getinfo()
- {
- Student::getinfo();
- Worker:: getinfo();
- }
- void main()
- {
- Person P;
- Student S;
- Worker W;
- Student_Worker SW;
- // P.getinfo();
- // S.getinfo();
- // W.getinfo();
- SW.getinfo();
- }
J