
Concept explainers
Program Plan:
We will implement the BasePlusCommissionEmp class using composition instead of inheritance and invoke different functions in the test program subsequently.
Explanation of Solution
Explanation:
Program Description:
The program demonstrates composition as an alternate way of implementing functionality in Object oriented
Program:
// BasePlusCommissionEmp class definition .
#ifndef BP_COMMISSION_H
#define BP_COMMISSION_H
#include<string>// C++ standard string class
usingnamespace std;
classBasePlusCommissionEmp
{
public:
BasePlusCommissionEmp(conststring&, conststring&, conststring&,
double = 0.0,double = 0.0, double = 0.0 );
//For generic attributes of Employee
voidsetFirstName( conststring& ); // set first name
stringgetFirstName() const; // return first name
voidsetLastName( conststring& ); // set last name
stringgetLastName() const; // return last name
voidsetSocialSecurityNumber( conststring& ); // set SSN
stringgetSocialSecurityNumber() const; // return SSN
// additional functions for attributes of CommisionEmployee
voidsetGrossSales( double ); // set gross sales amount
doublegetGrossSales() const; // return gross sales amount
voidsetCommissionRate( double ); // set commission rate
doublegetCommissionRate() const; // return commission rate
//additional functions for baseSalary
voidsetBaseSalary( double ); // set base salary
doublegetBaseSalary() const; // return base salary
// Generic functions of Employee
doubleearnings() const;
voidprint() const;
private:
//Generic attributes of Employee
stringfirstName; // composition: member object
stringlastName; // composition: member object
stringsocialSecurityNumber; //composition: member object
//attributes of CommisionEmployee
doublegrossSales; // gross weekly sales
doublecommissionRate; // commission percentage
//attribute for BaseSalary
doublebaseSalary; // base salary
}; // end class BasePlusCommissionEmp
#endif
BasePlusCommisionEmp.cpp
/* BasePlusCommissionEmp.cpp using composition Created on: 31-Jul-2018 :rajesh@acroknacks.com */
#include<string>// C++ standard string class
#include"BasePlusCommissionEmp.h"
#include<iostream>
usingnamespace std;
BasePlusCommissionEmp::BasePlusCommissionEmp(conststring&fname, conststring&lname, conststring&ssn1,
doublebaseSalary, doublegrossSales , doublecomRate )
:firstName (fname), lastName ( lname),socialSecurityNumber (ssn1 )
{
setBaseSalary(baseSalary ); // validate and store base salary
setGrossSales(grossSales);//validate and store gross sales
setCommissionRate(comRate);//validate and store commision rate
}// end constructor
/&Functions Below are specific to This class */
// set gross sales amount
voidBasePlusCommissionEmp::setGrossSales( double sales )
{
if ( sales **gt;= 0.0 )
grossSales = sales;
else
throwinvalid_argument( "Gross sales must be >= 0.0" );
} // end function setGrossSales
// return gross sales amount
doubleBasePlusCommissionEmp::getGrossSales() const
{
returngrossSales;
} // end function getGrossSales
// set commission rate
voidBasePlusCommissionEmp::setCommissionRate( double rate )
{
if ( rate > 0.0 && rate < 1.0 )
commissionRate = rate;
else
throwinvalid_argument( "Commission rate must be > 0.0 and < 1.0" );
} // end function setCommissionRate
doubleBasePlusCommissionEmp::getCommissionRate() const
{
returncommissionRate;
} // end function getCommissionRate
voidBasePlusCommissionEmp::setBaseSalary( double salary )
{
if ( salary >= 0.0 )
baseSalary = salary;
else
throwinvalid_argument( "Salary must be >= 0.0" );
} // end function setBaseSalary
// return base salary
doubleBasePlusCommissionEmp::getBaseSalary() const
{
returnbaseSalary;
} // end function getBaseSalary
//compute earnings
doubleBasePlusCommissionEmp::earnings() const
{
return ( (getCommissionRate() * getGrossSales()) + getBaseSalary()) ;
} // end function earnings
// print CommissionEmployee object
voidBasePlusCommissionEmp::print() const
{
cout<<"\nBasePlusCommission employee: ";
cout<<lastName<<", "<<firstName<<endl;
cout<<"SSN : "<<socialSecurityNumber<<endl;
cout<<"\n gross sales: $ "<<getGrossSales()
<<"\n Base Salary: $ "<<getBaseSalary()
<<"\n commission rate: "<<getCommissionRate() ;
} // end function print
/&Generic Employee functions **/
// set first name
voidBasePlusCommissionEmp::setFirstName( conststring**first )
{
firstName = first; // should validate
} // end function setFirstName
// return first name
stringBasePlusCommissionEmp::getFirstName() const
{
returnfirstName;
} // end function getFirstName
// set last name
voidBasePlusCommissionEmp::setLastName( conststring&last )
{
lastName = last; // should validate
} // end function setLastName
// return last name
stringBasePlusCommissionEmp::getLastName() const
{
returnlastName;
} // end function getLastName
// set social security number
voidBasePlusCommissionEmp::setSocialSecurityNumber( conststring&ssn )
{
socialSecurityNumber = ssn; // should validate
} // end function setSocialSecurityNumber
// return social security number
stringBasePlusCommissionEmp::getSocialSecurityNumber() const
{
returnsocialSecurityNumber;
} // end function getSocialSecurityNumber
Test Program
// Testing class BasePlusCommissionEmp.
#include<iostream>
#include<iomanip>
#include"BasePlusCommissionEmp.h"// BasePlusCommissionEmp class definition
usingnamespace std;
intmain()
{
// instantiate a BasePlusCommissionEmp object
BasePlusCommissionEmpemployee("Sue", "Jones", "222-22-2222",1500,10000,0.16 );
// get commission employee data
cout<<"Employee information obtained by get functions: \n"
<<"\nFirst name is "<<employee.getFirstName()
<<"\nLast name is "<<employee.getLastName()
<<"\nSocial security number is "
<<employee.getSocialSecurityNumber()
<<"\nBase Salary is $"<<employee.getBaseSalary()
<<"\nGross sales is $"<<employee.getGrossSales()
<<"\nCommission rate is $"<<employee.getCommissionRate() <<endl;
cout<<"Earnings based on current Data : $"<<employee.earnings();
//Modify Sales data
employee.setGrossSales( 8000 ); // set gross sales
employee.setCommissionRate( .1 ); // set commission rate
cout<<"\nUpdated employee information output by print function: \n"
<<endl;
employee.print(); // display the new employee information
// display the employee's earnings
cout<<"\n\n Updated Employee's earnings: $"<<employee.earnings() <<endl;
} // end main
Employee information obtained by get functions:
First name is Sue
Last name is Jones
Social security number is 222-22-2222
Base Salary is $1500
Gross sales is $10000
Commission rate is $0.16
Earnings based on current Data : $3100
Updated employee information output by print function:
BasePlusCommission employee: Jones, Sue
SSN : 222-22-2222
gross sales: $ 8000
Base Salary: $ 1500
commission rate: 0.1
Updated Employee's earnings: $2300
Want to see more full solutions like this?
Chapter 11 Solutions
C++ How to Program (Early Objects Version)
- Don't use chatgpt or any other AIarrow_forwardGiven a relation schema R = (A, B, C, D, E,G) with a set of functional dependencies F {ABCD BC → DE B→ D D→ A}. (a) Show that R is not in BCNF using the functional dependency A → BCD. (b) Show that AG is a superkey for R (c) Compute a canonical cover Fc for the set of functional dependencies F. Show your work. (d) Give a 3NF decomposition of R based on the canonical cover found in (c). Show your work. (e) Give a BCNF decomposition of R using F. Show your work.arrow_forwardThe following entity-relationship (ER) diagram models a database that helps car deal- ers maintain records of customers and cars in their inventory. Construct a relational database schema from the ER diagram. Your set of schemas should include primary-key and foreign-key constraints and you should ensure there are no redundant schemas. has_model model modelID name vehicle has_vehicle VIN dealer_ID brand name has_available_option has_option has_dealer options options_ID specification dealer dealer ID name customer_ID owned_by customer customer ID namearrow_forward
- A relation schema R = (A, B, C, D, E) with a set of functional dependencies F= {D A CAB} is decomposed into R₁ = (A, B, C) and R2 = (C, D, E). (a) Is this a lossless-join decomposition? Why or why not? (b) Is the decomposition dependency preserving? Why or why not?arrow_forwardNo chatgpt pleasearrow_forwardPlease help draw alu diagraarrow_forward
- 1. Level the resources (R) for the following network. Show exactly which activity is being moved at each cycle and how many days it is being moved. Show all cycles required to utilize the free float and the back float. B H 3 3 L 2 0-0-0 A C F G K N P Q T 0 3 2 2 1 2-2-2 7R 8R 4R 6R 4R 2R 5R 4R D 1 2R 2 M 000 4R 2 4R 1 2 3 4 B5 B BE B 5 5 7 D 2003 C NO C MBSCM В H 5 2 F 7 7 8 SH2F80 5 Н Н 6 7 7L3G4+ 6H2G4 J 4 4 14 8 L K 00 36 9 10 11 12 13 14 15 P 2 Z+ N N 4 4 Z t 2334 4 Σ + M M 4 +arrow_forward2. Perform resource allocation for the following project. Resource limits are 6 labors and 2 helpers. Legend: Activity Dur Resources G H 2 3 2L 1H 2L OH A 1 3L 1H + B D F J K 3 4 6 2 4 4L 2H 3L OH 4L 1H 2L 2H 4L 2H C E 2 2 I 1 2L 1H 3L 1H 5L 1Harrow_forwardNeed Java method please. Thank you.arrow_forward
- Need Java method please. Thank you.arrow_forward3. Write two nested loops to generate the following output. (Note: There is one space between each number, and any extra line shown is intentional.) 12 10 8 6 18 15 12 24 20 30 2 3 3 6 48 12 5 10 15 20 6 12 18 24 30arrow_forwardWrite in verilog coding languagearrow_forward
Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
Systems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning




