Workshop 7 Task 1: Employee Design and code a class named Employee that holds in
ID: 3623361 • Letter: W
Question
Workshop 7 Task 1: Employee Design and code a class named Employee that holds information for an employee. Upon instantiation, an Employee object may receive an integer identifying the employee and a double holding the employee's salary. If the object does not receive any data, or receives invalid data, the object adopts a safe empty state. Your Employee class includes the following member function: void display () const Displays the employee number followed by the salary in (NNNN) - SSSSSSSSSS format, where NNNN denotes the employee's number and SSSSSSSSSS denotes the employee's salary. Displaye the employee number in a field of 4 and the salary in a field of 10 to 2 decimal places. bool valid () const Returns true if the object holds valid data, false otherwise. Your Employee class is supported by an extraction operator. For the purpose of this workshop, you may assume that the user will input the data correctly. Task 2: Manager Derive a class named Manager from Employee that holds information for a manager. Upon instantiation, a Manager object may receive an integer identifying he number of employees for which the manager is responsible, an integer identifying the manager's employee number and a double holding the manager's salary. If the object does not receive any data or receives invalid data, the object adopts a safe empty state. Your Manager class includes the following member function: void display() const Display the employee information for the object followed by the number of employees for which the manager is responsible in (NNNN) - SSSSSSSSS - (RRR) format, where NNNN - SSSSSSSSSS denotes employee information and RRR denotes the number of employees. Bool valid() const Returns true if the object holds valid data, false otherwise. Your Manager class is supported by an extraction operator. For the purpose of this workshop, you may assume that the user will input the data correctly. Note: The main program that uses your class is The output from your program looks something like:Explanation / Answer
#include <stdio.h>
#define EMPTY_STATE -1
class Employee{
//Data members
int number;
double salary;
public:
//Constructor using default values
Employee(int num = EMPTY_STATE, double sal = EMPYT_STATE){number = num; salary = sal;}
void display(){
//formatting in printf takes care of precision
printf("Employee No. : %i Salary : %f.2 " , number,salary);
}
bool valid(){
//returns true ONLY if BOTH number and salary have been defined
return number != EMPTY_STATE && salary != EMPTY_STATE;
}
}
class Manager{
//Data Members
int number,employees;
double salary;
//Constructor
Manager(int num = EMPTY_STATE, int emp = EMPTY_STATE, double sal = EMPTY_STATE){
number = num;
employees = emp;
salary = sal;
}
void display(){
printf("Employee No. : %i Salary : %f.2 Subordinates : %n" , number,salary,employees);
}
bood valid(){
//returns true ONLY if all fields have been defined
return number != EMPTY_STATE && salary != EMPTY_STATE && employees != EMPTY_STATE;
}
}
Although the lab says to derive the manager class from the Employee class, I did not use inheritance becauser there is not really a point. You could easily change this if you wanted to, google c++ and inheritance if thats what you're into.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.