Object Oriented Design

Exercise 6

Inheritance and Output Formatting

Please finish the implementation of class name and derived classes person and employee in the following code. Format the output neatly using setw() and or other setioflags features (Module 13).

#include <iostream>

#include <fstream>

using namespace std;

class name {

protected:

char

*

first,

*

last;

public:

name() {};

name(char

*

f, char

*

l)

{...}

virtual void info(){// formatted display of the information

}

1

};

class person : public name {

char gender;

int ssn;

public:

};

person() {};

person(char

*

f, char

name::name(f, l) {}

*

l, char g, int s): gender(g), ssn(s),

virtual void info() { // formatted display of the information

name::info();

...

}

class employee : public person {

protected:

int payroll;

char

*

position;

public:

employee() {};

employee(char

}

...

*

f, char

*

l, char g, int s, int p, char

void info() { // formatted display of the information

...

}

*

pos) {

};

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;

The output would look like the following:

2 Submission Instructions

Package source file and output screen captures into < YOUR

NETID > exer6:zip and upload it online using Assignments menu.

 

 

    • 10 years ago
    A+ Work
    NOT RATED

    Purchase the answer to view it

    blurred-text
    • attachment
      q611q.zip