Quiz 14: Trees

Computing

Problem Plan: • Includes the header file "SalariedEmployee.h" o Declare the constructor for initialize all the variables o Declare the function "Display()" to print the object • Define the inline constructor for initialize the variables • Define the inline function "display()" for print the object • Declare the class "Administrator" that inherit the class "SalariedEmployee" o Declare the constructor for initialize all the variables o Declare the function "Print()" to display the object • Define the inline constructor for initialize the variables and initialize the "SalariedEmployee" variables • Define the inline function "Print()" for display the object • Define the "main()" function o Create the object for "Administrator" class with parameterized constructor o Display the object Program: / ********************************************************** * Program to test the administrator class * ********************************************************** / Administrator.h: / / Including required header files #include / * Include "SalariedEmployee.h" which is referred from book page no: 806 * / #include "SalariedEmployee.h" #ifndef ADMINISTRATOR #define ADMINISTRATOR / / Definition of 'Administrator' class class Administrator : public SalariedEmployee { / / Access specifier public: / / Declaration of constructor Administrator(long admin_id = 0, string admin_last = "", string admin_first = "", char admin_init = ' ', int admin_dept = 0, double admin_salary = 0, double admin_bonus = 0); / / declaration of 'Print()' function virtual void Print(ostream out) const; / / Access specifier private: / / Declaration of variable double my_bonus; }; / * Definition of inline constructor 'Administrator()' for initialize the variables * / inline Administrator::Administrator( long admin_id, string admin_last, string admin_first, char admin_init, int admin_dept, double admin_salary, double admin_bonus) : SalariedEmployee(admin_id, admin_last, admin_first, admin_init, admin_dept, admin_salary), my_bonus(admin_bonus) {} / / Definition of inline function 'Print()' for display 'Administrator' object inline void Administrator::Print(ostream out) const { / * Call the SalariedEmployee's member function 'display()' * / SalariedEmployee::display(out); out "Bonus: $" my_bonus endl; } #endif Main.cpp: / / Including required header files #include using namespace std; #include "Administrator.h" / / Definition of main int main() { cout "Administrator Details"; / * Create the object for 'Administrator' class with parameterized constructor * / Administrator admin(123, "zenith", "victor", 'V', 3, 23499, 3450); / / Print the object cout } Sample Output Administrator Details123 zenith, victor V 3 $23499

Problem Plan: • Includes the header file "Employee.h" o Declare the constructor for initialize all the variables o Declare the function "display()" to print the object • Define the inline constructor for initialize the variables • Define the inline function "display()" for print the object • Declare the class "FactoryEmployee" that inherit the class "Employee" o Declare the constructor for initialize all the variables o Declare the function "display()" to display the object • Define the inline constructor for initialize the variables and initialize the "Employee" variables • Define the inline function "display()" for display the object • Define the "main()" function o Create the object for "FactoryEmployee" class with parameterized constructor o Display the object Program: / ********************************************************** * Program to test the FactoryEmployee class * ********************************************************** / FactoryEmployee.h: / / Include required header files #include / * Include 'Employee.h' which is referred on book at page no : 805 * / #include "Employee.h" #ifndef FACTORYEMPLOYEE #define FACTORYEMPLOYEE / / Definition of class 'FactoryEmployee' class FactoryEmployee : public Employee { / / Access specifier public: / / Declaration of constructor FactoryEmployee(long factory_emp_id = 0, string factory_emp_last = "", string factory_emp_first = "", char factory_emp_initial = ' ', int factory_emp_dept = 0, double unitPay = 0, int no_Units = 0); / / declaration of 'display()' function virtual void display(ostream out) const; / / Access specifier private: / / Declaration of variable double payUnit; int noUnits; double wages; }; / * Definition of inline constructor 'FactoryEmployee()' for initialize the variables * / inline FactoryEmployee::FactoryEmployee( long factory_emp_id, string factory_emp_last, string factory_emp_first, char factory_emp_initial, int factory_emp_dept, double unitPay, int no_Units) : Employee(factory_emp_id, factory_emp_last, factory_emp_first, factory_emp_initial, factory_emp_dept), payUnit(unitPay), noUnits(no_Units) { / / Assign 'wages' is equal to 'payUnit' * 'noUnits' wages = payUnit * noUnits; } / * Definition of inline function 'display()' for display 'FactoryEmployee' object * / inline void FactoryEmployee::display(ostream out) const { / * Call the Employee's inherited member function 'display()' * / Employee::display(out); / / Display result out noUnits " units at $" payUnit " gives wages = $" wages endl; } #endif Main.cpp: / / Include required header files #include using namespace std; #include "FactoryEmployee.h" / / Definition of 'main()' int main() { cout "Factory Employee Details\n\n\n"; / * Create the object for 'FactoryEmployee' class with parameterized constructor * / FactoryEmployee factory_emp(123, "zenith", "victor", 'V', 3, 234, 34); / / Print the object cout factory_emp endl; system("pause"); } Sample Output Factory Employee Details 123 zenith, victor V 3 34 units at $234 gives wages = $7956

Problem Plan: • Includes the header file "SalariedEmployee.h" o Declare the constructor for initialize all the variables o Declare the function "display()" to print the object • Define the inline constructor for initialize the variables • Define the inline function "display()" for print the object • Declare the class "FactoryEmployee" that inherit the class "SalariedEmployee" o Declare the constructor for initialize all the variables o Declare the function "display()" to display the object • Define the inline constructor for initialize the variables and initialize the "SalariedEmployee" variables • Define the inline function "display()" for display the object • Define the "main()" function o Create the object for "Salesperson" class with parameterized constructor o Display the object Program: / ********************************************************** * Program to test the Salesperson class * ********************************************************** / Salesperson.h: / / Include required header files #include / / Include 'SalariedEmployee.h' which is referred from book at page no: 806 #include "SalariedEmployee.h" #ifndef SALES_PERSON #define SALES_PERSON / / Definition of class 'Salesperson class Salesperson : public SalariedEmployee { / / Access specifier public: / / Declaration of constructor Salesperson(long sales_id = 0, string sales_last = "", string sales_first = "", char sales_initial = ' ', int sales_dept = 0, double sales_salary = 0, double sales_commission = 0); / / declaration of 'display()' function virtual void display(ostream out) const; private: / / Declaration of variable double commision; }; / / Definition of inline constructor 'Salesperson()' for initialize the variables inline Salesperson::Salesperson( long sales_id, string sales_last, string sales_first, char sales_initial, int sales_dept, double sales_salary, double sales_commission) : SalariedEmployee(sales_id, sales_last, sales_first, sales_initial, sales_dept, sales_salary), commision(sales_commission) { } / * Definition of inline function 'display()' for display 'Salesperson' object * / inline void Salesperson::display(ostream out) const { / * Call the SaleriedEmployee's inherited member function 'display()' * / SalariedEmployee::display(out); / / Display result out "Commision: $" commision endl; } #endif Main.cpp: / / Include required header files #include using namespace std; #include "Salesperson.h" / / Definition of 'main()' int main() { cout "Sales Person Details\n\n\n"; / * Create the object for 'Salesperson' class with parameterized constructor * / Salesperson sales(123, "zenith", "victor", 'V', 3, 23400,345.6); / / Print the object cout sales endl; } Sample Output Sales Person Details 123 zenith, victor V 3 $23400 Commision: $345.6