C++11 for Programmers by Paul J. Deitel & Harvey M. Deitel
Author:Paul J. Deitel & Harvey M. Deitel [Deitel, Paul J. & Deitel, Harvey M.]
Language: eng
Format: epub
Tags: Computer Science, Education & Reference, Computers & Technology, Programming Languages, C#, Languages & Tools, Programming, C
ISBN: 9780133439854
Publisher: Prentice Hall
Published: 2013-03-22T14:00:00+00:00
* * *
Fig. 12.13. CommissionEmployee class header.
Click here to view code image
* * *
1 // Fig. 12.14: CommissionEmployee.cpp
2 // CommissionEmployee class member-function definitions.
3 #include <iostream>
4 #include <stdexcept>
5 #include "CommissionEmployee.h" // CommissionEmployee class definition
6 using namespace std;
7
8 // constructor
9 CommissionEmployee::CommissionEmployee( const string &first,
10 const string &last, const string &ssn, double sales, double rate )
11 : Employee( first, last, ssn )
12 {
13 setGrossSales( sales );
14 setCommissionRate( rate );
15 } // end CommissionEmployee constructor
16
17 // set gross sales amount
18 void CommissionEmployee::setGrossSales( double sales )
19 {
20 if ( sales >= 0.0 )
21 grossSales = sales;
22 else
23 throw invalid_argument( "Gross sales must be >= 0.0" );
24 } // end function setGrossSales
25
26 // return gross sales amount
27 double CommissionEmployee::getGrossSales() const
28 {
29 return grossSales;
30 } // end function getGrossSales
31
32 // set commission rate
33 void CommissionEmployee::setCommissionRate( double rate )
34 {
35 if ( rate > 0.0 && rate < 1.0 )
36 commissionRate = rate;
37 else
38 throw invalid_argument( "Commission rate must be > 0.0 and < 1.0" );
39 } // end function setCommissionRate
40
41 // return commission rate
42 double CommissionEmployee::getCommissionRate() const
43 {
44 return commissionRate;
45 } // end function getCommissionRate
46
47 // calculate earnings; override pure virtual function earnings in Employee
48 double CommissionEmployee::earnings() const
49 {
50 return getCommissionRate() * getGrossSales();
51 } // end function earnings
52
53 // print CommissionEmployee's information
54 void CommissionEmployee::print() const
55 {
56 cout << "commission employee: ";
57 Employee::print(); // code reuse
58 cout << "\ngross sales: " << getGrossSales()
59 << "; commission rate: " << getCommissionRate();
60 } // end function print
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Coding Theory | Localization |
Logic | Object-Oriented Design |
Performance Optimization | Quality Control |
Reengineering | Robohelp |
Software Development | Software Reuse |
Structured Design | Testing |
Tools | UML |
Deep Learning with Python by François Chollet(12585)
Hello! Python by Anthony Briggs(9924)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9799)
The Mikado Method by Ola Ellnestam Daniel Brolund(9783)
Dependency Injection in .NET by Mark Seemann(9347)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8308)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7770)
Grails in Action by Glen Smith Peter Ledbrook(7703)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7564)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(7134)
Microservices with Go by Alexander Shuiskov(6896)
Practical Design Patterns for Java Developers by Miroslav Wengner(6813)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6755)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6422)
Angular Projects - Third Edition by Aristeidis Bampakos(6171)
The Art of Crafting User Stories by The Art of Crafting User Stories(5695)
NetSuite for Consultants - Second Edition by Peter Ries(5624)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5437)
Kotlin in Action by Dmitry Jemerov(5071)
