Commit 28563ab4 authored by O'Reilly Media, Inc.'s avatar O'Reilly Media, Inc.
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading

README.md

0 → 100644
+15 −0
Changes for README.md: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
## Example files for the title:  
  
# Advanced C++ Programming, by Mike McMillan
  
[![Advanced C++ Programming, by Mike McMillan](http://akamaicovers.oreilly.com/images/9781771370110/cat.gif)](https://www.safaribooksonline.com/library/view/title/9781771370110//)
  
The following applies to example files from material published by O’Reilly Media, Inc. Content from other publishers may include different rules of usage. Please refer to any additional usage rights explained in the actual example files or refer to the publisher’s website.
  
O'Reilly books are here to help you get your job done. In general, you may use the code in O'Reilly books in your programs and documentation. You do not need to contact us for permission unless you're reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from our books does not require permission. Answering a question by citing our books and quoting example code does not require permission. On the other hand, selling or distributing a CD-ROM of examples from O'Reilly books does require permission. Incorporating a significant amount of example code from our books into your product's documentation does require permission.
  
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN.
  
If you think your use of code examples falls outside fair use or the permission given here, feel free to contact us at <permissions@oreilly.com>.
  
Please note that the examples are not production code and have not been carefully testing. They are provided "as-is" and come with no warranty of any kind.
+50 −0
Changes for Working Files/Chapter 01/Chap0102.cpp: 50 added lines, 0 removed lines.
Original line number Diff line number Diff line
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

class Employee {
    private:
        string name;
        double pay;
    public:
        Employee() {
            name = "";
            pay = 0;
        }

        Employee(string empName, double payRate) {
            name = empName;
            pay = payRate;
        }

        string getName() const {
            return name;
        }

        void setName(string empName) {
            name = empName;
        }

        int getPay() {
            return pay;
        }

        void setPay(int payRate) {
            pay = payRate;
        }

        string toString() {
            stringstream stm;
            stm << name << ": " << pay;
            return stm.str();
        }
};
int main()
{
    Employee emp1;
    emp1.setName("Jane Doe");
    cout << emp1.getName();
    return 0;
}
+74 −0
Changes for Working Files/Chapter 01/Chap0103.cpp: 74 added lines, 0 removed lines.
Original line number Diff line number Diff line
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

// base class
class Employee {
    private:
        string name;
        double pay;
    public:
        Employee() {
            name = "";
            pay = 0;
        }

        Employee(string empName, double payRate) {
            name = empName;
            pay = payRate;
        }

        string getName() const {
            return name;
        }

        void setName(string empName) {
            name = empName;
        }

        int getPay() {
            return pay;
        }

        void setPay(int payRate) {
            pay = payRate;
        }

        string toString() {
            stringstream stm;
            stm << name << ": " << pay;
            return stm.str();
        }
};

// derived class

class Manager : public Employee {
    private:
       bool salaried;

    public:
       Manager(string name, double payRate, bool isSalaried)
           : Employee(name, payRate)
        {
            salaried = isSalaried;
        }

        bool getSalaried() {
            return salaried;
        }
};

int main()
{
    Employee emp1("Mary Smith", 15.00);
    cout << "Employee name; " << emp1.getName() << endl;
    cout << "Employee pay rate: " << emp1.getPay() << endl;
    Manager emp2("Bob Brown", 1500, true);
    cout << "Employee name; " << emp2.getName() << endl;
    cout << "Employee pay rate: " << emp2.getPay() << endl;
    cout << "Emp2 Salaried? " << emp2.getSalaried() << endl;
    return 0;
}
+84 −0
Changes for Working Files/Chapter 01/Chap0104.cpp: 84 added lines, 0 removed lines.
Original line number Diff line number Diff line
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

// base class
class Employee {
    protected:
        string name;
        double pay;
    public:
        Employee() {
            name = "";
            pay = 0;
        }

        Employee(string empName, double payRate) {
            name = empName;
            pay = payRate;
        }

        string getName() const {
            return name;
        }

        void setName(string empName) {
            name = empName;
        }

        int getPay() {
            return pay;
        }

        void setPay(int payRate) {
            pay = payRate;
        }

        string toString() {
            stringstream stm;
            stm << name << ": " << pay;
            return stm.str();
        }

        double grossPay(int hours) {
            return pay * hours;
        }
};

// derived class

class Manager : public Employee {
    private:
       bool salaried;

    public:
       Manager(string name, double payRate, bool isSalaried)
           : Employee(name, payRate)
        {
            salaried = isSalaried;
        }

        bool getSalaried() {
            return salaried;
        }

        double grossPay() {
            return pay;
        }
};

int main()
{
    Employee emp1("Mary Smith", 15.00);
    cout << "Employee name; " << emp1.getName() << endl;
    cout << "Employee pay rate: " << emp1.getPay() << endl;
    cout << "Employee gross pay: " << emp1.grossPay(40) << endl;
    Manager emp2("Bob Brown", 1500, true);
    cout << "Employee name; " << emp2.getName() << endl;
    cout << "Employee pay rate: " << emp2.getPay() << endl;
    cout << "Emp2 Salaried? " << emp2.getSalaried() << endl;
    cout << "Emp2 gross pay: " << emp2.grossPay() << endl;
    return 0;
}
+100 −0
Changes for Working Files/Chapter 01/Chap0105.cpp: 100 added lines, 0 removed lines.
Original line number Diff line number Diff line
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

// base class
class Employee {
    protected:
        string name;
        double pay;
    public:
        Employee() {
            name = "";
            pay = 0;
        }

        Employee(string empName, double payRate) {
            name = empName;
            pay = payRate;
        }

        string getName() const {
            return name;
        }

        void setName(string empName) {
            name = empName;
        }

        int getPay() {
            return pay;
        }

        void setPay(int payRate) {
            pay = payRate;
        }

        string toString() {
            stringstream stm;
            stm << name << ": " << pay;
            return stm.str();
        }

        double grossPay(int hours) {
            return pay * hours;
        }
};

// derived class

class Manager : public Employee {
    private:
       bool salaried;

    public:
       Manager(string name, double payRate, bool isSalaried)
           : Employee(name, payRate)
        {
            salaried = isSalaried;
        }

        bool getSalaried() {
            return salaried;
        }

        double grossPay(int hours) {
            if (salaried) {
                return pay;
            } else {
                return pay * hours;
            }
        }

        string toString() {
            stringstream stm;
            string salary;
            if (salaried) {
                salary = "Salaried";
            } else {
                salary = "Hourly";
            }
            stm << name << ": " << pay
                << ": " << salary << endl;
            return stm.str();
        }
};

int main()
{
    Employee emp1("Mary Smith", 15.00);
    cout << "Employee name; " << emp1.getName() << endl;
    cout << "Employee pay rate: " << emp1.getPay() << endl;
    cout << "Employee gross pay: " << emp1.grossPay(40) << endl;
    Manager emp2("Bob Brown", 1500, true);

    cout << emp2.toString();
    cout << "emp2's gross pay: " << emp2.grossPay(100);
    return 0;
}
Loading