Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the program in Q 1 to use overloaded operators operator and operator rather than read ( ) and write ( ) functions. Implement these

Modify the program in Q1 to use overloaded operators operator and operator rather than read() and write() functions. Implement these operators for all the classes and modify the main program accordingly. The program input/output remains unchanged.
The program in Q1 is modified to store the workforce records (of various employee types) in a vector using the following main program.
(a) Use the declaration and implementation of classes from Q1 and run the program using the followig main, and the input values from Q1. Does the program work properly?
(b) Make the necessary changes to the classes (not main) to make the program generate the desired output.
Main Program Using Classes EmployeeTypes
File: testemployeetypes. epp
Application program using elasses employeetypes
Programimer: your name
Date:
#include "employeetypes. hm
int main (void)
{
char type; // employee type
ofstream fout ("employeetypesout.tt?;
employee ptr :
vector (:=1'
q1code
/ #include employeetypes.h
int main(void)
{
char type;
ofstream fout( employeetypesout.txt );
while (true){
cout endl Type of employee(enter l for laboUrer, m for manager, q to quit) : ;
cin >> type;
if(type == q ) break;
if(type == l ){
labourer lab;
lab.read(cin);
cout endl;
lab.write(cout);
fout endl;
lab.write(fout);
} else if(type ==m){
manager man;
man.read(cin);
cout endl;
man.write(cout);
fout endl;
man.write(fout);
}
}
fout.close();
return 0;
}
#pragma once
#ifndef EMPLOYEETYPES_H
#define EMPLOYEETYPES_H
#include
#include
#include
using namespace std;
class Date {
private:
int day;
int month;
int year;
public:
Date() : day(0), month(0), year(0){}
Date(int d, int m, int y) : day(d), month(m), year(y){}
void read(){
cout "Enter start date (dd mm yyyy): ";
cin >> day >> month >> year;
}
void write() const {
cout "Start date: " day "/" month "/" year endl;
}
};
class Employee {
protected:
string name;
int id;
float salary;
Date start;
public:
Employee() : name(""), id(0), salary(0.0){}
void read(){
cout "Enter employee name: ";
cin >> name;
cout "Enter employee ID: ";
cin >> id;
cout "Enter employee salary: ";
cin >> salary;
start.read();
}
void write() const {
cout "Name: " name endl;
cout "ID: " id endl;
cout "Salary: " salary endl;
start.write();
}
};
class Labourer : public Employee {
private:
string dept;
public:
Labourer() : dept(""){}
void read(){
Employee::read();
cout "Enter department: ";
cin >> dept;
}
void write() const {
Employee::write();
cout "Department: " dept endl;
}
};
class Manager : public Employee {
private:
string title;
public:
Manager() : title(""){}
void read(){
Employee::read();
cout "Enter title: ";
cin >> title;
}
void write() const {
Employee::write();
cout "Title: " title endl;
}
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions

Question

Then why bother to ask for the writing?

Answered: 1 week ago

Question

apply the regulations governing overtime pay

Answered: 1 week ago