Data Structures

Computing

Quiz 14 :

Trees

Quiz 14 :

Trees

Question Type
search
arrow
In an ordered list, all operations that modify the list are designed to ensure that the elements remain in ascending order. Build and test an OrderedList class template derived from class List that exhibits this characteristic.
Free
Essay
Answer:

Answer:

Problem Plan:
OrderedList.h:
• "List.h" is referred from book chapter 6
o Declare the class "orderedList"
• Declare the function "sort()" for sorting the elements in ascending order
• Declare the function "erase()" to delete the elements
• Declare the function "display()" to display the output
o Definition of "sort()"
• Create an object for list class
• Loop till "i" is less than size
o Loop till "j" is less than "size-1-i"
• check if "arr[j] " is greater than "arr[j+1]"
• Declare the variable "temp" and assign "arr[j]"
• assign "arr[j+] "' to "arr[j] "
• Assign "temp" to "arr[j+1] "
• Loop till "j" is less than size
o call the function "insert()"
• Print the sorted list
o Definition of "erase()"
• Call the "erase()" function from the "list.h"
o Definition of "display()"
• Call the "display()" function from the "list.h"
o Definition of output operator
• Call the "display()" function from the "list.h"
• Return the value stored in "out"
Main.cpp:
• Define "main()" function
o Create the object for "OrderedList"
o Declare the array
o Get the elements form the user to sort the list
• Call the "sort()" to sort the list
• Print the list
o Get the position from the user to delete the element from the list
• Call the "erase" to delete element from the list
• Print the list after deleting the element
Program:
/ **********************************************************
*Program to implement all operations in the ordered list * *and to ensure that all the elements remain in the * *ascending order *
********************************************************** /
OrderedList.h:
/ / Include the required header files
#pragma once
#include
/ / List.h is referred from book
#include"List.h"
using namespace std;
/ / Declare the class 'OrderedList' which inherits the list class
class OrderedList :List
{
public:
/ / Declare the function 'sort()' for sorting the / / elements in ascending order
       void sort(ElementType arr[], int size);
/ / Declare the function 'erase()' to delete the / / elements
       virtual void erase(int pos);
/ / Declare the function 'display()' to display the / / output
       virtual void display(ostream out) const;
public:
/ / Declare the variable 's' as integer and assign 0 to it
       int s = 0;
};
/ / Definiton of sort()
inline void OrderedList::sort(ElementType arr[], int size)
{
       / / Create an object for list class
       List l;
/ / Declare the variable 'a' as integer and assign / / size to it
       int a = size;
/ / Loop till 'i' is less than size
       for (int i = 0; i
              / / Loop till 'j' is less than 'size-1-i'
              for (int j = 0; j size - i - 1; ++j)
/ / Check if 'arr[j]' is greater than arr[j+1]
                     if (arr[j] arr[j + 1])
                     {
/ / Declare the variable 'temp' and assign 'arr[j]'
                           int temp = arr[j];
                           / / assign 'arr[j+1]' to  'arr[j]'
                           arr[j] = arr[j + 1];
                           / / Assign 'temp' to 'arr[j+1]'
                           arr[j + 1] = temp;
                     }
       / / Loop till 'j' is less than size
       for (int j = 0;j size;j++)
              / / call the function 'insert()'
              OrderedList::insert(arr[j], j);
       / / Print the sorted list
       cout l;
}
/ / Definition of erase()
void OrderedList::erase(int pos)
{
       / / Call the function erase()
       List::erase(pos);
}
/ / Definition of display()
void OrderedList::display(ostream out) const
{
       / / Call the function display()
       List::display(cout);
}
/ / Definition of output operator
ostream operator (ostream out, const OrderedList aList)
{
       / / Call the function display()
       aList.display(out);
       return out;
}
#endif
Main.cpp:
/ / Include the required header files
#include
#include "OrderedList.h"
using namespace std;
/ / Definition of main
int main()
{
       / / Create an object for orderedList
       OrderedList intList;
       cout "Constructing intList\n";
       / / Declare the array 'a' of size 100
       int a[100];
       / / Declare the variable 'pos' as integer
       int pos;
       / / Declare the variable 'i' as integer
       int i = 0;
       / / For infinite loop
       for (;;)
       {
              / / Get the elements from the user
              cout "Enter the elements(-1 stop)";
              cin a[i];
              / / Check if 'a[i]' equals to -1
              if (a[i] == -1) break;
              / / increment 'i'
              i++;
       }
       / / Call the sort()
       intList.sort(a, i);
       / / Print the sorted list
       cout intList;
       cout "\n";
/ / Get the position from the user to delete the item
       cout "Enter the position to be deleted";
       cin pos;
       / / Call the function 'erase()' to delete the element
       intList.erase(pos);
       / / print the list after deleting the element
       cout intList;
       / / Pause the screen
       system("pause");
}
Sample Output:
Constructing intList
Enter the elements(-1 stop)5
Enter the elements(-1 stop)7
Enter the elements(-1 stop)3
Enter the elements(-1 stop)8
Enter the elements(-1 stop)2
Enter the elements(-1 stop)1
Enter the elements(-1 stop)-1
1  2  3  5  7  8
Enter the position to be deleted1
1  3  5  7  8

Tags
Choose question tag
close menu
arrow
Write a complete payroll program for a company in which each employee falls into one of the five categories described in the text and in Exercises 1-3-salaried, hourly, administrative, factory, or salesperson.
Free
Essay
Answer:

Answer:

Problem Plan:
Administrator.h
• 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 "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
FactoryEmployee.h
• 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
Salesperson.h
• 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 "Salesperson" 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
Main.cpp
• Includes required header files
• Define "main()" function
o Get Employee id, first name, last name, initial and department from the user
o Get Employee Type
o If user input is 1
• Get salary from user
• Create the object for SalariedEmployee class with parameterized constructor
• Print the object
o If user input is 2
• Get Weekly wages, number of hours worked and overtime factor from user
• Create the object for HourlyEmployee class with parameterized constructor
• Print the object
o If user input is 3
• Get salary and bonus from user
• Create the object for Administrator class with parameterized constructor
• Print the object
o If user input is 4
• Get unit pay and number of units from user
• Create the object for FactoryEmployee class with parameterized constructor
• Print the object
o If user input is 5
• Get salary and commission from user
• Create the object for Salesperson class with parameterized constructor
• Print the object
o Continue the process until the user enter 'n' or 'N'
Program:
/ **********************************************************
* Program for payroll management system *
********************************************************** /
Administrator.h:
/ / Including required header files
#include
/ * Include "SalariedEmployee.h" which is referred from book at 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 'display()' function
virtual void display(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 'display()' for display 'administ' object * /
inline void Administrator::display(ostream out) const
{
/ * Call the SalariedEmployee's member function 'display()' * /
SalariedEmployee::display(out);
out "Bonus: $" my_bonus endl;
}
#endif
FactoryEmployee.h:
/ / Include required header files
#include
/ * Include 'Employee.h' which is referred from 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
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 'Employee.h' which is referred from book at page no : 805 * /
#include "Employee.h"
/ * Include 'HourlyEmployee.h' which is referred from book at page no : 808 * /
#include "HourlyEmployee.h"
/ * Include "SalariedEmployee.h" which is referred from book at page no : 806 * /
#include "SalariedEmployee.h"
#include "Salesperson.h"
#include "Administrator.h"
#include "FactoryWorker.h"
/ / Definition of 'main()'
int main()
{
/ / Variable declaration
long emp_id;
string fname, lname;
char init;
int dept,n_units;
int type;
double salary =0.0,w_wages,hours,ot,unit_pay,comision,bonus;
char ch;
cout "\nPayroll";
do
{
/ * Get employee id, first name, last name, initial, department from user input * /
cout "\nEnter Employee id :";
cin emp_id;
cout "\nEnter Employee First name :";
cin fname;
cout "\nEnter Employee Last name :";
cin lname;
cout "\nEnter Employee initial :";
cin init;
cout "\nEnter Employee department :";
cin dept;
/ / Get employee type
cout "\n1.Salaried Employee";
cout "\n2.Hourly Employee";
cout "\n3.Administrative";
cout "\n4.FactoryEmployee";
cout "\n5.Salesperson";
cout "\nSelect Employee Type :";
cin type;
/ / check user input is 1
if (type == 1)
{
/ / Get salary from user
cout "\nEnter salary :";
cin salary;
/ * Create the object for SalariedEmployee class with parameterized constructor * /
SalariedEmployee salaried(emp_id, fname, lname, init, dept, salary);
cout "\nSalaried Employee Details\n";
/ / Print the object
cout salaried endl;
}
else if (type == 2)
{
/ / Get weekly wages from user
cout "\nEnter Weelly Wages :";
cin w_wages;
/ / Get number of hours worked from user
cout "\nEnter No of hours worked :";
cin hours;
/ / Get overtime factor from user
cout "\nEnter OverTime Factor :";
cin ot;
/ * Create the object for HourlyEmployee class with parameterized constructor * /
HourlyEmployee hourly_emp(emp_id, fname, lname, init, dept, w_wages, hours, ot);
cout "\Hourly Employee Details\n";
/ / Print the object
cout hourly_emp endl;
}
else if (type == 3)
{
/ / Get salary from user
cout "\nEnter salary :";
cin salary;
/ / Get bonus from user
cout "\nEnter bonus :";
cin bonus;
/ * Create the object for Administrator class with parameterized constructor * /
Administrator admin(emp_id, fname, lname, init, dept, salary, bonus);
/ / Print the object
cout "\Administrator Details\n";
cout admin endl;
}
else if (type == 4)
{
/ / Get unit_pay from user
cout "\nEnter unit_pay :";
cin unit_pay;
/ / Get number of units from user
cout "\nEnter number of units :";
cin n_units;
/ * Create the object for FactoryEmployee class with parameterized constructor * /
FactoryEmployee fact_emp(emp_id, fname, lname, init, dept, unit_pay, n_units);
/ / Print the object
cout "\Factory Employee Details\n";
cout fact_emp endl;
}
else if (type == 5)
{
/ / Get salary from user
cout "\nEnter salary :";
cin salary;
/ / Get commission from user
cout "\nEnter comminssion :";
cin comision;
/ * Create the object for Salesperson class with parameterized constructor * /
Salesperson sales(emp_id, fname, lname, init, dept, salary, comision);
/ / Print the object
cout "\SalesPerson Details\n";
cout sales endl;
}
else
cout "Invalid option";
/ / Get continue or not
cout "Do u want to continue (y=yes,n=no)";
cin ch;
/ / Check continue or not
} while (ch!='n' ch !='N');
/ / Pause screen
system("pause");
}
Sample Output:
Payroll
Enter Employee id :111
Enter Employee First name :zenith
Enter Employee Last name :victor
Enter Employee initial :v
Enter Employee department :5
1.Salaried Employee
2.Hourly Employee
3.Administrative
4.FactoryEmployee
5.Salesperson
Select Employee Type :3
Enter salary :23444
Enter bonus :3450
Administrator Details
111 zenith, victor v 5
$23444
Bonus: $3450
Do u want to continue (y=yes,n=no)y
Enter Employee id :112
Enter Employee First name :riya
Enter Employee Last name :mary
Enter Employee initial :g
Enter Employee department :3
1.salaried Employee
2.hourly Employee
3.Administrative
4.FactoryEmployee
5.salesperson
Select Employee Type :5
Enter salary :20300
Enter comminssion :345
SalesPerson Details
112 riya, mary g 3
$20300
Commision: $345
Do u want to continue (y=yes,n=no)n

Tags
Choose question tag
close menu
arrow
Write a program that processes a heterogeneous list of the five different kinds of employees in Problem 4. Instead of the simple creation of list elements in the driver program in Figure 14.6, use other list operations to input the list, output the list, add to the list, remove from the list, search the list, and sort the list so that id-numbers are in ascending order.
Free
Essay
Answer:

Answer:

Problem Plan:
Administrator.h:
• 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 "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
FactoryEmployee.h:
• 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
Salesperson.h:
• 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 "Salesperson" 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
Main.cpp:
• Includes required header files
• Create a structure named "employ"
o Declare the variables "emp_id", "fname", "lname", "init", "dept", "n_units", "type", "salary", "w_wages", "hours", "ot", "unit_pay", "comision", "bonus".
• Define "main()" function
o Create the struct object
o Get option for Employee details and display
o If user input is 1
• Get Employee id, first name, last name, initial and department from the user
• Get Employee Type
• If user input is 1
• Get salary from user
• Create the object for SalariedEmployee class with parameterized constructor
• Print the object
• If user input is 2
• Get Weekly wages, number of hours worked and overtime factor from user
• Create the object for HourlyEmployee class with parameterized constructor
• Print the object
• If user input is 3
• Get salary and bonus from user
• Create the object for Administrator class with parameterized constructor
• Print the object
• If user input is 4
• Get unit pay and number of units from user
• Create the object for FactoryEmployee class with parameterized constructor
• Print the object
• If user input is 5
• Get salary and commission from user
• Create the object for Salesperson class with parameterized constructor
• Print the object
o If the user input is 2
• Get Employee id from the user
• If the user input is 1
• Remove the employee details from the list
• If the user input is 2

Remove the employee details from the list
• If the user input is 3
• Remove the employee details from the list
• If the user input is 4
• Remove the employee details from the list
• If the user input is 5
• Remove the employee details from the list
o If the user input is 3
• Get Employee id from the user
• If the user input is 1
• Display the first employee details
• If the user input is 2
• Display the second employee details
• If the user input is 3
• Display the third employee details
• If the user input is 4
• Display the fourth employee details
• If the user input is 5
• Display the fifth employee details
o If user input is 4
• Get Employee type to display
• If user input is 1
• Print SalariedEmployee details
• If user input is 2
• Print HourlyEmployee details
• If user input is 3
• Print Administrator details
• If user input is 4
• Print FactoryEmployee details
• If user input is 5
• Print Salesperson details
o If the user input is 5
• Sort the employee list according to the employee id
o Continue the process until the user enter 'n' or 'N'
Program:
/ **********************************************************
* Program for payroll management system *
********************************************************** /
Administrator.h:
/ / Including required header files
#include
/ * Include "SalariedEmployee.h" which is referred from book at 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 'display()' function
virtual void display(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 'display()' for display 'administ' object * /
inline void Administrator::display(ostream out) const
{
/ * Call the SalariedEmployee's member function 'display()' * /
SalariedEmployee::display(out);
out "Bonus: $" my_bonus endl;
}
#endif
FactoryEmployee.h:
/ / Include required header files
#include
/ * Include 'Employee.h' which is referred from 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
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
#include
#include
using namespace std;
/ * Include 'Employee.h' which is referred from book at page no : 805 * /
#include "Employee.h"
/ * Include 'HourlyEmployee.h' which is referred from book at page no : 808 * /
#include "HourlyEmployee.h"
/ * Include "SalariedEmployee.h" which is referred from book at page no : 806 * /
#include "SalariedEmployee.h"
#include "Salesperson.h"
#include "Administrator.h"
#include "FactoryEmployee.h"
#define SIZE 10
/ / struct is created with name "employ"
struct employ
{
/ / declaration of variable "emp_id" in long
long emp_id;
/ * declaration of variable "fname" and "lname" in string * /
string fname, lname;
/ / declaration of variable "init" in character
char init;
/ * declaration of variable "dept" and "n_units" in integer * /
int dept, n_units;
/ / declaration of variable "type" in integer
int type;
/ * declaration of variable "salary", "w_wages", "hours", "ot", "unit_pay", "comision" and "bonus" in double * /
double salary = 0.0, w_wages, hours, ot, unit_pay, comision, bonus;
};
/ / Definition of 'main()'
int main()
{
/ / object is created
employ ch[SIZE];
int t1 = 0;
int t2 = 0;
int t3 = 0;
int t4 = 0;
int t5 = 0;
/ / declaration of variable "choice" in character
char choice;
/ / declaration of variable "i" in integer data type
int i = 0;
/ / print statement in output screen
cout "\nPayroll";
/ / declaration of variable "c" in integer data type
int c;
/ * while loop condition to execute the following operations * /
while (1)
{
/ / print statement in output screen
cout "\n1.Add Employee";
cout "\n2.Remove Employee";
cout "\n3.Search ";
cout "\n4.Display";
cout "\n5.Sort";
cout "\n6.Exit";
cout "\nEnter your choice";
/ / gets the input "c" from user
cin c;
/ / switch case condition
switch (c)
{
case 1:
/ / print statement in output screen
cout "\nEnter Employee id :";
/ / get the employee id from the user
cin ch[i].emp_id;
/ / print statement in output screen
cout "\nEnter Employee First name :";
/ / get the first name from the user
cin ch[i].fname;
/ / print statement in output screen
cout "\nEnter Employee Last name :";
/ / get the last name from the user
cin ch[i].lname;
/ / print statement in output screen
cout "\nEnter Employee initial :";
/ * get the employee initial from the user * /
cin ch[i].init;
/ / print statement in output screen
cout "\nEnter Employee department :";
/ / get the department from the user
cin ch[i].dept;
/ / Get employee type
cout "\n1.Salaried Employee";
cout "\n2.Hourly Employee";
cout "\n3.Administrative";
cout "\n4.FactoryEmployee";
cout "\n5.Salesperson";
cout "\nSelect Employee Type :";
cin ch[i].type;
/ / check user input is 1
if (ch[i].type == 1)
{
/ / Get salary from user
cout "\nEnter salary :";
cin ch[i].salary;
/ * Create the object for SalariedEmployee class with parameterized constructor * /
SalariedEmployee salaried(ch[i].emp_id, ch[i].fname, ch[i].lname, ch[i].init, ch[i].dept, ch[i].salary);
cout "\nSalaried Employee Details\n";
/ / Print the object
cout salaried endl;
t1 = t1 + 1;
}
/ / check whether user type is 2
else if (ch[i].type == 2)
{
/ / Get weekly wages from user
cout "\nEnter Weelly Wages :";
cin ch[i].w_wages;
/ * Get number of hours worked from user * /
cout "\nEnter No of hours worked :";
cin ch[i].hours;
/ / Get overtime factor from user
cout "\nEnter OverTime Factor :";
cin ch[i].ot;
/ * Create the object for HourlyEmployee class with parameterized constructor * /
HourlyEmployee hemployee(ch[i].emp_id, ch[i].fname, ch[i].lname, ch[i].init, ch[i].dept, ch[i].w_wages, ch[i].hours, ch[i].ot);
cout "\Hourly Employee Details\n";
t2 = t2 + 1;
/ / Print the object
cout hemployee endl;
}
/ / check whether user type is 3
else if (ch[i].type == 3)
{
/ / Get salary from user
cout "\nEnter salary :";
cin ch[i].salary;
/ / Get bonus from user
cout "\nEnter bonus :";
cin ch[i].bonus;
/ * Create the object for Administrator class with parameterized constructor * /
Administrator admin(ch[i].emp_id, ch[i].fname, ch[i].lname, ch[i].init, ch[i].dept, ch[i].salary, ch[i].bonus);
t3 = t3 + 1;
/ / Print the object
cout "\Administrator Details\n";
cout admin endl;
}
/ / check whether user type is 4
else if (ch[i].type == 4)
{
/ / Get unit_pay from user
cout "\nEnter unit_pay :";
cin ch[i].unit_pay;
/ / Get number of units from user
cout "\nEnter number of units :";
cin ch[i].n_units;
/ * Create the object for FactoryEmployee class with parameterized constructor * /
FactoryEmployee factemp(ch[i].emp_id, ch[i].fname, ch[i].lname, ch[i].init, ch[i].dept, ch[i].unit_pay, ch[i].n_units);
t4 = t4 + 1;
/ / Print the object
cout "\Factory Employee Details\n";
cout factemp endl;
}
/ / check whether user type is 5
else if (ch[i].type == 5)
{
/ / Get salary from user
cout "\nEnter salary :";
cin ch[i].salary;
/ / Get commission from user
cout "\nEnter comminssion :";
cin ch[i].comision;
/ * Create the object for Salesperson class with parameterized constructor * /
Salesperson sales(ch[i].emp_id, ch[i].fname, ch[i].lname, ch[i].init, ch[i].dept, ch[i].salary, ch[i].comision);
t5 = t5 + 1;
/ / Print the object
cout "\SalesPerson Details\n";
cout sales endl;
}
/ / otherwise
else
cout "Invalid option";
/ / Get continue or not
cout "Do u want to continue (y=yes,n=no)";
cin choice;
i++;
/ / Check continue or not
break;
case 2:
/ / declare "id" as a long data type
long id;
/ / get the employee id from the user
cout "Enter employee Id";
cin id;
/ / check for the condition
for (int j = 0;j i;j++)
/ / check for the condition
if(ch[j].emp_id==id)
/ / check for the condition
for (int k = j;k = i;k++)
{
/ * check for the condition if the "type" is 1 remove the first employee details * /
if (ch[k].type == 1)
{
ch[k].emp_id = ch[k + 1].emp_id;
ch[k].fname = ch[k + 1].fname;
ch[k].lname = ch[k + 1].lname;
ch[k].init = ch[k + 1].init;
ch[k].dept = ch[k + 1].dept;
ch[k].salary = ch[k + 1].salary;
i = i - 1-t2-t3-t4-t5;
break;
}
/ / check for the condition if the "type" is 2 remove the second employee details
else if (ch[k].type == 2)
{
ch[k].emp_id = ch[k + 1].emp_id;
ch[k].fname = ch[k + 1].fname;
ch[k].lname = ch[k + 1].lname;
ch[k].init = ch[k + 1].init;
ch[k].dept = ch[k + 1].dept;
ch[k].w_wages = ch[k + 1].w_wages;
ch[k].hours = ch[k + 1].hours;
ch[k].ot = ch[k + 1].hours;
i = i - 1 - t1 - t3 - t4 - t5;
break;
}
/ * check for the condition if the "type" is 3 remove the third employee details * /
else if (ch[k].type == 3)
{
ch[k].emp_id = ch[k + 1].emp_id;
ch[k].fname = ch[k + 1].fname;
ch[k].lname = ch[k + 1].lname;
ch[k].init = ch[k + 1].init;
ch[k].dept = ch[k + 1].dept;
ch[k].salary = ch[k + 1].salary;
i = i - 1 - t1 - t2 - t4 - t5;
break;
}
/ * check for the condition if the "type" is 4 remove the fourth employee details * /
else if (ch[k].type == 4)
{
ch[k].emp_id = ch[k + 1].emp_id;
ch[k].fname = ch[k + 1].fname;
ch[k].lname = ch[k + 1].lname;
ch[k].init = ch[k + 1].init;
ch[k].dept = ch[k + 1].dept;
ch[k].unit_pay = ch[k + 1].unit_pay;
ch[k].n_units = ch[k + 1].n_units;
i = i - 1 - t1 - t2 - t3 - t5;
break;
}
/ * check for the condition if the "type" is 5 remove the fifth employee details * /
else if (ch[k].type == 5)
{
ch[k].emp_id = ch[k + 1].emp_id;
ch[k].fname = ch[k + 1].fname;
ch[k].lname = ch[k + 1].lname;
ch[k].init = ch[k + 1].init;
ch[k].dept = ch[k + 1].dept;
ch[k].salary = ch[k + 1].salary;
ch[k].comision = ch[k + 1].comision;
i = i - 1 - t1 - t2 - t3 - t4;
break;
}
}
break;
case 3:
/ / declare "eid" as a long data type
long eid;
/ / get the employee id from the user
cout "Enter employee Id";
cin eid;
/ / check for the condition
for (int j = 0;j i;j++)
/ / check for the condition
if (ch[j].emp_id == eid)
{
/ * check for the condition if the "type" is 1 display the first employee details * /
if (ch[j].type == 1)
{
cout ch[j].emp_id ' ' ch[j].lname ", "
ch[j].fname ' ' ch[j].init " "
ch[j].dept " " ch[j].salary endl;
}
/ * check for the condition if the "type" is 2 display the second employee details * /
else if (ch[j].type == 2)
{
cout ch[j].emp_id ' ' ch[j].lname ", "
ch[j].fname ' ' ch[j].init " "
ch[j].dept " " ch[j].w_wages " " ch[j].hours " " ch[j].ot endl;
}
/ * check for the condition if the "type" is 3 display the third employee details * /
else if (ch[j].type == 3)
{
cout ch[j].emp_id ' ' ch[j].lname ", "
ch[j].fname ' ' ch[j].init " " ch[j].dept " "
ch[j].salary " " ch[j].bonus endl;
}
/ * check for the condition if the "type" is 4 display the fourth employee details * /
else if (ch[j].type == 4)
{
cout ch[j].emp_id ' ' ch[j].lname ", "
ch[j].fname ' ' ch[j].init " "
ch[j].dept " " ch[i].unit_pay " " ch[i].n_units endl;
}
/ * check for the condition if the "type" is 5 display the fifth employee details * /
else if (ch[j].type == 5)
{
cout ch[j].emp_id ' ' ch[j].lname ", "
ch[j].fname ' ' ch[j].init " "
ch[j].dept " " ch[i].salary " " ch[i].comision endl;
}
}
break;
case 4:
/ * declaration of variable "t" with integer data type * /
int t;
/ / Display menu option
cout "\n1.Salaried Employee";
cout "\n2.Hourly Employee";
cout "\n3.Administrative";
cout "\n4.FactoryEmployee";
cout "\n5.Salesperson";
/ / Get employee type
cout "\nEnter Type of Employee";
cin t;
/ / Check employee type
switch (t)
{
/ / Process when employee type is 1
case 1:
/ / Print the Salaried Employee Details
for (int j = 0;j i;j++)
/ * check for the condition if the "type" is 1 display the first employee details * /
if (ch[j].type == 1)
{
cout ch[j].emp_id ' ' ch[j].lname ", "
ch[j].fname ' ' ch[j].init " "
ch[j].dept " " ch[j].salary endl;
}
break;
/ / Process when employee type is 2
case 2:
/ / Print the Hourly Employee Details
for (int j = 0;j i;j++)
/ * check for the condition if the "type" is 2 display the second employee details * /
if (ch[j].type == 2)
{
cout ch[j].emp_id ' ' ch[j].lname ", "
ch[j].fname ' ' ch[j].init " "
ch[j].dept " " ch[j].w_wages " " ch[j].hours " " ch[j].ot endl;
}
break;
/ / Process when employee type is 3
case 3:
/ / Print the Administrative Details
for (int j = 0;j i;j++)
/ * check for the condition if the "type" is 3 display the third employee details * /
if (ch[j].type == 3)
{
cout ch[j].emp_id ' ' ch[j].lname ", "
ch[j].fname ' ' ch[j].init " " ch[j].dept " "
ch[j].salary " " ch[j].bonus endl;
}
break;
/ / Process when employee type is 4
case 4:
/ / Print the Factory Employee Details
for (int j = 0;j i;j++)
/ * check for the condition if the "type" is 4 display the fourth employee details * /
if (ch[j].type == 4)
{
cout ch[j].emp_id ' ' ch[j].lname ", "
ch[j].fname ' ' ch[j].init " "
ch[j].dept " " ch[i].unit_pay " " ch[i].n_units endl;
}
break;
/ / Process when employee type is 1
case 5:
/ / Print the SalesPerson Details
for (int j = 0;j i;j++)
if (ch[j].type == 4)
{
cout ch[j].emp_id ' ' ch[j].lname ", "
ch[j].fname ' ' ch[j].init " "
ch[j].dept " " ch[i].salary " " ch[i].comision endl;
}
break;
/ / Default block
default:
break;
}
break;
case 5:
/ / check for the condition
for (int k = 0; k i; ++k)
/ / check for the condition
for (int j = 0; j i - k - 1; ++j)
/ / check for the condition
if (ch[j].emp_id ch[j + 1].emp_id)
{
/ / swap the employee id
employ temp = ch[j];
ch[j] = ch[j + 1];
ch[j + 1] = temp;
}
break;
default:
exit(0);
}
}
/ / Pause screen
system("pause");
}
Sample Output:
Payroll
1.Add Employee
2.Remove Employee
3.Search
4.Display
5.Sort
6.Exit
Enter your choice1
Enter Employee id :5
Enter Employee First name :zenith
Enter Employee Last name :victor
Enter Employee initial :V
Enter Employee department :1
1.Salaried Employee
2.Hourly Employee
3.Administrative
4.FactoryEmployee
5.Salesperson
Select Employee Type :1
Enter salary :20000
Salaried Employee Details
5 zenith, victor V 1
$20000
Do u want to continue (y=yes,n=no)y
1.Add Employee
2.Remove Employee
3.Search
4.Display
5.Sort
6.Exit
Enter your choice1
Enter Employee id :10
Enter Employee First name :kavi
Enter Employee Last name :raja
Enter Employee initial :R
Enter Employee department :2
1.Salaried Employee
2.Hourly Employee
3.Administrative
4.FactoryEmployee
5.Salesperson
Select Employee Type :3
Enter salary :30000
Enter bonus :1000
Administrator Details
10 kavi, raja R 2
$30000
Bonus: $1000
Do u want to continue (y=yes,n=no)y
1.Add Employee
2.Remove Employee
3.Search
4.Display
5.Sort
6.Exit
Enter your choice1
Enter Employee id :2
Enter Employee First name :keerthi
Enter Employee Last name :prabu
Enter Employee initial :P
Enter Employee department :15
1.Salaried Employee
2.Hourly Employee
3.Administrative
4.FactoryEmployee
5.Salesperson
Select Employee Type :1
Enter salary :10000
Salaried Employee Details
2 keerthi, prabu P 15
$10000
Do u want to continue (y=yes,n=no)y
1.Add Employee
2.Remove Employee
3.Search
4.Display
5.Sort
6.Exit
Enter your choice4
1.Salaried Employee
2.Hourly Employee
3.Administrative
4.FactoryEmployee
5.Salesperson
Enter Type of Employee1
5 victor, zenith V 1 20000
2 prabu, keerthi P 15 10000
1.Add Employee
2.Remove Employee
3.Search
4.Display
5.Sort
6.Exit
Enter your choice4
1.Salaried Employee
2.Hourly Employee
3.Administrative
4.FactoryEmployee
5.Salesperson
Enter Type of Employee3
10 raja, kavi R 2 30000 1000
1.Add Employee
2.Remove Employee
3.Search
4.Display
5.Sort
6.Exit
Enter your choice5
1.Add Employee
2.Remove Employee
3.Search
4.Display
5.Sort
6.Exit
Enter your choice4
1.Salaried Employee
2.Hourly Employee
3.Administrative
4.FactoryEmployee
5.Salesperson
Enter Type of Employee1
2 prabu, keerthi P 15 10000
5 victor, zenith V 1 20000
1.Add Employee
2.Remove Employee
3.Search
4.Display
5.Sort
6.Exit
Enter your choice3
Enter employee Id2
2 prabu, keerthi P 15 10000
1.Add Employee
2.Remove Employee
3.Search
4.Display
5.Sort
6.Exit
Enter your choice2
Enter employee Id2
1.Add Employee
2.Remove Employee
3.Search
4.Display
5.Sort
6.Exit
Enter your choice4
1.Salaried Employee
2.Hourly Employee
3.Administrative
4.FactoryEmployee
5.Salesperson
Enter Type of Employee1
5 victor, zenith V 1 20000
1.Add Employee
2.Remove Employee
3.Search
4.Display
5.Sort
6.Exit
Enter your choice6

Tags
Choose question tag
close menu
arrow
Write a driver program to test the Administrator class from Exercise 1.
Essay
Answer:
Tags
Choose question tag
close menu
arrow
For Exercises 3-18, determine which of the following best describes the relationship between the given objects: is-a , has-a, uses-a , none of the preceding. Professors and employees at Universal University
Essay
Answer:
Tags
Choose question tag
close menu
arrow
For Exercises 3-18, determine which of the following best describes the relationship between the given objects: is-a , has-a, uses-a , none of the preceding. Students and the library at Universal University
Essay
Answer:
Tags
Choose question tag
close menu
arrow
For Exercises 3-18, determine which of the following best describes the relationship between the given objects: is-a , has-a, uses-a , none of the preceding. Triangles and rectangles
Essay
Answer:
Tags
Choose question tag
close menu
arrow
For Exercises 3-18, determine which of the following best describes the relationship between the given objects: is-a , has-a, uses-a , none of the preceding. Binary trees and trees
Essay
Answer:
Tags
Choose question tag
close menu
arrow
For Exercises 3-18, determine which of the following best describes the relationship between the given objects: is-a , has-a, uses-a , none of the preceding. Stacks and queues
Essay
Answer:
Tags
Choose question tag
close menu
arrow
Contrast the is-a, has-a , and uses-a relationships between classes.
Essay
Answer:
Tags
Choose question tag
close menu
arrow
Write a driver program to test the SalesPerson class from Exercise 3.
Essay
Answer:
Tags
Choose question tag
close menu
arrow
Write a driver program to test the Document class from Exercise 4.
Essay
Answer:
Tags
Choose question tag
close menu
arrow
Write a driver program to test the FactoryErnployee class from Exercise 2.
Essay
Answer:
Tags
Choose question tag
close menu
arrow
For Exercises 3-18, determine which of the following best describes the relationship between the given objects: is-a , has-a, uses-a , none of the preceding. Squares and rectangles
Essay
Answer:
Tags
Choose question tag
close menu
arrow
For Exercises 3-18, determine which of the following best describes the relationship between the given objects: is-a , has-a, uses-a , none of the preceding. Students at Universal University and GPAs
Essay
Answer:
Tags
Choose question tag
close menu
arrow
For Exercises 3-18, determine which of the following best describes the relationship between the given objects: is-a , has-a, uses-a , none of the preceding. Lines and rectangles
Essay
Answer:
Tags
Choose question tag
close menu
arrow
Write a driver program to test the LookAheadStack class from Exercise 5.
Essay
Answer:
Tags
Choose question tag
close menu
arrow
For Exercises 3-18, determine which of the following best describes the relationship between the given objects: is-a , has-a, uses-a , none of the preceding. Employees and persons at Universal University
Essay
Answer:
Tags
Choose question tag
close menu
arrow
Contrast public, private, and protected inheritance.
Essay
Answer:
Tags
Choose question tag
close menu
arrow
For Exercises 3-18, determine which of the following best describes the relationship between the given objects: is-a , has-a, uses-a , none of the preceding. Stacks and ADTs
Essay
Answer:
Tags
Choose question tag
close menu
Showing 1 - 20 of 31