Docsity

C++ Programming Assignment: Inheritance, Constructors, and Destructors, Lab Reports of Computer Science

Toggle sidebar
bg1
Page 1 of 2
CS 1410 Programming Assignment #7
Inheritance, Constructors, and Destructors
Assignment
Write a C++ program consisting of the four related classes presented in the UML diagram below.
Complete the program with the provided driver program (no modification required).
1. Each class is small and relatively simple, so it is feasible to create each class, including
all function definitions, in its own header file: employee.h, salariedemployee.h,
wagedemployee.h, and salesemployee.h.
2. Make all member variables (i.e., attributes) private.
3. Make all member functions (i.e., behaviors, operations, or services) public.
4. Initialize all member variables via constructor calls.
5. Define each class in a separate .h file (remember the #ifndef and #endif preprocessor
statements - they are necessary in this program)
+Employee(in n : string)
+operator<<(in out : ostream&, in e : Employee&) : ostream&
-name : string
Employee
+SalariedEmployee(in name : string, in s : double)
+operator<<(in out : ostream&, in e : SalariedEmployee&) : ostream&
-salary : double
SalariedEmployee
+WagedEmployee(in name : string, in w : double, in h : double)
+operator<<(in out : ostream&, in e : WagedEmployee&) : ostream&
-wage : double
-hours : double
WagedEmployee
+SalesEmployee(in name : string, in sal : double, in com : double, in totsales : double)
+operator<<(in out : ostream&, in e : SalesEmployee&) : ostream&
-commission : double
-sales : double
SalesEmployee
pf2

Partial preview of the text

Download C++ Programming Assignment: Inheritance, Constructors, and Destructors and more Lab Reports Computer Science in PDF only on Docsity!

Page 1 of 2

CS 1410 Programming Assignment

Inheritance, Constructors, and Destructors

Assignment

Write a C++ program consisting of the four related classes presented in the UML diagram below. Complete the program with the provided driver program (no modification required).

  1. Each class is small and relatively simple, so it is feasible to create each class, including all function definitions, in its own header file: employee.h, salariedemployee.h, wagedemployee.h, and salesemployee.h.
  2. Make all member variables (i.e., attributes) private.
  3. Make all member functions (i.e., behaviors, operations, or services) public.
  4. Initialize all member variables via constructor calls.
  5. Define each class in a separate .h file (remember the #ifndef and #endif preprocessor statements - they are necessary in this program)

+Employee(in n : string) +operator<<(in out : ostream&, in e : Employee&) : ostream&

-name : string

Employee

+SalariedEmployee(in name : string, in s : double) +operator<<(in out : ostream&, in e : SalariedEmployee&) : ostream&

-salary : double

SalariedEmployee

+WagedEmployee(in name : string, in w : double, in h : double) +operator<<(in out : ostream&, in e : WagedEmployee&) : ostream&

-wage : double -hours : double

WagedEmployee

+SalesEmployee(in name : string, in sal : double, in com : double, in totsales : double) +operator<<(in out : ostream&, in e : SalesEmployee&) : ostream&

-commission : double -sales : double

SalesEmployee

Page 2 of 2

  1. The SalesEmployee constructor a. should retain (i.e., initialize the corresponding local variables) the commission (c) and the sales (s) b. should call the SalariedEmployee constructor and pass to it the name, and salary (sa)
  2. The SalariedEmployee constructor a. should retain (i.e., initialize the corresponding local variable) the salary (s) b. should call the Employee constructor and pass to it the name
  3. The WagedEmployee constructor a. should retain (i.e., initialize the corresponding local variables) the wage (w) and hours (h) b. should call the Employee constructor and pass to it the name
  4. The Employee constructor a. should initialize the name variable
  5. The SalesEmployee operator<< a. should call the SalariedEmployee operator<< to print the salary b. should print the commission and sales
  6. The SalariedEmployee operator<< a. should call the Employee operator<< to print the name b. should print the salary
  7. The WagedEmployee operator<< a. should call the Employee operator<< to print the name b. should print the wage and hours
  8. The Employee operator<< a. should print the name

Program Submission

  • Upload the four files (employee.h, salariedemployee.h, wagedemployee.h, and salesemployee.h) to WSU Online (make a new directory and upload the files to that directory)
  • Please do not zip the files
  • Retain a copy of your code for use in the next two assignments.