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
|
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
class name {
protected:
char *first, *last;
public:
name() {};
name(char *f, char *l): first (f), last (l){}
virtual void info(){
name:info();
}
void Print (void)
{ setw(30);
cout << "The first name is" << first << endl;
cout << "The last name is" << last << endl;}
};
class person : public name {
char gender;
int ssn;
public:
person() {};
person(char *f, char *l, char g, int s): gender(g), ssn(s), name::name(f, l) {}
virtual void info() { // formatted display of the information
name:info();
}
void Print (void) {
setw(30);
cout << "The gender is" << gender << endl;
cout << "The social security number is" << ssn<< endl;
}
};
class employee : public person {
protected:
int payroll;
char *position;
public:
employee() {};
employee(char *f, char *l, char g, int s, int p, char *pos): payroll(p), position (pos), person::person(f,l,g,s) {}
void info() {
employee:info();
}
void Print (void) {
setw(30);
cout << "The payroll is" << payroll << endl;
cout << "The position is" << position << endl;
}
};
int main()
{
char fn[20], ln[20], pos[20];
char gen;
int s, pay;
name *worker;
for (int i=0; i<3; i++) {
cout << "Input the first name: " << endl;
cin >> fn;
cout << "Input the last name: " << endl;
cin >> ln;
cout << "Input the gender: " << endl;
cin >> gen;
cout << "Input the social security number: " << endl;
cin >> s;
cout << "Input the payroll: " << endl;
cin >> pay;
cout << "Input the position: " << endl;
cin >> pos;
worker = new employee(fn, ln, gen, s, pay, pos);
worker->info();
}
system("pause");
return 0;
}
|