├── .clang-format ├── .gitignore ├── Chapter02 ├── examples │ ├── 2.01 │ │ └── fig02_01.cpp │ ├── 2.03 │ │ └── fig02_03.cpp │ ├── 2.04 │ │ └── fig02_04.cpp │ ├── 2.05 │ │ └── fig02_05.cpp │ └── 2.13 │ │ └── fig02_13.cpp └── exercises │ ├── 2.09 │ └── ex_209.cpp │ ├── 2.16 │ └── ex_216.cpp │ ├── 2.17 │ └── ex_217.cpp │ ├── 2.18 │ └── ex_218.cpp │ ├── 2.19 │ └── ex_219.cpp │ ├── 2.20 │ └── ex_220.cpp │ ├── 2.21 │ └── ex_221.cpp │ ├── 2.23 │ └── ex_223.cpp │ ├── 2.24 │ └── ex_224.cpp │ ├── 2.25 │ └── ex_225.cpp │ ├── 2.26 │ └── ex_226.cpp │ ├── 2.27 │ └── ex_227.cpp │ ├── 2.28 │ └── ex_228.cpp │ ├── 2.29 │ └── ex_229.cpp │ ├── 2.30 │ └── ex_230.cpp │ └── 2.31 │ └── ex_231.cpp ├── Chapter03 ├── examples │ ├── 3.01 │ │ └── fig03_01.cpp │ ├── 3.03 │ │ └── fig03_03.cpp │ ├── 3.05 │ │ └── fig03_05.cpp │ ├── 3.07 │ │ └── fig03_07.cpp │ ├── 3.09 │ │ ├── GradeBook.hpp │ │ └── fig03.10.cpp │ ├── 3.11 │ │ ├── GradeBook.cpp │ │ ├── GradeBook.hpp │ │ └── fig03_13.cpp │ └── 3.17 │ │ ├── GradeBook.cpp │ │ ├── GradeBook.hpp │ │ └── fig03_17.cpp └── exercises │ ├── 3.11 │ ├── GradeBook.cpp │ ├── GradeBook.hpp │ └── ex_311.cpp │ ├── 3.12 │ ├── Account.cpp │ ├── Account.hpp │ └── ex_312.cpp │ ├── 3.13 │ ├── Invoice.cpp │ ├── Invoice.hpp │ └── ex_313.cpp │ ├── 3.14 │ ├── Employee.cpp │ ├── Employee.hpp │ └── ex_314.cpp │ ├── 3.15 │ ├── Date.cpp │ ├── Date.hpp │ └── ex_315.cpp │ ├── 3.16 │ ├── HeartRates.cpp │ ├── HeartRates.hpp │ └── ex_316.cpp │ └── 3.17 │ ├── HealthProfile.cpp │ ├── HealthProfile.hpp │ └── ex_317.cpp ├── Chapter04 ├── examples │ ├── 4.08 │ │ ├── GradeBook.cpp │ │ ├── GradeBook.hpp │ │ └── fig04_10.cpp │ ├── 4.12 │ │ ├── GradeBook.cpp │ │ ├── GradeBook.hpp │ │ └── fig04_14.cpp │ ├── 4.16 │ │ └── fig04_16.cpp │ └── 4.19 │ │ └── fig04_19.cpp └── exercises │ ├── 4.13 │ ├── GasMileage.cpp │ ├── GasMileage.hpp │ └── ex_413.cpp │ ├── 4.14 │ ├── CreditLimits.cpp │ ├── CreditLimits.hpp │ └── ex_414.cpp │ ├── 4.15 │ ├── SalesCommissionCalculator.cpp │ ├── SalesCommissionCalculator.hpp │ └── ex_415.cpp │ ├── 4.16 │ ├── SalaryCalculator.cpp │ ├── SalaryCalculator.hpp │ └── ex_416.cpp │ ├── 4.17 │ └── ex_417.cpp │ ├── 4.18 │ └── ex_418.cpp │ ├── 4.19 │ └── ex_419.cpp │ ├── 4.20 │ └── ex_420.cpp │ ├── 4.25 │ └── ex_425.cpp │ ├── 4.26 │ └── ex_426.cpp │ ├── 4.27 │ └── ex_427.cpp │ ├── 4.28 │ └── ex_428.cpp │ ├── 4.29 │ └── ex_429.cpp │ ├── 4.30 │ └── ex_430.cpp │ ├── 4.32 │ └── ex_432.cpp │ ├── 4.33 │ └── ex_433.cpp │ ├── 4.34 │ └── ex_434.cpp │ ├── 4.35 │ ├── EncryptionSystem.cpp │ ├── EncryptionSystem.hpp │ └── ex_435.cpp │ └── 4.36 │ └── ex_436.cpp ├── Chapter05 ├── examples │ ├── 5.01 │ │ └── fig05_01.cpp │ ├── 5.02 │ │ └── fig05_02.cpp │ ├── 5.05 │ │ └── fig05_05.cpp │ ├── 5.06 │ │ └── fig05_06.cpp │ ├── 5.07 │ │ └── fig05_07.cpp │ ├── 5.09 │ │ ├── GradeBook.cpp │ │ ├── GradeBook.hpp │ │ └── fig05_11.cpp │ ├── 5.13 │ │ └── fig05_13.cpp │ ├── 5.14 │ │ └── fig05_14.cpp │ └── 5.18 │ │ └── fig05_18.cpp └── exercises │ ├── 5.05 │ └── ex_505.cpp │ ├── 5.06 │ └── ex_506.cpp │ ├── 5.08 │ └── ex_508.cpp │ ├── 5.09 │ └── ex_509.cpp │ ├── 5.10 │ └── ex_510.cpp │ ├── 5.11 │ └── ex_511.cpp │ ├── 5.12 │ └── ex_512.cpp │ ├── 5.13 │ └── ex_513.cpp │ ├── 5.14 │ └── ex_514.cpp │ ├── 5.15 │ ├── GradeBook.cpp │ ├── GradeBook.hpp │ └── ex_515.cpp │ ├── 5.16 │ └── ex_516.cpp │ ├── 5.18 │ └── ex_518.cpp │ ├── 5.19 │ └── ex_519.cpp │ ├── 5.20 │ └── ex_520.cpp │ ├── 5.21 │ ├── SalaryCalculator.cpp │ ├── SalaryCalculator.hpp │ └── ex_521.cpp │ ├── 5.22 │ └── ex_522.cpp │ ├── 5.23 │ └── ex_523.cpp │ ├── 5.24 │ └── ex_524.cpp │ ├── 5.25 │ └── ex_525.cpp │ ├── 5.27 │ └── ex_527.cpp │ ├── 5.28 │ └── ex_528.cpp │ ├── 5.29 │ └── ex_529.cpp │ ├── 5.30 │ ├── Question.cpp │ ├── Question.hpp │ ├── Quiz.cpp │ ├── Quiz.hpp │ └── ex_530.cpp │ └── 5.31 │ └── ex_531.cpp ├── Chapter06 ├── README.md ├── examples │ ├── 6.03 │ │ ├── GradeBook.cpp │ │ ├── GradeBook.hpp │ │ └── fig06_05.cpp │ ├── 6.08 │ │ └── fig06_08.cpp │ ├── 6.09 │ │ └── fig06_09.cpp │ ├── 6.10 │ │ └── fig06_10.cpp │ ├── 6.11 │ │ └── fig06_11.cpp │ ├── 6.12 │ │ └── fig06_12.cpp │ ├── 6.13 │ │ └── fig06_13.cpp │ ├── 6.17 │ │ └── fig06_17.cpp │ ├── 6.18 │ │ └── fig06_18.cpp │ ├── 6.19 │ │ └── fig06_19.cpp │ ├── 6.20 │ │ └── fig06_20.cpp │ ├── 6.21 │ │ └── fig06_21.cpp │ ├── 6.22 │ │ └── fig06_22.cpp │ ├── 6.23 │ │ └── fig06_23.cpp │ ├── 6.24 │ │ └── fig06_24.cpp │ ├── 6.25 │ │ └── fig06_25.cpp │ ├── 6.26 │ │ ├── fig06_27.cpp │ │ └── maximum.hpp │ ├── 6.29 │ │ └── fig06_29.cpp │ ├── 6.30 │ │ └── fig06_30.cpp │ └── 6.32 │ │ └── fig06_32.cpp └── exercises │ ├── 6.12 │ └── ex_612.cpp │ ├── 6.13 │ └── ex_613.cpp │ ├── 6.14 │ └── ex_614.cpp │ ├── 6.16 │ └── ex_616.cpp │ ├── 6.17 │ └── ex_617.cpp │ ├── 6.18 │ └── ex_618.cpp │ ├── 6.19 │ └── ex_619.cpp │ ├── 6.20 │ └── ex_620.cpp │ ├── 6.21 │ └── ex_621.cpp │ ├── 6.22 │ └── ex_622.cpp │ ├── 6.23 │ └── ex_623.cpp │ ├── 6.24 │ └── ex_624.cpp │ ├── 6.25 │ └── ex_625.cpp │ ├── 6.26 │ └── ex_626.cpp │ ├── 6.27 │ └── ex_627.cpp │ ├── 6.28 │ └── ex_628.cpp │ ├── 6.29 │ └── ex_629.cpp │ ├── 6.30 │ └── ex_630.cpp │ ├── 6.31 │ └── ex_631.cpp │ ├── 6.32 │ └── ex_632.cpp │ ├── 6.33 │ └── ex_633.cpp │ ├── 6.34 │ ├── GuessTheNumber.cpp │ ├── GuessTheNumber.hpp │ └── ex_634.cpp │ ├── 6.35 │ ├── GuessTheNumber.cpp │ ├── GuessTheNumber.hpp │ └── ex_635.cpp │ ├── 6.36 │ └── ex_636.cpp │ ├── 6.37 │ └── ex_637.cpp │ ├── 6.38 │ └── empty │ ├── 6.39 │ └── empty │ ├── 6.40 │ └── ex_640.cpp │ ├── 6.41 │ └── ex_641.cpp │ ├── 6.42 │ └── ex_642.cpp │ ├── 6.43 │ └── ex_643.cpp │ ├── 6.49 │ ├── Craps.cpp │ ├── Craps.hpp │ └── ex_649.cpp │ ├── 6.50 │ └── ex_650.cpp │ ├── 6.51 │ └── ex_651.cpp │ ├── 6.53 │ └── ex_653.cpp │ ├── 6.54 │ └── ex_654.cpp │ └── 6.56 │ ├── CAI.cpp │ ├── CAI.hpp │ ├── Question.hpp │ └── ex_656.cpp ├── Chapter07 ├── README.md ├── examples │ ├── 7.03 │ │ └── fig07_03.cpp │ ├── 7.04 │ │ └── fig07_04.cpp │ ├── 7.05 │ │ └── fig07_05.cpp │ ├── 7.08 │ │ └── fig07_08.cpp │ ├── 7.09 │ │ └── fig07_09.cpp │ ├── 7.10 │ │ └── fig07_10.cpp │ ├── 7.11 │ │ └── fig07_11.cpp │ ├── 7.12 │ │ └── fig07_12.cpp │ ├── 7.13 │ │ └── fig07_13.cpp │ ├── 7.14 │ │ └── fig07_14.cpp │ ├── 7.15 │ │ ├── GradeBook.cpp │ │ ├── GradeBook.hpp │ │ └── fig07_17.cpp │ ├── 7.18 │ │ └── fig07_18.cpp │ ├── 7.19 │ │ └── fig07_19.cpp │ ├── 7.21 │ │ └── fig07_21.cpp │ ├── 7.22 │ │ ├── GradeBook.cpp │ │ ├── GradeBook.hpp │ │ └── fig07_24.cpp │ └── 7.25 │ │ └── fig07_25.cpp └── exercises │ ├── 7.10 │ └── ex_710.cpp │ ├── 7.11 │ └── ex_711.cpp │ ├── 7.12 │ └── ex_712.cpp │ ├── 7.13 │ └── ex_713.cpp │ ├── 7.15 │ └── ex_715.cpp │ ├── 7.17 │ └── ex_717.cpp │ ├── 7.19 │ └── empty │ ├── 7.20 │ ├── ReservationSystem.cpp │ ├── ReservationSystem.hpp │ └── ex_720.cpp │ ├── 7.22 │ └── ex_722.cpp │ ├── 7.23 │ ├── Turtle.cpp │ ├── Turtle.hpp │ └── ex_723.cpp │ ├── 7.24 │ └── empty │ ├── 7.25 │ └── empty │ ├── 7.26 │ └── empty │ ├── 7.27 │ └── empty │ ├── 7.28 │ └── empty │ ├── 7.29 │ └── ex_729.cpp │ ├── 7.30 │ └── ex_730.cpp │ ├── 7.31 │ └── ex_731.cpp │ ├── 7.32 │ └── ex_732.cpp │ ├── 7.33 │ └── ex_733.cpp │ ├── 7.34 │ └── empty │ ├── 7.35 │ └── ex_735.cpp │ ├── 7.36 │ └── ex_736.cpp │ ├── 7.37 │ └── ex_737.cpp │ ├── 7.38 │ └── ex_738.cpp │ ├── 7.39 │ └── ex_739.cpp │ ├── 7.40 │ └── ex_740.cpp │ └── 7.41 │ ├── Poll.cpp │ ├── Poll.hpp │ └── ex_741.cpp ├── Chapter08 ├── README.md ├── examples │ ├── 8.04 │ │ └── fig08_04.cpp │ ├── 8.06 │ │ └── fig08_06.cpp │ ├── 8.07 │ │ └── fig08_07.cpp │ ├── 8.10 │ │ └── fig08_10.cpp │ ├── 8.11 │ │ └── fig08_11.cpp │ ├── 8.12 │ │ └── fig08_12.cpp │ ├── 8.13 │ │ └── fig08_13.cpp │ ├── 8.14 │ │ └── fig08_14.cpp │ ├── 8.15 │ │ └── fig08_15.cpp │ ├── 8.18 │ │ └── fig08_18.cpp │ └── 8.20 │ │ └── fig08_20.cpp └── exercises │ ├── 8.08 │ └── ex_808.cpp │ ├── 8.09 │ └── ex_809.cpp │ ├── 8.10 │ └── ex_810.cpp │ ├── 8.12 │ ├── TortoiseAndHare.cpp │ ├── TortoiseAndHare.hpp │ └── ex_812.cpp │ ├── 8.15 │ └── ex_815.cpp │ ├── 8.16 │ ├── Maze.cpp │ ├── Maze.hpp │ ├── ex_816.cpp │ └── levels │ │ ├── level1 │ │ └── level2 │ ├── 8.17 │ └── empty │ ├── 8.18 │ ├── Simpletron.cpp │ ├── Simpletron.hpp │ └── ex_818.cpp │ ├── 8.19 │ ├── Simpletron.cpp │ ├── Simpletron.hpp │ └── ex_819.cpp │ └── 8.20 │ ├── README.md │ ├── Simpletron.cpp │ ├── Simpletron.hpp │ └── ex_820.cpp ├── Chapter09 ├── README.md ├── examples │ ├── 9.01 │ │ ├── Time.cpp │ │ ├── Time.hpp │ │ └── fig09_03.cpp │ ├── 9.04 │ │ └── fig09_04.cpp │ ├── 9.05 │ │ ├── SalesPerson.cpp │ │ ├── SalesPerson.hpp │ │ └── fig09_07.cpp │ ├── 9.08 │ │ ├── Time.cpp │ │ ├── Time.hpp │ │ └── fig09_10.cpp │ ├── 9.11 │ │ ├── CreateAndDestroy.cpp │ │ ├── CreateAndDestroy.hpp │ │ └── fig09_13.cpp │ ├── 9.14 │ │ ├── Time.cpp │ │ ├── Time.hpp │ │ └── fig09_16.cpp │ └── 9.17 │ │ ├── Date.cpp │ │ ├── Date.hpp │ │ └── fig09_19.cpp └── exercises │ ├── 9.04 │ ├── Time.cpp │ ├── Time.hpp │ └── ex_904.cpp │ ├── 9.05 │ ├── Complex.cpp │ ├── Complex.hpp │ └── ex_905.cpp │ ├── 9.06 │ ├── Rational.cpp │ ├── Rational.hpp │ └── ex_906.cpp │ ├── 9.07 │ ├── Time.cpp │ ├── Time.hpp │ └── ex_907.cpp │ ├── 9.08 │ ├── Date.cpp │ ├── Date.hpp │ └── ex_908.cpp │ ├── 9.09 │ ├── DateAndTime.cpp │ ├── DateAndTime.hpp │ └── ex_909.cpp │ ├── 9.10 │ └── empty │ ├── 9.11 │ ├── Rectangle.cpp │ ├── Rectangle.hpp │ └── ex_911.cpp │ ├── 9.12 │ ├── Coord2D.hpp │ ├── Rectangle.cpp │ ├── Rectangle.hpp │ └── ex_912.cpp │ ├── 9.13 │ └── empty │ ├── 9.14 │ ├── HugeInteger.cpp │ ├── HugeInteger.hpp │ └── ex_914.cpp │ └── 9.15 │ ├── TicTacToe.cpp │ ├── TicTacToe.hpp │ └── ex_915.cpp ├── Chapter10 ├── README.md ├── examples │ ├── 10.01 │ │ ├── Time.cpp │ │ ├── Time.hpp │ │ └── fig10_03.cpp │ ├── 10.04 │ │ ├── Increment.cpp │ │ ├── Increment.hpp │ │ └── fig10_06.cpp │ ├── 10.08 │ │ ├── Date.cpp │ │ ├── Date.hpp │ │ ├── Employee.cpp │ │ ├── Employee.hpp │ │ └── fig10_12.cpp │ ├── 10.13 │ │ └── fig10_13.cpp │ ├── 10.14 │ │ └── fig10_14.cpp │ ├── 10.15 │ │ ├── Time.cpp │ │ ├── Time.hpp │ │ └── fig10_17.cpp │ ├── 10.18 │ │ ├── Employee.cpp │ │ ├── Employee.hpp │ │ └── fig10_20.cpp │ └── 10.21 │ │ ├── Implementation.hpp │ │ ├── Interface.cpp │ │ ├── Interface.hpp │ │ └── fig10_24.cpp └── exercises │ ├── 10.06 │ ├── Date.cpp │ ├── Date.hpp │ └── ex_1006.cpp │ ├── 10.07 │ ├── SavingsAccount.cpp │ ├── SavingsAccount.hpp │ └── ex_1007.cpp │ ├── 10.08 │ ├── IntegerSet.cpp │ ├── IntegerSet.hpp │ └── ex_1008.cpp │ ├── 10.09 │ ├── Time.cpp │ ├── Time.hpp │ └── ex_1009.cpp │ ├── 10.10 │ ├── Card.cpp │ ├── Card.hpp │ ├── DeckOfCards.cpp │ ├── DeckOfCards.hpp │ └── ex_1010.cpp │ ├── 10.11 │ ├── Card.cpp │ ├── Card.hpp │ ├── DeckOfCards.cpp │ ├── DeckOfCards.hpp │ └── ex_1011.cpp │ ├── 10.12 │ ├── Card.cpp │ ├── Card.hpp │ ├── DeckOfCards.cpp │ ├── DeckOfCards.hpp │ └── ex_1012.cpp │ ├── 10.13 │ ├── Card.cpp │ ├── Card.hpp │ ├── DeckOfCards.cpp │ ├── DeckOfCards.hpp │ ├── Hand.cpp │ ├── Hand.hpp │ ├── Poker.cpp │ ├── Poker.hpp │ └── ex_1013.cpp │ └── 10.15 │ └── empty ├── Chapter11 ├── README.md ├── examples │ ├── 11.01 │ │ └── fig11_01.cpp │ ├── 11.03 │ │ ├── PhoneNumber.cpp │ │ ├── PhoneNumber.hpp │ │ └── fig11_05.cpp │ ├── 11.06 │ │ ├── Date.cpp │ │ ├── Date.hpp │ │ └── fig11_11.cpp │ ├── 11.09 │ │ ├── Array.cpp │ │ ├── Array.hpp │ │ └── fig11_09.cpp │ ├── 11.12 │ │ └── fig11_12.cpp │ └── 11.13 │ │ └── fig11_13.cpp └── exercises │ ├── 11.07 │ ├── Array.cpp │ ├── Array.hpp │ ├── DoubleScriptedArray.cpp │ ├── DoubleScriptedArray.hpp │ └── ex_1107.cpp │ ├── 11.08 │ ├── Complex.cpp │ ├── Complex.hpp │ └── ex_1108.cpp │ ├── 11.09 │ └── empty │ ├── 11.10 │ ├── RationalNumber.cpp │ ├── RationalNumber.hpp │ └── ex_1110.cpp │ └── 11.11 │ └── empty ├── Chapter12 ├── examples │ ├── 12.04 │ │ ├── CommissionEmployee.cpp │ │ ├── CommissionEmployee.hpp │ │ └── fig12_06.cpp │ ├── 12.07 │ │ ├── BasePlusCommissionEmployee.cpp │ │ ├── BasePlusCommissionEmployee.hpp │ │ └── fig12_09.cpp │ ├── 12.10 │ │ ├── BasePlusCommissionEmployee.cpp │ │ └── BasePlusCommissionEmployee.hpp │ ├── 12.12 │ │ └── CommissionEmployee.hpp │ └── 12.14 │ │ ├── BasePlusCommissionEmployee.cpp │ │ └── CommissionEmployee.cpp └── exercises │ ├── 12.09 │ ├── OvernightPackage.cpp │ ├── OvernightPackage.hpp │ ├── Package.cpp │ ├── Package.hpp │ ├── TwoDayPackage.cpp │ ├── TwoDayPackage.hpp │ ├── Utility.hpp │ └── ex_1209.cpp │ └── 12.10 │ ├── Account.cpp │ ├── Account.hpp │ ├── CheckingAccount.cpp │ ├── CheckingAccount.hpp │ ├── SavingsAccount.cpp │ ├── SavingsAccount.hpp │ └── ex_1210.cpp ├── Chapter13 ├── examples │ ├── 13.01 │ │ └── fig13_01.cpp │ ├── 13.02 │ │ └── fig13_02.cpp │ ├── 13.03 │ │ └── fig13_03.cpp │ ├── 13.04 │ │ ├── BasePlusCommissionEmployee.hpp │ │ ├── CommissionEmployee.hpp │ │ └── fig13_06.cpp │ ├── 13.09 │ │ ├── BasePlusCommissionEmployee.cpp │ │ ├── BasePlusCommissionEmployee.hpp │ │ ├── CommissionEmployee.cpp │ │ ├── CommissionEmployee.hpp │ │ ├── Employee.cpp │ │ ├── Employee.hpp │ │ ├── SalariedEmployee.cpp │ │ ├── SalariedEmployee.hpp │ │ └── fig13_17.cpp │ └── 13.19 │ │ └── fig13_19.cpp └── exercises │ ├── 13.12 │ ├── BasePlusCommissionEmployee.cpp │ ├── BasePlusCommissionEmployee.hpp │ ├── CommissionEmployee.cpp │ ├── CommissionEmployee.hpp │ ├── Date.cpp │ ├── Date.hpp │ ├── Employee.cpp │ ├── Employee.hpp │ ├── SalariedEmployee.cpp │ ├── SalariedEmployee.hpp │ └── ex_1312.cpp │ ├── 13.13 │ ├── Circle.cpp │ ├── Circle.hpp │ ├── Cube.cpp │ ├── Cube.hpp │ ├── Cuboid.cpp │ ├── Cuboid.hpp │ ├── Rectangle.cpp │ ├── Rectangle.hpp │ ├── Shape.cpp │ ├── Shape.hpp │ ├── Sphere.cpp │ ├── Sphere.hpp │ ├── Square.cpp │ ├── Square.hpp │ ├── ThreeDimensionalShape.cpp │ ├── ThreeDimensionalShape.hpp │ ├── Triangle.cpp │ ├── Triangle.hpp │ ├── TwoDimensionalShape.cpp │ ├── TwoDimensionalShape.hpp │ └── ex_1313.cpp │ ├── 13.14 │ ├── Canvas.hpp │ ├── Circle.cpp │ ├── Circle.hpp │ ├── Rectangle.cpp │ ├── Rectangle.hpp │ ├── ScreenManager.cpp │ ├── ScreenManager.hpp │ ├── Shape.cpp │ ├── Shape.hpp │ ├── Square.cpp │ ├── Square.hpp │ ├── Triangle.cpp │ ├── Triangle.hpp │ ├── TwoDimensionalShape.cpp │ ├── TwoDimensionalShape.hpp │ └── ex_1314.cpp │ ├── 13.15 │ ├── OvernightPackage.cpp │ ├── OvernightPackage.hpp │ ├── Package.cpp │ ├── Package.hpp │ ├── TwoDayPackage.cpp │ ├── TwoDayPackage.hpp │ ├── Utility.hpp │ └── ex_1315.cpp │ ├── 13.16 │ ├── Account.cpp │ ├── Account.hpp │ ├── CheckingAccount.cpp │ ├── CheckingAccount.hpp │ ├── SavingsAccount.cpp │ ├── SavingsAccount.hpp │ └── ex_1316.cpp │ ├── 13.17 │ ├── BasePlusCommissionEmployee.cpp │ ├── BasePlusCommissionEmployee.hpp │ ├── CommissionEmployee.cpp │ ├── CommissionEmployee.hpp │ ├── Employee.cpp │ ├── Employee.hpp │ ├── HourlyWorker.cpp │ ├── HourlyWorker.hpp │ ├── PieceWorker.cpp │ ├── PieceWorker.hpp │ ├── SalariedEmployee.cpp │ ├── SalariedEmployee.hpp │ └── ex_1317.cpp │ └── 13.18 │ ├── Bicycle.cpp │ ├── Bicycle.hpp │ ├── Building.cpp │ ├── Building.hpp │ ├── Car.cpp │ ├── Car.hpp │ ├── CarbonFootprint.hpp │ ├── README.md │ └── ex_1318.cpp ├── Chapter14 ├── examples │ ├── 14.01 │ │ └── fig14_01.cpp │ ├── 14.02 │ │ ├── Stack.hpp │ │ └── fig14_03.cpp │ └── 14.04 │ │ ├── Stack.hpp │ │ └── fig14_04.cpp └── exercises │ ├── 14.03 │ └── ex_1403.cpp │ ├── 14.04 │ └── ex_1404.cpp │ ├── 14.05 │ └── ex_1405.cpp │ ├── 14.06 │ ├── README.md │ └── ex_1406.cpp │ └── 14.07 │ ├── Array.hpp │ └── ex_1407.cpp ├── Chapter15 ├── README.md ├── examples │ ├── 15.03 │ │ └── fig15_03.cpp │ ├── 15.04 │ │ └── fig15_04.cpp │ ├── 15.05 │ │ └── fig15_05.cpp │ ├── 15.06 │ │ └── fig15_06.cpp │ ├── 15.07 │ │ └── fig15_07.cpp │ ├── 15.08 │ │ └── fig15_08.cpp │ ├── 15.09 │ │ └── fig15_09.cpp │ ├── 15.10 │ │ └── fig15_10.cpp │ ├── 15.11 │ │ └── fig15_11.cpp │ ├── 15.13 │ │ └── fig15_13.cpp │ ├── 15.14 │ │ └── fig15_14.cpp │ ├── 15.15 │ │ └── fig15_15.cpp │ ├── 15.16 │ │ └── fig15_16.cpp │ ├── 15.17 │ │ └── fig15_17.cpp │ ├── 15.18 │ │ └── fig15_18.cpp │ ├── 15.19 │ │ └── fig15_19.cpp │ ├── 15.20 │ │ └── fig15_20.cpp │ ├── 15.21 │ │ └── fig15_21.cpp │ └── 15.22 │ │ └── fig15_22.cpp └── exercises │ ├── 15.06 │ └── ex_1506.cpp │ ├── 15.07 │ └── ex_1507.cpp │ ├── 15.08 │ └── ex_1508.cpp │ ├── 15.09 │ └── ex_1509.cpp │ ├── 15.10 │ └── ex_1510.cpp │ ├── 15.11 │ └── ex_1511.cpp │ ├── 15.12 │ └── ex_1512.cpp │ ├── 15.14 │ ├── PhoneNumber.cpp │ ├── PhoneNumber.hpp │ └── ex_1514.cpp │ ├── 15.15 │ ├── Point.cpp │ ├── Point.hpp │ └── ex_1515.cpp │ ├── 15.16 │ └── empty │ ├── 15.17 │ └── ex_1517.cpp │ └── 15.18 │ └── empty ├── Chapter16 ├── examples │ ├── 16.01 │ │ ├── DivideByZeroException.hpp │ │ └── fig16_02.cpp │ ├── 16.03 │ │ └── fig16_03.cpp │ ├── 16.04 │ │ └── fig16_04.cpp │ ├── 16.05 │ │ └── fig16_05.cpp │ ├── 16.06 │ │ └── fig16_06.cpp │ └── 16.07 │ │ ├── Integer.cpp │ │ ├── Integer.hpp │ │ └── fig16_09.cpp └── exercises │ ├── 16.22 │ └── ex_1622.cpp │ ├── 16.23 │ └── ex_1623.cpp │ ├── 16.24 │ └── ex_1624.cpp │ ├── 16.25 │ └── ex_1625.cpp │ ├── 16.26 │ └── ex_1626.cpp │ ├── 16.27 │ └── ex_1627.cpp │ ├── 16.28 │ └── ex_1628.cpp │ ├── 16.29 │ └── ex_1629.cpp │ ├── 16.30 │ └── ex_1630.cpp │ └── 16.31 │ └── ex_1631.cpp ├── Chapter17 ├── examples │ ├── 17.03 │ │ ├── clients.txt │ │ └── fig17_03.cpp │ ├── 17.06 │ │ ├── clients.txt │ │ └── fig17_06.cpp │ ├── 17.07 │ │ ├── clients.txt │ │ └── fig17_07.cpp │ ├── 17.09 │ │ ├── ClientData.cpp │ │ ├── ClientData.hpp │ │ ├── credit.dat │ │ └── fig17_11.cpp │ ├── 17.12 │ │ ├── ClientData.cpp │ │ ├── ClientData.hpp │ │ ├── credit.dat │ │ └── fig17_12.cpp │ ├── 17.13 │ │ ├── ClientData.cpp │ │ ├── ClientData.hpp │ │ ├── credit.dat │ │ └── fig17_13.cpp │ └── 17.14 │ │ ├── ClientData.cpp │ │ ├── ClientData.hpp │ │ ├── credit.dat │ │ ├── fig17_14.cpp │ │ └── print.txt └── exercises │ ├── 17.06 │ └── ex_1706.cpp │ ├── 17.07 │ ├── ex_1707.cpp │ ├── oldmast.dat │ └── trans.dat │ ├── 17.09 │ ├── ex_1709.cpp │ ├── newmast.dat │ ├── oldmast.dat │ └── trans.dat │ ├── 17.11 │ ├── ex_1711.cpp │ └── hardware.dat │ ├── 17.12 │ ├── ex_17.12.cpp │ └── phone.dat │ ├── 17.13 │ └── ex_17.13.cpp │ └── 17.14 │ ├── ex_17.14.cpp │ ├── phising_list.txt │ └── test.txt ├── Chapter18 ├── README.md ├── examples │ ├── 18.01 │ │ └── fig18_01.cpp │ ├── 18.02 │ │ └── fig18_02.cpp │ ├── 18.03 │ │ └── fig18_03.cpp │ ├── 18.04 │ │ └── fig18_04.cpp │ ├── 18.05 │ │ └── fig18_05.cpp │ ├── 18.06 │ │ └── fig18_16.cpp │ ├── 18.07 │ │ └── fig18_07.cpp │ ├── 18.08 │ │ └── fig18_08.cpp │ ├── 18.09 │ │ └── fig18_09.cpp │ ├── 18.10 │ │ └── fig18_10.cpp │ ├── 18.11 │ │ └── fig18_11.cpp │ └── 18.12 │ │ └── fig18_12.cpp └── exercises │ ├── 18.07 │ └── ex_1807.cpp │ ├── 18.08 │ └── ex_1808.cpp │ ├── 18.09 │ └── ex_1809.cpp │ ├── 18.10 │ └── ex_1810.cpp │ ├── 18.11 │ ├── ex_1811.cpp │ └── words.txt │ ├── 18.12 │ └── ex_1812.cpp │ ├── 18.13 │ ├── animals.txt │ └── ex_1813.cpp │ ├── 18.14 │ └── ex_1814.cpp │ ├── 18.15 │ ├── Cryptograms.cpp │ ├── Cryptograms.hpp │ ├── ex_1815.cpp │ └── phrases.txt │ ├── 18.16 │ └── ex_1816.cpp │ ├── 18.17 │ └── ex_18.17.cpp │ ├── 18.18 │ └── ex_1818.cpp │ ├── 18.19 │ └── ex_1819.cpp │ ├── 18.20 │ └── ex_1820.cpp │ ├── 18.21 │ └── ex_1821.cpp │ ├── 18.22 │ └── ex_1822.cpp │ ├── 18.23 │ └── ex_1823.cpp │ ├── 18.24 │ └── ex_1824.cpp │ ├── 18.25 │ └── empty │ ├── 18.26 │ └── ex_1826.cpp │ ├── 18.27 │ ├── Employee.cpp │ └── Employee.hpp │ ├── 18.28 │ ├── IngredientSwitcher.cpp │ ├── IngredientSwitcher.hpp │ ├── alternatives │ └── ex_1828.cpp │ ├── 18.29 │ └── README.md │ ├── 18.30 │ ├── SMSDecoder.cpp │ ├── SMSDecoder.hpp │ ├── abbreviations │ └── ex_1830.cpp │ └── README.md ├── Chapter19 ├── README.md ├── examples │ ├── 19.02 │ │ ├── BinarySearch.cpp │ │ ├── BinarySearch.hpp │ │ └── fig19_04.cpp │ └── 19.05 │ │ ├── MergeSort.cpp │ │ ├── MergeSort.hpp │ │ └── fig19_07.cpp └── exercises │ ├── 19.05 │ └── ex_1905.cpp │ ├── 19.06 │ └── ex_1906.cpp │ ├── 19.07 │ └── empty │ ├── 19.08 │ └── ex_1908.cpp │ ├── 19.09 │ └── ex_1909.cpp │ └── 19.10 │ └── ex_1910.cpp ├── Chapter20 ├── README.md ├── examples │ ├── 20.03 │ │ ├── List.hpp │ │ ├── ListNode.hpp │ │ └── fig20_05.cpp │ ├── 20.13 │ │ ├── List.hpp │ │ ├── ListNode.hpp │ │ ├── Stack.hpp │ │ └── fig10_14.cpp │ ├── 20.15 │ │ └── StackComposition.hpp │ ├── 20.16 │ │ ├── List.hpp │ │ ├── ListNode.hpp │ │ ├── Queue.hpp │ │ └── fig20_17.cpp │ └── 20.20 │ │ ├── Tree.hpp │ │ ├── TreeNode.hpp │ │ └── fig20_22.cpp └── exercises │ ├── 20.06 │ ├── List.hpp │ ├── ListNode.hpp │ └── ex_2006.cpp │ ├── 20.07 │ ├── List.hpp │ ├── ListNode.hpp │ └── ex_2007.cpp │ ├── 20.08 │ ├── List.hpp │ ├── ListNode.hpp │ └── ex_2008.cpp │ ├── 20.09 │ ├── List.hpp │ ├── ListNode.hpp │ └── ex_2009.cpp │ ├── 20.10 │ └── ex_2010.cpp │ ├── 20.11 │ └── ex_2011.cpp │ ├── 20.12 │ ├── List.hpp │ ├── ListNode.hpp │ ├── Stack.hpp │ └── ex_2012.cpp │ ├── 20.13 │ ├── List.hpp │ ├── ListNode.hpp │ ├── Stack.hpp │ └── ex_20.13.cpp │ ├── 20.14 │ ├── List.hpp │ ├── ListNode.hpp │ ├── Stack.hpp │ └── ex_20.14.cpp │ ├── 20.15 │ ├── List.hpp │ ├── ListNode.hpp │ ├── Queue.hpp │ └── ex_2015.cpp │ ├── 20.16 │ ├── Tree.hpp │ ├── TreeNode.hpp │ └── ex_2016.cpp │ ├── 20.17 │ ├── Tree.hpp │ ├── TreeNode.hpp │ └── ex_20.17.cpp │ ├── 20.18 │ ├── Tree.hpp │ ├── TreeNode.hpp │ └── ex_2018.cpp │ ├── 20.19 │ ├── Tree.hpp │ ├── TreeNode.hpp │ └── ex_2019.cpp │ ├── 20.20 │ ├── List.hpp │ ├── ListNode.hpp │ └── ex_2020.cpp │ ├── 20.21 │ ├── List.hpp │ ├── ListNode.hpp │ └── ex_2021.cpp │ ├── 20.22 │ └── empty │ ├── 20.23 │ ├── Tree.hpp │ ├── TreeNode.hpp │ └── ex_2023.cpp │ ├── 20.24 │ ├── Tree.hpp │ ├── TreeNode.hpp │ └── ex_2024.cpp │ ├── 20.25 │ ├── Tree.hpp │ ├── TreeNode.hpp │ └── ex_2025.cpp │ ├── 20.26 │ ├── List.hpp │ ├── ListNode.hpp │ └── ex_2026.cpp │ ├── 20.27 │ ├── List.hpp │ ├── ListNode.hpp │ ├── Queue.hpp │ └── ex_2027.cpp │ ├── 20.28 │ └── StackComposition.hpp │ └── 20.30 │ └── empty ├── Chapter21 ├── README.md ├── examples │ ├── 21.02 │ │ ├── DeckOfCards.cpp │ │ ├── DeckOfCards.h │ │ └── fig21_04.cpp │ ├── 21.06 │ │ └── fig21_06.cpp │ ├── 21.08 │ │ └── fig21_08.cpp │ ├── 21.11 │ │ └── fig21_11.cpp │ ├── 21.14 │ │ ├── DeckOfCards.cpp │ │ ├── DeckOfCards.h │ │ └── fig21_16.cpp │ ├── 21.18 │ │ └── fig21_18.cpp │ ├── 21.19 │ │ └── fig21_19.cpp │ ├── 21.20 │ │ └── fig21_20.cpp │ ├── 21.22 │ │ └── fig21_22.cpp │ ├── 21.23 │ │ └── fig21_23.cpp │ ├── 21.24 │ │ └── fig21_24.cpp │ ├── 21.25 │ │ └── fig21_25.cpp │ ├── 21.26 │ │ └── fig21_26.cpp │ ├── 21.28 │ │ └── fig21_28.cpp │ ├── 21.29 │ │ └── fig21_29.cpp │ ├── 21.30 │ │ └── fig21_30.cpp │ ├── 21.31 │ │ └── fig21_31.cpp │ ├── 21.32 │ │ └── fig21_32.cpp │ ├── 21.33 │ │ └── fig21_33.cpp │ ├── 21.35 │ │ └── fig21_35.cpp │ ├── 21.36 │ │ └── fig21_36.cpp │ ├── 21.37 │ │ └── fig21_37.cpp │ ├── 21.38 │ │ └── fig21_38.cpp │ ├── 21.39 │ │ └── fig21_39.cpp │ ├── 21.40 │ │ └── fig21_40.cpp │ ├── 21.42 │ │ └── fig21_42.cpp │ ├── 21.43 │ │ └── fig21_43.cpp │ ├── 21.44 │ │ └── fig21_44.cpp │ ├── 21.45 │ │ └── fig21_45.cpp │ └── 21.46 │ │ └── fig21_46.cpp └── exercises │ ├── 21.04 │ └── ex_2104.cpp │ ├── 21.05 │ ├── DeckOfCards.cpp │ ├── DeckOfCards.hpp │ └── ex_2105.cpp │ ├── 21.06 │ └── ex_2106.cpp │ ├── 21.07 │ └── ex_2107.cpp │ ├── 21.08 │ └── ex_2108.cpp │ ├── 21.09 │ └── README.md │ ├── 21.10 │ └── ex_2110.cpp │ ├── 21.11 │ └── README.md │ ├── 21.12 │ └── empty │ ├── 21.13 │ └── ex_2113.cpp │ ├── 21.16 │ └── ex_2116.cpp │ ├── 21.17 │ └── ex_2117.cpp │ ├── 21.18 │ └── ex_2118.cpp │ ├── 21.19 │ └── ex_2119.cpp │ ├── 21.20 │ └── ex_2120.cpp │ ├── 21.21 │ └── ex_2121.cpp │ ├── 21.22 │ └── ex_2122.cpp │ ├── 21.24 │ └── ex_2124.cpp │ ├── 21.25 │ └── ex_2125.cpp │ ├── 21.26 │ └── ex_2126.cpp │ ├── 21.27 │ └── custchar.hpp │ ├── 21.28 │ └── custconversions.hpp │ ├── 21.29 │ └── custsearch.hpp │ ├── 21.30 │ └── custmemory.hpp │ ├── 21.32 │ └── ex_2132.cpp │ ├── 21.33 │ └── ex_2133.cpp │ ├── 21.34 │ └── ex_2134.cpp │ ├── 21.35 │ └── empty │ ├── 21.36 │ └── ex_21.36.cpp │ ├── 21.37 │ └── ex_2137.cpp │ ├── 21.38 │ └── ex_2138.cpp │ ├── 21.39 │ └── ex_2139.cpp │ ├── 21.40 │ ├── custcopycatptr.hpp │ └── custcopycatsub.hpp │ ├── 21.41 │ └── README.md │ ├── 21.42 │ └── README.md │ ├── 21.43 │ └── ex_2143.cpp │ ├── 21.44 │ └── ex_2144.cpp │ ├── 21.45 │ └── ex_2145.cpp │ └── 21.46 │ └── ex_2146.cpp └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io/api/vim 2 | 3 | ### Vim ### 4 | # swap 5 | .sw[a-p] 6 | .*.sw[a-p] 7 | # session 8 | Session.vim 9 | # temporary 10 | .netrwhist 11 | *~ 12 | # auto-generated tag files 13 | tags 14 | 15 | # compiled binary files 16 | main 17 | 18 | # dotfiles 19 | .* 20 | -------------------------------------------------------------------------------- /Chapter02/examples/2.01/fig02_01.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig02_01.cpp 5 | * 6 | * Description: Fig. 2.1 - Text-printing program 7 | * 8 | * Version: 1.0 9 | * Created: 10/03/16 18:59:23 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include // allows program to output data to the screen 19 | 20 | // function main begins program execution 21 | int main(int argc, const char *argv[]) { 22 | std::cout << "Welcome to C++!" << std::endl; // display message 23 | 24 | return 0; // indicate that program ended successfully 25 | } // end function main 26 | -------------------------------------------------------------------------------- /Chapter02/examples/2.03/fig02_03.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig02_03.cpp 5 | * 6 | * Description: Fig. 2.3: Printing a line of text with multiple statements. 7 | * 8 | * Version: 1.0 9 | * Created: 10/03/16 19:06:52 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int main(int argc, const char *argv[]) { 21 | std::cout << "Welcome "; 22 | std::cout << "to C++" << std::endl; 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Chapter02/examples/2.04/fig02_04.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig02_04.cpp 5 | * 6 | * Description: Fig. 2.4: Printing multiple lines of text with a single 7 | * statement. 8 | * 9 | * Version: 1.0 10 | * Created: 10/03/16 19:09:04 11 | * Revision: none 12 | * Compiler: g++ 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include 20 | 21 | int main(int argc, const char *argv[]) { 22 | std::cout << "Welcome\nto\n\nC++!" << std::endl; 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Chapter02/exercises/2.09/ex_209.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_209.cpp 5 | * 6 | * Description: Exercise 2.9 - Print Single C++ Statements. 7 | * 8 | * Version: 1.0 9 | * Created: 10/03/16 23:52:15 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int main(int argc, const char *argv[]) { 21 | int a, b, c; 22 | 23 | std::cout << "Enter two numbers "; 24 | std::cin >> b >> c; 25 | 26 | a = b * c; 27 | 28 | std::cout << "This program performs a payroll calculation" << std::endl; 29 | std::cout << "Enter three integer values "; 30 | 31 | std::cin >> a >> b >> c; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Chapter02/exercises/2.17/ex_217.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_217.cpp 5 | * 6 | * Description: Exercise 2.17 - Printing 7 | * 8 | * Version: 1.0 9 | * Created: 11/03/16 03:22:46 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int main(int argc, const char *argv[]) { 21 | std::cout << "1 2 3 4" << std::endl; 22 | std::cout << "1 " 23 | << "2 " 24 | << "3 " 25 | << "4 " << std::endl; 26 | std::cout << "1 "; 27 | std::cout << "2 "; 28 | std::cout << "3 "; 29 | std::cout << "4 " << std::endl; 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Chapter02/exercises/2.18/ex_218.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_218.cpp 5 | * 6 | * Description: Exercise 2.18 - Comparing integers 7 | * 8 | * Version: 1.0 9 | * Created: 11/03/16 04:28:06 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | inline int MAX(int a, int b) { return (a > b) ? a : b; } 21 | 22 | int main(int argc, const char *argv[]) { 23 | int num1, num2; 24 | 25 | std::cout << "Enter two integers: "; 26 | std::cin >> num1 >> num2; 27 | 28 | if (num1 == num2) { 29 | std::cout << "These numbers are equal" << std::endl; 30 | } else { 31 | std::cout << MAX(num1, num2) << " is Larger." << std::endl; 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Chapter02/exercises/2.20/ex_220.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_220.cpp 5 | * 6 | * Description: Exercise 2.20 - Diameter, Circumference and Area of a circle 7 | * 8 | * Version: 1.0 9 | * Created: 11/03/16 03:39:27 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | const double PI = 3.14159; 21 | 22 | int main(int argc, const char *argv[]) { 23 | int radius; 24 | 25 | std::cout << "Enter an integer value circle radius: "; 26 | std::cin >> radius; 27 | 28 | std::cout << "Diameter: " << 2 * radius << std::endl; 29 | std::cout << "Circumference: " << PI * (2 * radius) << std::endl; 30 | std::cout << "Area: " << PI * (radius * radius) << std::endl; 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Chapter02/exercises/2.24/ex_224.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_224.cpp 5 | * 6 | * Description: Exercise 2.24 - Odd or Even 7 | * 8 | * Version: 1.0 9 | * Created: 11/03/16 04:03:30 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int main(int argc, const char *argv[]) { 21 | int num1; 22 | 23 | std::cout << "Enter an integer: "; 24 | std::cin >> num1; 25 | 26 | std::cout << num1 << " is " << ((num1 % 2 == 0) ? "even" : "odd") << std::endl; 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Chapter02/exercises/2.25/ex_225.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_225.cpp 5 | * 6 | * Description: Exercise 2.25 - Multiples 7 | * 8 | * Version: 1.0 9 | * Created: 11/03/16 04:06:37 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int main(int argc, const char *argv[]) { 21 | int num1, num2; 22 | 23 | std::cout << "Enter two integers: "; 24 | std::cin >> num1 >> num2; 25 | 26 | std::cout << num1 << ((num1 % num2 == 0) ? " is " : " is not ") 27 | << "a multiple of " << num2 << std::endl; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Chapter02/exercises/2.27/ex_227.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_227.cpp 5 | * 6 | * Description: Exercise 2.27 - Integer Equivalent of a Character 7 | * 8 | * Version: 1.0 9 | * Created: 11/03/16 04:37:43 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int main(int argc, const char *argv[]) { 21 | char char1; 22 | 23 | std::cout << "Enter a character: "; 24 | std::cin >> char1; 25 | 26 | std::cout << "Integer equivalent of " << char1 << ": "; 27 | std::cout << static_cast(char1) << std::endl; 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Chapter02/exercises/2.29/ex_229.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_229.cpp 5 | * 6 | * Description: Exercise 2.29 - Table 7 | * 8 | * Version: 1.0 9 | * Created: 11/03/16 04:59:04 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int main(int argc, const char *argv[]) { 21 | std::cout << "integer square cube" << std::endl; 22 | 23 | for (int i = 0; i <= 10; ++i) { 24 | std::cout << i << "\t" << (i * i) << "\t" << (i * i * i) << std::endl; 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Chapter03/examples/3.17/GradeBook.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: GradeBook.hpp 5 | * 6 | * Description: Fig. 3.15: GradeBook class definitions presents the public 7 | * interface of the class. 8 | * Member-function definitions appear in GradeBook.cpp. 9 | * 10 | * Version: 1.0 11 | * Created: 20/03/16 19:59:38 12 | * Revision: none 13 | * Compiler: gcc 14 | * 15 | * Author: Siidney Watson - siidney.watson.work@gmail.com 16 | * Organization: LolaDog Studio 17 | * 18 | * ===================================================================================== 19 | */ 20 | #pragma once 21 | 22 | #include 23 | 24 | class GradeBook { 25 | private: 26 | std::string courseName; 27 | 28 | public: 29 | explicit GradeBook(const std::string &); 30 | 31 | // SETTERS 32 | void setCourseName(const std::string &); 33 | 34 | // GETTERS 35 | std::string getCourseName(); 36 | 37 | void displayMessage(); 38 | }; 39 | -------------------------------------------------------------------------------- /Chapter03/exercises/3.11/ex_311.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_311.cpp 5 | * 6 | * Description: Exercise 3.11 - Modifying Class GradeBook 7 | * 8 | * Version: 1.0 9 | * Created: 20/03/16 20:30:29 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "GradeBook.hpp" 19 | 20 | int main(int argc, const char *argv[]) { 21 | GradeBook gradeBook1("This is a course", "The Instructor"); 22 | 23 | gradeBook1.displayMessage(); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Chapter03/exercises/3.12/Account.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Account.hpp 5 | * 6 | * Description: Exercise 3.12 - Account Class 7 | * 8 | * Version: 1.0 9 | * Created: 21/03/16 00:11:29 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | class Account { 21 | private: 22 | int accountBalance; 23 | 24 | public: 25 | explicit Account(int); 26 | 27 | // GETTERS 28 | int getBalance(); 29 | 30 | void credit(int); // credit account 31 | void debit(int); // debit account 32 | }; 33 | -------------------------------------------------------------------------------- /Chapter03/exercises/3.14/ex_314.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_314.cpp 5 | * 6 | * Description: Exercise 3.14 - Employee Class 7 | * 8 | * Version: 1.0 9 | * Created: 21/03/16 02:51:14 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | #include "Employee.hpp" 21 | 22 | int main(int argc, const char *argv[]) { 23 | Employee emp1("Bob", "Bobson", 1200); 24 | Employee emp2("Sue", "Sueson", 2000); 25 | 26 | emp1.showEmployee(); 27 | emp2.showEmployee(); 28 | 29 | emp1.giveRaise(10); 30 | emp2.giveRaise(10); 31 | 32 | emp1.showEmployee(); 33 | emp2.showEmployee(); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Chapter03/exercises/3.15/Date.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Date.hpp 5 | * 6 | * Description: Exercise 3.15 - Date Class 7 | * 8 | * Version: 1.0 9 | * Created: 23/03/16 18:00:34 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include 21 | 22 | class Date { 23 | private: 24 | int month = 1; 25 | int day = 1; 26 | int year = 1900; 27 | 28 | public: 29 | Date(int, int, int); 30 | 31 | // SETTERS 32 | void setMonth(int); 33 | void setDay(int); 34 | void setYear(int); 35 | 36 | // GETTERS 37 | int getMonth() const; 38 | int getDay() const; 39 | int getYear() const; 40 | 41 | void displayDate() const; 42 | }; 43 | -------------------------------------------------------------------------------- /Chapter03/exercises/3.15/ex_315.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_315.cpp 5 | * 6 | * Description: Exercise 3.15 - Date Class 7 | * 8 | * Version: 1.0 9 | * Created: 23/03/16 18:09:41 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "Date.hpp" 19 | 20 | int main(int argc, const char *argv[]) { 21 | Date date1(12, 7, 1983); 22 | Date date2(14, 23, 1255); 23 | 24 | date1.displayDate(); 25 | date2.displayDate(); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Chapter03/exercises/3.16/ex_316.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_316.cpp 5 | * 6 | * Description: Exercise 3.16 - Target-Heart-Rate Calculator 7 | * 8 | * Version: 1.0 9 | * Created: 23/03/16 19:39:20 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "HeartRates.hpp" 19 | 20 | int main(int argc, const char *argv[]) { 21 | HeartRates heartRates1("Billy", "Bunson", 11, 23, 1956); 22 | heartRates1.displayInformation(); 23 | 24 | HeartRates heartRates2("Sue", "Sueson", 5, 13, 1983); 25 | heartRates2.displayInformation(); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Chapter04/examples/4.08/GradeBook.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: GradeBook.hpp 5 | * 6 | * Description: Fig. 4.8: Definition of class GradeBook that determines a 7 | * class average. Member functions are defined in 8 | * GradeBook.cpp. 9 | * 10 | * Version: 1.0 11 | * Created: 24/03/16 17:27:07 12 | * Revision: none 13 | * Compiler: gcc 14 | * 15 | * Author: Siidney Watson - siidney.watson.work@gmail.com 16 | * Organization: LolaDog Studio 17 | * 18 | * ===================================================================================== 19 | */ 20 | #pragma once 21 | 22 | #include 23 | 24 | class GradeBook { 25 | private: 26 | std::string courseName; 27 | 28 | public: 29 | explicit GradeBook(std::string); 30 | 31 | // SETTERS 32 | void setCourseName(std::string); 33 | 34 | // GETTERS 35 | std::string getCourseName(); 36 | 37 | void displayMessage(); 38 | void determineClassAverage(); 39 | }; 40 | -------------------------------------------------------------------------------- /Chapter04/examples/4.08/fig04_10.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig04_10.cpp 5 | * 6 | * Description: Fig. 4.10: Create GradeBook object and invoke its 7 | * determineClassAverage function. 8 | * 9 | * Version: 1.0 10 | * Created: 24/03/16 17:44:49 11 | * Revision: none 12 | * Compiler: g++ 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include "GradeBook.hpp" 20 | 21 | int main(int argc, const char *argv[]) { 22 | GradeBook myGradeBook("CS101 C++ Programming"); 23 | 24 | myGradeBook.displayMessage(); 25 | myGradeBook.determineClassAverage(); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Chapter04/examples/4.12/fig04_14.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig04_14.cpp 5 | * 6 | * Description: Fig. 4.14: Create GradeBook object and invoke its 7 | * determineClassAverage function. 8 | * 9 | * Version: 1.0 10 | * Created: 24/03/16 17:44:49 11 | * Revision: none 12 | * Compiler: g++ 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include "GradeBook.hpp" 20 | 21 | int main(int argc, const char *argv[]) { 22 | GradeBook myGradeBook("CS101 C++ Programming"); 23 | 24 | myGradeBook.displayMessage(); 25 | myGradeBook.determineClassAverage(); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Chapter04/examples/4.19/fig04_19.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig04_19.cpp 5 | * 6 | * Description: Fig. 4.19: Preincrimenting and postincrementing. 7 | * 8 | * Version: 1.0 9 | * Created: 24/03/16 19:30:39 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int main(int argc, const char *argv[]) { 21 | int c; 22 | 23 | // postincrement 24 | c = 5; 25 | std::cout << c << std::endl; 26 | std::cout << c++ << std::endl; 27 | std::cout << c << std::endl; 28 | 29 | std::cout << std::endl; 30 | 31 | // preincrement 32 | c = 5; 33 | std::cout << c << std::endl; 34 | std::cout << ++c << std::endl; 35 | std::cout << c << std::endl; 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Chapter04/exercises/4.13/ex_413.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_413.cpp 5 | * 6 | * Description: Exercise 4.13 - Gas Mileage 7 | * 8 | * Version: 1.0 9 | * Created: 27/03/16 00:33:47 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "GasMileage.hpp" 19 | 20 | static const int QUIT = -1; 21 | 22 | int main(int argc, const char *argv[]) { 23 | GasMileage gm; 24 | 25 | while (gm.getMilesDriven() != QUIT) { 26 | gm.run(); 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Chapter04/exercises/4.14/ex_414.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_414.cpp 5 | * 6 | * Description: Exercise 4.14 - Credit Limits 7 | * 8 | * Version: 1.0 9 | * Created: 27/03/16 01:02:27 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "CreditLimits.hpp" 19 | 20 | const static int QUIT = -1; 21 | 22 | int main(int argc, const char *argv[]) { 23 | CreditLimits cl; 24 | 25 | while (cl.getAccountNumber() != QUIT) { 26 | cl.run(); 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Chapter04/exercises/4.15/ex_415.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_415.cpp 5 | * 6 | * Description: Exercise 4.15 - Sales Commission Calculator 7 | * 8 | * Version: 1.0 9 | * Created: 27/03/16 01:27:06 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "SalesCommissionCalculator.hpp" 19 | 20 | static const int QUIT = -1; 21 | 22 | int main(int argc, const char *argv[]) { 23 | SalesCommissionCalculator scc; 24 | 25 | while (scc.getWeeklySales() != QUIT) { 26 | scc.run(); 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Chapter04/exercises/4.16/ex_416.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_416.cpp 5 | * 6 | * Description: Exercise 4.16 - Salary Calculator 7 | * 8 | * Version: 1.0 9 | * Created: 27/03/16 01:45:44 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "SalaryCalculator.hpp" 19 | 20 | static const int QUIT = -1; 21 | 22 | int main(int argc, const char *argv[]) { 23 | SalaryCalculator sc; 24 | 25 | while (sc.getHoursWorked() != QUIT) { 26 | sc.run(); 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Chapter04/exercises/4.18/ex_418.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_418.cpp 5 | * 6 | * Description: Exercise 4.18 - Tabular Output 7 | * 8 | * Version: 1.0 9 | * Created: 27/03/16 02:03:43 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int main(int argc, const char *argv[]) { 21 | int counter = 0; 22 | 23 | printf("N\t10*N\t100*N\t1000*N\n\n"); 24 | 25 | while (counter < 5) { 26 | counter++; 27 | 28 | printf("%d\t%d\t%d\t%d\n", counter, counter * 10, counter * 100, counter * 1000); 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Chapter04/exercises/4.28/ex_428.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_428.cpp 5 | * 6 | * Description: Exercise 4.28 - Checkerboard Patter of Asterisks 7 | * 8 | * Version: 1.0 9 | * Created: 27/03/16 03:37:35 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int main(int argc, const char *argv[]) { 21 | for (int i = 1; i <= 8; i++) { 22 | if (i % 2 == 0) { 23 | std::cout << ' '; 24 | } 25 | for (int j = 0; j < 8; j++) { 26 | std::cout << "* "; 27 | } 28 | std::cout << std::endl; 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Chapter04/exercises/4.29/ex_429.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_429.cpp 5 | * 6 | * Description: Exercise 4.29 - Multiples of 2 with an Infinite Loop 7 | * 8 | * Version: 1.0 9 | * Created: 27/03/16 18:07:17 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int main(int argc, const char *argv[]) { 21 | int num = 2; 22 | 23 | while (true) { 24 | std::cout << num << std::endl; 25 | num *= 2; 26 | } 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Chapter05/examples/5.01/fig05_01.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig05_01.cpp 5 | * 6 | * Description: Fig. 5.1: Counter-controlled repetition. 7 | * 8 | * Version: 1.0 9 | * Created: 04/04/16 16:41:00 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int main(int argc, const char *argv[]) { 21 | int counter = 1; 22 | 23 | while (counter <= 10) { 24 | std::cout << counter << " "; 25 | ++counter; 26 | } 27 | std::cout << std::endl; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Chapter05/examples/5.02/fig05_02.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig05_02.cpp 5 | * 6 | * Description: Fig. 5.2: Counter-controlled repetition with the for 7 | * statement. 8 | * 9 | * Version: 1.0 10 | * Created: 04/04/16 16:42:15 11 | * Revision: none 12 | * Compiler: g++ 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include 20 | 21 | int main(int argc, const char *argv[]) { 22 | for (int counter = 1; counter <= 10; ++counter) { 23 | std::cout << counter << " "; 24 | } 25 | std::cout << std::endl; 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Chapter05/examples/5.05/fig05_05.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig05_05.cpp 5 | * 6 | * Description: Fig. 5.05: Summing integers with the for statement 7 | * 8 | * Version: 1.0 9 | * Created: 04/04/16 16:43:16 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int main(int argc, const char *argv[]) { 21 | int total = 0; 22 | 23 | for (int number = 2; number <= 20; number += 2) { 24 | total += number; 25 | } 26 | 27 | std::cout << "Sum is " << total << std::endl; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Chapter05/examples/5.07/fig05_07.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig05_07.cpp 5 | * 6 | * Description: Fig. 5.7: do...while repetition statement 7 | * 8 | * Version: 1.0 9 | * Created: 04/04/16 16:48:50 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int main(int argc, const char *argv[]) { 21 | int counter = 1; 22 | 23 | do { 24 | std::cout << counter << " "; 25 | ++counter; 26 | } while (counter <= 10); 27 | 28 | std::cout << std::endl; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Chapter05/examples/5.09/fig05_11.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig05_11.cpp 5 | * 6 | * Description: Fig. 5.11: Create GradeBook object, input grades and display 7 | * grade report. 8 | * 9 | * Version: 1.0 10 | * Created: 04/04/16 17:04:22 11 | * Revision: none 12 | * Compiler: g++ 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include "GradeBook.hpp" 20 | 21 | int main(int argc, const char *argv[]) { 22 | GradeBook myGradeBook("CS101 C++ Programming"); 23 | 24 | myGradeBook.displayMessage(); 25 | myGradeBook.inputGrades(); 26 | myGradeBook.displayGradeReport(); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Chapter05/examples/5.13/fig05_13.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig05_13.cpp 5 | * 6 | * Description: Fig. 5.13: Break statement exiting a for statement 7 | * 8 | * Version: 1.0 9 | * Created: 04/04/16 17:07:27 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int main(int argc, const char *argv[]) { 21 | int count; 22 | 23 | for (count = 1; count <= 10; ++count) { 24 | if (count == 5) { break; } 25 | 26 | std::cout << count << " "; 27 | } 28 | 29 | std::cout << "\nBroke out of loop at count = " << count << std::endl; 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Chapter05/exercises/5.05/ex_505.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_505.cpp 5 | * 6 | * Description: Exercise 5.05 - Summing Integers 7 | * 8 | * Version: 1.0 9 | * Created: 04/04/16 17:13:33 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int main(int argc, const char *argv[]) { 21 | int limit, num, total = 0; 22 | 23 | std::cout << "Enter number of values to be summed followed by values: "; 24 | std::cin >> limit; 25 | 26 | for (int i = 1; i <= limit; i++) { 27 | std::cin >> num; 28 | total += num; 29 | } 30 | 31 | std::cout << "Total = " << total << std::endl; 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Chapter05/exercises/5.09/ex_509.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_509.cpp 5 | * 6 | * Description: Exercise 5.09 - Product of Odd Integers 7 | * 8 | * Version: 1.0 9 | * Created: 04/04/16 18:05:51 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int main(int argc, const char *argv[]) { 21 | int product = 1; 22 | 23 | std::cout << "Product of odd integers 1 to 15: "; 24 | 25 | for (int i = 1; i <= 15; i += 2) { 26 | product *= i; 27 | } 28 | 29 | std::cout << product << std::endl; 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Chapter05/exercises/5.15/ex_515.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_515.cpp 5 | * 6 | * Description: Exercise 5.15 - GradeBook Modification 7 | * 8 | * Version: 1.0 9 | * Created: 05/04/16 17:31:54 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "GradeBook.hpp" 19 | 20 | int main(int argc, const char *argv[]) { 21 | GradeBook myGradeBook("Course Name"); 22 | 23 | myGradeBook.displayMessage(); 24 | myGradeBook.inputGrades(); 25 | myGradeBook.displayGradeReport(); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Chapter05/exercises/5.18/ex_518.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_518.cpp 5 | * 6 | * Description: Exercise 5.18 - Number Systems Table 7 | * 8 | * Version: 1.0 9 | * Created: 05/04/16 18:02:07 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int main(int argc, const char *argv[]) { 21 | std::cout << "Binary\tOctal\tHexadecimal\n"; 22 | 23 | for (int i = 1; i <= 256; i++) { 24 | std::cout << std::dec << i << "\t" << std::oct << i << "\t" << std::hex 25 | << i << std::endl; 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Chapter05/exercises/5.21/ex_521.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_521.cpp 5 | * 6 | * Description: Exercise 5.21 - Calculating Salaries 7 | * 8 | * Version: 1.0 9 | * Created: 07/04/16 18:05:25 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "SalaryCalculator.hpp" 19 | 20 | int main(int argc, const char *argv[]) { 21 | SalaryCalculator sc; 22 | 23 | sc.inputSalaries(); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Chapter05/exercises/5.23/ex_523.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_523.cpp 5 | * 6 | * Description: Exercise 5.23 - Diamond of Asterisks 7 | * 8 | * Version: 1.0 9 | * Created: 07/04/16 19:41:13 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int main(int argc, const char *argv[]) { 21 | // i = rows, j = diamonds, k = spaces 22 | for (int i = 1, j = 1, k = 4; i <= 9; i++) { 23 | for (int s = 0; s < k; s++) { 24 | std::cout << " "; 25 | } 26 | for (int d = 0; d < j; d++) { 27 | std::cout << "*"; 28 | } 29 | 30 | (i >= 5) ? j -= 2 : j += 2; 31 | (i >= 5) ? k++ : k--; 32 | 33 | std::cout << std::endl; 34 | } 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Chapter05/exercises/5.25/ex_525.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: ex_525.cpp 5 | * 6 | * Description: Exercise 5.25 - Removing Break and Continue. 7 | * 8 | * Version: 1.0 9 | * Created: 09/02/18 04:16:22 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ============================================================================= 17 | */ 18 | #include 19 | 20 | /** 21 | * This is the main method. 22 | * @param argc. 23 | * @param argv[]. 24 | * @return int. 25 | */ 26 | int main(int argc, char* argv[]) { 27 | int count = 1; 28 | bool exit = false; 29 | 30 | while (!exit) { 31 | std::cout << count++ << " "; 32 | 33 | exit = (count == 5); 34 | } 35 | 36 | std::cout << "\nBroke out of loop at count = " << count << std::endl; 37 | 38 | return 0; 39 | } // end method main 40 | -------------------------------------------------------------------------------- /Chapter05/exercises/5.27/ex_527.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: ex_527.cpp 5 | * 6 | * Description: Exercise 5.27 - Removing the Continue Statement. 7 | * 8 | * Version: 1.0 9 | * Created: 09/02/18 04:25:01 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ============================================================================= 17 | */ 18 | #include 19 | 20 | /** 21 | * This is the main method. 22 | * @param argc. 23 | * @param argv[]. 24 | * @return int. 25 | */ 26 | int main(int argc, char* argv[]) { 27 | for (int count = 1; count <= 10; ++count) { 28 | if (count != 5) { 29 | std::cout << count << ' '; 30 | } 31 | } 32 | 33 | std::cout << "\nSkipped printing 5 without continue" << std::endl; 34 | 35 | return 0; 36 | } // end method main 37 | -------------------------------------------------------------------------------- /Chapter05/exercises/5.30/ex_530.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_530.cpp 5 | * 6 | * Description: Exercise 5.30 - Global Warming Facts Quiz 7 | * 8 | * Version: 1.0 9 | * Created: 08/04/16 16:08:46 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "Quiz.hpp" 19 | 20 | int main(int argc, const char *argv[]) { 21 | Quiz q; 22 | 23 | q.run(); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Chapter06/README.md: -------------------------------------------------------------------------------- 1 | #### Chapter 6 Incomplete Solutions 2 | 3 | *If you have a solution feel free to contribute* 4 | 5 | - [6.38](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter06/exercises/6.38/) - *Towers of Hanoi* 6 | - [6.39](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter06/exercises/6.39/) - *Towers of Hanoi: Iterative Version* 7 | -------------------------------------------------------------------------------- /Chapter06/examples/6.03/fig06_05.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig06_05.cpp 5 | * 6 | * Description: Fig. 6.5: Create GradeBook object, intput grades and display 7 | * grade report. 8 | * 9 | * Version: 1.0 10 | * Created: 11/04/16 10:30:12 11 | * Revision: none 12 | * Compiler: g++ 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include "GradeBook.hpp" 20 | 21 | int main(int argc, const char *argv[]) { 22 | GradeBook myGradeBook("CS101 C++ Programming"); 23 | 24 | myGradeBook.displayMessage(); 25 | myGradeBook.inputGrades(); 26 | myGradeBook.displayGradeReport(); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Chapter06/examples/6.08/fig06_08.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig06_08.cpp 5 | * 6 | * Description: Fig. 6.8: Shifted and scaled random integers 7 | * 8 | * Version: 1.0 9 | * Created: 11/04/16 11:21:45 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | #include 20 | #include 21 | 22 | int main(int argc, const char *argv[]) { 23 | for (int counter = 1; counter <= 20; ++counter) { 24 | std::cout << std::setw(10) << (1 + rand() % 6); 25 | 26 | // if counter divisible by 5, start a new line of output 27 | if (counter % 5 == 0) { 28 | std::cout << std::endl; 29 | } 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Chapter06/examples/6.10/fig06_10.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig06_10.cpp 5 | * 6 | * Description: Fig. 6.10: Randomizing the die-rolling program 7 | * 8 | * Version: 1.0 9 | * Created: 11/04/16 11:34:18 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | #include 20 | #include 21 | 22 | int main(int argc, const char *argv[]) { 23 | unsigned seed; 24 | 25 | std::cout << "Enter seed: "; 26 | std::cin >> seed; 27 | 28 | srand(seed); 29 | 30 | for (int counter = 0; counter <= 10; ++counter) { 31 | std::cout << std::setw(10) << (1 + rand() % 6); 32 | 33 | if (counter % 5 == 0) { 34 | std::cout << std::endl; 35 | } 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Chapter06/examples/6.13/fig06_13.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig06_13.cpp 5 | * 6 | * Description: Fig. 6.13: Square function used to demonstrate the function 7 | * call stack and activation records. 8 | * 9 | * Version: 1.0 10 | * Created: 11/04/16 13:34:36 11 | * Revision: none 12 | * Compiler: g++ 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include 20 | 21 | int square(int); 22 | 23 | int main(int argc, const char *argv[]) { 24 | int a = 10; // value to square (local automatic variable in main) 25 | 26 | std::cout << a << " squared: " << square(a) << std::endl; 27 | return 0; 28 | } 29 | // returns the square of an integer 30 | int square(int x) { // x is a local variable 31 | return x * x; 32 | } 33 | -------------------------------------------------------------------------------- /Chapter06/examples/6.20/fig06_20.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig06_20.cpp 5 | * 6 | * Description: Fig. 6.20: Initializing and using a reference. 7 | * 8 | * Version: 1.0 9 | * Created: 11/04/16 14:10:58 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int main(int argc, const char* argv[]) { 21 | int x = 3; 22 | int& y = x; 23 | 24 | std::cout << "x = " << x << std::endl << "y = " << y << std::endl; 25 | 26 | y = 7; // modifies x 27 | 28 | std::cout << "x = " << x << std::endl << "y = " << y << std::endl; 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Chapter06/examples/6.21/fig06_21.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig06_21.cpp 5 | * 6 | * Description: Fig. 6.21: References must be initialised 7 | * 8 | * Version: 1.0 9 | * Created: 11/04/16 14:12:38 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int main(int argc, const char* argv[]) { 21 | int x = 3; 22 | int& y; // Error y must be initialised 23 | 24 | std::cout << "x = " << x << std::endl << "y = " << y << std::endl; 25 | y = 7; 26 | std::cout << "x = " << x << std::endl << "y = " << y << std::endl; 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Chapter06/examples/6.23/fig06_23.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig06_23.cpp 5 | * 6 | * Description: Fig. 6.23: Using the unary scope resolution operator 7 | * 8 | * Version: 1.0 9 | * Created: 11/04/16 16:06:25 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int number = 7; // global variable named number 21 | 22 | int main(int argc, const char *argv[]) { 23 | double number = 10.0f; // local variable named number 24 | 25 | std::cout << "Local double value of number = " << number 26 | << "\nGlobal int value of number = " << ::number << std::endl; 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Chapter06/examples/6.24/fig06_24.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig06_24.cpp 5 | * 6 | * Description: Fig. 6.24: Overloaded functions 7 | * 8 | * Version: 1.0 9 | * Created: 11/04/16 16:11:35 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int square(int x) { 21 | std::cout << "square of integer " << x << " is "; 22 | return x * x; 23 | } 24 | double square(double y) { 25 | std::cout << "square of double " << y << " is "; 26 | return y * y; 27 | } 28 | int main(int argc, const char *argv[]) { 29 | std::cout << square(7); 30 | std::cout << std::endl; 31 | 32 | std::cout << square(7.5); 33 | std::cout << std::endl; 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Chapter06/examples/6.25/fig06_25.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig06_25.cpp 5 | * 6 | * Description: Fig. 6.25: Name mangling 7 | * 8 | * Version: 1.0 9 | * Created: 11/04/16 16:14:53 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | int square(int x) { return x * x; } 19 | double square(double y) { return y * y; } 20 | void nothing1(int a, float b, char c, int& d) {} 21 | int nothing2(char a, int b, float& c, double& d) { return 0; } 22 | int main(int argc, const char* argv[]) { return 0; } 23 | -------------------------------------------------------------------------------- /Chapter06/examples/6.26/maximum.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: maximum.hpp 5 | * 6 | * Description: Fig. 6.26: Definition of function type maximum 7 | * 8 | * Version: 1.0 9 | * Created: 11/04/16 16:40:26 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | template 21 | 22 | T maximum(T value1, T value2, T value3) { 23 | T maximumValue = value1; 24 | 25 | if (value2 > maximumValue) { 26 | maximumValue = value2; 27 | } 28 | 29 | if (value3 > maximumValue) { 30 | maximumValue = value3; 31 | } 32 | 33 | return maximumValue; 34 | } 35 | -------------------------------------------------------------------------------- /Chapter06/exercises/6.34/ex_634.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_634.cpp 5 | * 6 | * Description: Exercise 6.34 - Guess-the-Number Game 7 | * 8 | * Version: 1.0 9 | * Created: 15/04/16 13:59:48 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "GuessTheNumber.hpp" 19 | 20 | int main(int argc, const char *argv[]) { 21 | GuessTheNumber gtn; 22 | 23 | gtn.run(); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Chapter06/exercises/6.35/ex_635.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_635.cpp 5 | * 6 | * Description: Exercise 6.35 - Guess-the-Number Game Modification 7 | * 8 | * Version: 1.1 9 | * Created: 15/04/16 13:59:48 10 | * Revision: 15/04/16 14:53:09 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "GuessTheNumber.hpp" 19 | 20 | int main(int argc, const char *argv[]) { 21 | GuessTheNumber gtn; 22 | 23 | gtn.run(); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Chapter06/exercises/6.38/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter06/exercises/6.38/empty -------------------------------------------------------------------------------- /Chapter06/exercises/6.39/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter06/exercises/6.39/empty -------------------------------------------------------------------------------- /Chapter06/exercises/6.42/ex_642.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_642.cpp 5 | * 6 | * Description: Exercise 6.42 - Recursive Main 7 | * 8 | * Version: 1.0 9 | * Created: 15/04/16 17:12:35 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int main() { 21 | static int count = 1; 22 | 23 | std::cout << count++ << std::endl; 24 | 25 | main(); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Chapter06/exercises/6.49/ex_649.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_649.cpp 5 | * 6 | * Description: Exercise 6.49 - Craps Game Modification 7 | * 8 | * Version: 1.1 9 | * Created: 11/04/16 11:39:25 10 | * Revision: 15/04/16 17:29:39 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "Craps.hpp" 19 | 20 | int main(int argc, const char *argv[]) { 21 | Craps craps; 22 | 23 | craps.run(); 24 | } 25 | -------------------------------------------------------------------------------- /Chapter06/exercises/6.56/ex_656.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_656.cpp 5 | * 6 | * Description: Exercise 6.56-60 - Computer-Assisted Instruction 7 | * 8 | * Version: 1.0 9 | * Created: 16/04/16 15:26:05 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | #include "CAI.hpp" 21 | 22 | int main(int argc, const char *argv[]) { 23 | CAI cai; 24 | 25 | cai.run(); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Chapter07/README.md: -------------------------------------------------------------------------------- 1 | #### Chapter 7 Incomplete Solutions 2 | 3 | *If you have a solution feel free to contribute* 4 | 5 | - [7.19](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter07/exercises/7.19/) - *Craps Game Modification* 6 | - [7.24](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter07/exercises/7.24/) - *Knight's Tour* 7 | - [7.25](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter07/exercises/7.25/) - *Knight's Tour: Brute Force Approach* 8 | - [7.26](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter07/exercises/7.26/) - *Eight Queens* 9 | - [7.27](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter07/exercises/7.27/) - *Eight Queens: Brute Force Approach* 10 | - [7.28](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter07/exercises/7.28/) - *Knight's Tour: Closed-Tour Test* 11 | - [7.34](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter07/exercises/7.34/) - *Eight Queens* 12 | -------------------------------------------------------------------------------- /Chapter07/examples/7.03/fig07_03.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig07_03.cpp 5 | * 6 | * Description: Fig. 7.3: Initializing an array's elements to zeros and 7 | * printing the array. 8 | * 9 | * Version: 1.0 10 | * Created: 18/04/16 19:26:09 11 | * Revision: none 12 | * Compiler: g++ 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include 20 | #include 21 | 22 | int main(int argc, const char *argv[]) { 23 | int n[10]; 24 | 25 | for (int i = 0; i < 10; ++i) { 26 | n[i] = 0; 27 | } 28 | 29 | std::cout << "Element" << std::setw(13) << "Value" << std::endl; 30 | 31 | for (int i = 0; i < 10; ++i) { 32 | std::cout << std::setw(7) << i << std::setw(13) << n[i] << std::endl; 33 | } 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Chapter07/examples/7.04/fig07_04.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig07_04.cpp 5 | * 6 | * Description: Fig. 7.4: Initializing an array in a declaration. 7 | * 8 | * Version: 1.0 9 | * Created: 18/04/16 19:29:12 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | #include 20 | 21 | int main(int argc, const char *argv[]) { 22 | int n[10] = {32, 27, 64, 18, 95, 14, 90, 70, 60, 37}; 23 | 24 | std::cout << "Element" << std::setw(13) << "Value" << std::endl; 25 | 26 | for (int i = 0; i < 10; ++i) { 27 | std::cout << std::setw(7) << i << std::setw(13) << n[i] << std::endl; 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Chapter07/examples/7.05/fig07_05.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig07_05.cpp 5 | * 6 | * Description: Fig. 7.5: Set array s to the even integers from 2 to 20. 7 | * 8 | * Version: 1.0 9 | * Created: 18/04/16 19:31:40 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | #include 20 | 21 | int main(int argc, const char *argv[]) { 22 | const int arraySize = 10; 23 | 24 | int s[arraySize]; 25 | 26 | for (int i = 0; i < arraySize; ++i) { 27 | s[i] = 2 + 2 * i; 28 | } 29 | 30 | std::cout << "Element" << std::setw(13) << "Value" << std::endl; 31 | 32 | for (int i = 0; i < arraySize; ++i) { 33 | std::cout << std::setw(7) << i << std::setw(13) << s[i] << std::endl; 34 | } 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Chapter07/examples/7.08/fig07_08.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig07_08.cpp 5 | * 6 | * Description: Fig. 7.8: compute the sum of the elements of the array. 7 | * 8 | * Version: 1.0 9 | * Created: 18/04/16 19:39:22 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int main(int argc, const char *argv[]) { 21 | const int arraySize = 10; 22 | 23 | int a[arraySize] = {87, 68, 94, 100, 83, 78, 85, 91, 76, 87}; 24 | int total = 0; 25 | 26 | for (int i = 0; i < arraySize; ++i) { 27 | total += a[i]; 28 | } 29 | 30 | std::cout << "Total of array elements: " << total << std::endl; 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Chapter07/examples/7.14/fig07_14.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig07_14.cpp 5 | * 6 | * Description: Fig. 7.14: Demonstrating the const qualifier. 7 | * 8 | * Version: 1.0 9 | * Created: 19/04/16 13:46:28 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | void tryToModifyArray(const int[]); 21 | 22 | int main(int argc, const char *argv[]) { 23 | int a[] = {10, 20, 30}; 24 | 25 | tryToModifyArray(a); 26 | 27 | std::cout << a[0] << ' ' << a[1] << ' ' << a[2] << std::endl; 28 | 29 | return 0; 30 | } 31 | // In function tryToModifyArray, "b" cannot be used to modify the original array 32 | // "a" in main 33 | void tryToModifyArray(const int b[]) { 34 | b[0] /= 2; // compilation error 35 | } 36 | -------------------------------------------------------------------------------- /Chapter07/examples/7.15/fig07_17.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig07_17.cpp 5 | * 6 | * Description: Fig. 7.17: Creates GradeBook object using an array of 7 | * grades. 8 | * 9 | * Version: 1.0 10 | * Created: 19/04/16 19:09:57 11 | * Revision: none 12 | * Compiler: g++ 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include "GradeBook.hpp" 20 | 21 | int main(int argc, const char *argv[]) { 22 | int gradesArray[GradeBook::students] = {87, 68, 94, 100, 83, 23 | 78, 85, 91, 76, 87}; 24 | 25 | GradeBook myGradeBook("CS101 Introduction to C++ Programming", gradesArray); 26 | 27 | myGradeBook.displayMessage(); 28 | myGradeBook.processGrades(); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Chapter07/exercises/7.19/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter07/exercises/7.19/empty -------------------------------------------------------------------------------- /Chapter07/exercises/7.20/ex_720.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_720.cpp 5 | * 6 | * Description: Exercise 7.20 - Airline Reservation System 7 | * 8 | * Version: 1.0 9 | * Created: 22/04/16 14:44:44 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "ReservationSystem.hpp" 19 | 20 | int main(int argc, const char *argv[]) { 21 | ReservationSystem res; 22 | 23 | res.go(); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Chapter07/exercises/7.23/ex_723.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_723.cpp 5 | * 6 | * Description: Exercise 7.23 - Turtle Graphics 7 | * 8 | * Version: 1.0 9 | * Created: 25/04/16 12:13:50 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "Turtle.hpp" 19 | 20 | int main(int argc, const char *argv[]) { 21 | Turtle turtle; 22 | 23 | turtle.go(); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Chapter07/exercises/7.24/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter07/exercises/7.24/empty -------------------------------------------------------------------------------- /Chapter07/exercises/7.25/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter07/exercises/7.25/empty -------------------------------------------------------------------------------- /Chapter07/exercises/7.26/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter07/exercises/7.26/empty -------------------------------------------------------------------------------- /Chapter07/exercises/7.27/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter07/exercises/7.27/empty -------------------------------------------------------------------------------- /Chapter07/exercises/7.28/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter07/exercises/7.28/empty -------------------------------------------------------------------------------- /Chapter07/exercises/7.34/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter07/exercises/7.34/empty -------------------------------------------------------------------------------- /Chapter07/exercises/7.41/Poll.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Poll.hpp 5 | * 6 | * Description: Exercise 7.41 - Polling 7 | * 8 | * Version: 1.0 9 | * Created: 26/04/16 16:28:16 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | class Poll { 25 | private: 26 | static const size_t TOPICS = 5; 27 | static const size_t RESPONSES = 10; 28 | 29 | std::string topics[TOPICS]; 30 | int responses[TOPICS][RESPONSES]; 31 | 32 | public: 33 | Poll(); 34 | ~Poll() {} 35 | 36 | void initialise(); 37 | void go(); 38 | void askPoll(); 39 | void printResults(); 40 | }; 41 | -------------------------------------------------------------------------------- /Chapter07/exercises/7.41/ex_741.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_741.cpp 5 | * 6 | * Description: Exercise 7.41 - Polling 7 | * 8 | * Version: 1.0 9 | * Created: 26/04/16 16:23:22 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "Poll.hpp" 19 | 20 | int main(int argc, const char *argv[]) { 21 | Poll poll; 22 | 23 | poll.go(); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Chapter08/README.md: -------------------------------------------------------------------------------- 1 | #### Chapter 8 Incomplete Solutions 2 | 3 | *If you have a solution feel free to contribute* 4 | 5 | - [8.17](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter08/exercises/8.17/) - *Generating Mazes Randomly* 6 | -------------------------------------------------------------------------------- /Chapter08/examples/8.06/fig08_06.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig08_06.cpp 5 | * 6 | * Description: Fig. 8.6: Pass-by-value used to cube a variable's value 7 | * 8 | * Version: 1.0 9 | * Created: 29/04/16 16:31:04 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int cubeByValue(int); 21 | 22 | int main(int argc, const char *argv[]) { 23 | int number = 5; 24 | 25 | std::cout << "The original value of number is " << number; 26 | 27 | number = cubeByValue(number); 28 | 29 | std::cout << "\nThe new value of number is " << number << std::endl; 30 | return 0; 31 | } 32 | // calculate and return cube of integer argument 33 | int cubeByValue(int n) { return n * n * n; } 34 | -------------------------------------------------------------------------------- /Chapter08/examples/8.10/fig08_10.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig08_10.cpp 5 | * 6 | * Description: Fig. 8.10: Nonconstant Pointer to Constant Data. 7 | * Attempting to modify data through a nonconstant pointer 8 | * to constant data. 9 | * 10 | * Version: 1.0 11 | * Created: 04/05/16 19:02:49 12 | * Revision: none 13 | * Compiler: g++ 14 | * 15 | * Author: Siidney Watson - siidney.watson.work@gmail.com 16 | * Organization: LolaDog Studio 17 | * 18 | * ===================================================================================== 19 | */ 20 | void f(const int *); 21 | 22 | int main(int argc, const char *argv[]) { 23 | int y; 24 | 25 | f(&y); 26 | 27 | return 0; 28 | } 29 | // xPtr cannot modify the value of constant variable to which it points 30 | void f(const int *xPtr) { 31 | *xPtr = 100; // error: cannot modify a const object 32 | } 33 | -------------------------------------------------------------------------------- /Chapter08/examples/8.11/fig08_11.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig08_11.cpp 5 | * 6 | * Description: Fig. 8.11: Constant Pointer to Nonconstant Data 7 | * Attempting to modify a constant pointer to nonconstant data. 8 | * 9 | * Version: 1.0 10 | * Created: 04/05/16 19:12:15 11 | * Revision: none 12 | * Compiler: g++ 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | 20 | int main(int argc, const char* argv[]) { 21 | int x, y; 22 | 23 | // ptr is a constant pointer to an integer that can be modified through ptr, 24 | // but ptr always points to the same memory location. 25 | int* const ptr = &x; 26 | 27 | *ptr = 7; // allowed: *ptr is not const 28 | ptr = &y; // error: ptr is const; cannot assign it to a new address 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Chapter08/exercises/8.12/ex_812.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_812.cpp 5 | * 6 | * Description: Exercise 8.12 - Simulation: The Tortoise and the Hare 7 | * 8 | * Version: 1.0 9 | * Created: 06/05/16 18:04:26 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "TortoiseAndHare.hpp" 19 | 20 | int main(int argc, const char *argv[]) { 21 | TortoiseAndHare th; 22 | 23 | th.go(); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Chapter08/exercises/8.16/ex_816.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: ex_816.cpp 5 | * 6 | * Description: Exercise 8.16 - Maze Traversal 7 | * 8 | * Version: 1.0 9 | * Created: 13/02/18 04:05:58 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ============================================================================= 17 | */ 18 | #include "Maze.hpp" 19 | 20 | /** 21 | * This is the main method. 22 | * @param argc. 23 | * @param argv[]. 24 | * @return int. 25 | */ 26 | int main(int argc, char* argv[]) { 27 | Maze maze("levels/level2"); 28 | 29 | maze.go(); 30 | 31 | return 0; 32 | } // end method main 33 | -------------------------------------------------------------------------------- /Chapter08/exercises/8.16/levels/level1: -------------------------------------------------------------------------------- 1 | 12 12 2 | ############ 3 | #...#......# 4 | X.#.#.####.# 5 | ###.#....#.# 6 | #....###.#.@ 7 | ####.#.#.#.# 8 | #..#.#.#.#.# 9 | ##.#.#.#.#.# 10 | #........#.# 11 | ######.###.# 12 | #......#...# 13 | ############ 14 | -------------------------------------------------------------------------------- /Chapter08/exercises/8.16/levels/level2: -------------------------------------------------------------------------------- 1 | 12 12 2 | ############ 3 | #...#......# 4 | X.#.#.####.# 5 | ###.#....#.# 6 | #....###.#.# 7 | ####.#.#.#.# 8 | #..#.#.#.#.# 9 | ##.#.#.#.#.# 10 | #........#.# 11 | ######.###.# 12 | #......#...# 13 | ########@### 14 | -------------------------------------------------------------------------------- /Chapter08/exercises/8.17/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter08/exercises/8.17/empty -------------------------------------------------------------------------------- /Chapter08/exercises/8.18/ex_818.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_818.cpp 5 | * 6 | * Description: Exercise 8.18 - Machine Language Programming 7 | * 8 | * Version: 1.0 9 | * Created: 03/06/16 15:14:08 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "Simpletron.hpp" 19 | 20 | int main(int argc, const char *argv[]) { 21 | Simpletron s; 22 | 23 | s.go(); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Chapter08/exercises/8.19/ex_819.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_819.cpp 5 | * 6 | * Description: Exercise 8.19 - Computer Simulator 7 | * 8 | * Version: 1.0 9 | * Created: 05/06/16 12:07:38 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "Simpletron.hpp" 19 | 20 | int main(int argc, const char *argv[]) { 21 | Simpletron s; 22 | 23 | s.go(); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Chapter08/exercises/8.20/README.md: -------------------------------------------------------------------------------- 1 | This is complete except for F (process floats). I cannot fathom a way to reliably process 2 | floating point values in addition to integers. 3 | 4 | Will return to this at a later date. 5 | -------------------------------------------------------------------------------- /Chapter08/exercises/8.20/ex_820.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_820.cpp 5 | * 6 | * Description: Exercise 8.20 - Project Modification to the Simpletron 7 | * Simulator. 8 | * 9 | * Version: 1.0 10 | * Created: 05/06/16 19:11:26 11 | * Revision: none 12 | * Compiler: g++ 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include "Simpletron.hpp" 20 | 21 | int main(int argc, const char *argv[]) { 22 | Simpletron s; 23 | 24 | s.go(); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Chapter09/README.md: -------------------------------------------------------------------------------- 1 | #### Chapter 9 Incomplete Solutions 2 | 3 | *If you have a solution feel free to contribute* 4 | 5 | - [9.10](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter09/exercises/9.10/) - *Returning Error Indicators from Class Time's set Functions* 6 | - [9.13](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter09/exercises/9.13/) - *Enhancing Class __Rectangle__* 7 | -------------------------------------------------------------------------------- /Chapter09/examples/9.01/Time.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Time.h 5 | * 6 | * Description: Fig. 9.1: Time class definition 7 | * 8 | * Version: 1.0 9 | * Created: 07/06/16 15:03:26 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | class Time { 21 | private: 22 | int hour; // 0-23 (24-hour format) 23 | int minute; // 0-59 24 | int second; // 0-59 25 | 26 | public: 27 | Time(); 28 | 29 | void setTime(int, int, int); // set hour minute second 30 | void printUniversal(); // print time in universal time format 31 | void printStandard(); // print time in standard time format 32 | }; 33 | -------------------------------------------------------------------------------- /Chapter09/examples/9.05/SalesPerson.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: SalesPerson.h 5 | * 6 | * Description: Fig. 9.5: SalesPerson class definition 7 | * 8 | * Version: 1.0 9 | * Created: 07/06/16 16:33:43 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | class SalesPerson { 21 | public: 22 | static const int monthsPerYear = 12; 23 | 24 | SalesPerson(); 25 | 26 | void getSalesFromUser(); 27 | void setSales(int, double); 28 | void printAnnualSales(); 29 | 30 | private: 31 | double totalAnnualSales(); 32 | double sales[monthsPerYear]; 33 | }; 34 | -------------------------------------------------------------------------------- /Chapter09/examples/9.05/fig09_07.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig09_07.cpp 5 | * 6 | * Description: Fig. 9.7: Utility function demonstration 7 | * 8 | * Version: 1.0 9 | * Created: 07/06/16 16:44:07 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "SalesPerson.hpp" 19 | 20 | int main(int argc, const char *argv[]) { 21 | SalesPerson s; 22 | 23 | s.getSalesFromUser(); 24 | s.printAnnualSales(); 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Chapter09/examples/9.11/CreateAndDestroy.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: CreateAndDestroy.h 5 | * 6 | * Description: Fig. 9.11: CreateAndDestroy class definition. 7 | * 8 | * Version: 1.0 9 | * Created: 08/06/16 14:54:42 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | class CreateAndDestroy { 24 | private: 25 | int objectID; 26 | std::string message; 27 | 28 | public: 29 | CreateAndDestroy(int, std::string); 30 | ~CreateAndDestroy(); 31 | }; 32 | -------------------------------------------------------------------------------- /Chapter09/examples/9.14/Time.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Time.h 5 | * 6 | * Description: Fig. 9.14: Time class declaration 7 | * 8 | * Version: 1.0 9 | * Created: 08/06/16 19:50:57 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include 21 | 22 | class Time { 23 | private: 24 | int hour; 25 | int minute; 26 | int second; 27 | 28 | public: 29 | Time(int = 0, int = 0, int = 0); 30 | ; 31 | 32 | void setTime(int, int, int); 33 | int &badSetHour(int); // dangerous reference return 34 | 35 | int getHour(); 36 | }; 37 | -------------------------------------------------------------------------------- /Chapter09/examples/9.17/Date.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Date.cpp 5 | * 6 | * Description: Fig. 9.18: Date class member-function definitions 7 | * 8 | * Version: 1.0 9 | * Created: 09/06/16 13:40:10 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "Date.hpp" 19 | 20 | #include 21 | 22 | // date constructor (should do range checking) 23 | Date::Date(int m, int d, int y) { 24 | month = m; 25 | day = d; 26 | year = y; 27 | } 28 | // print date in format mm/dd/yyyy 29 | void Date::print() { std::cout << month << "/" << day << "/" << year; } 30 | -------------------------------------------------------------------------------- /Chapter09/examples/9.17/Date.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Date.h 5 | * 6 | * Description: Fig. 9.17: Date class declaration 7 | * 8 | * Version: 1.0 9 | * Created: 09/06/16 13:38:18 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | class Date { 21 | public: 22 | Date(int = 1, int = 1, int = 2000); 23 | 24 | void print(); 25 | 26 | private: 27 | int month; 28 | int day; 29 | int year; 30 | }; 31 | -------------------------------------------------------------------------------- /Chapter09/exercises/9.04/Time.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Time.hpp 5 | * 6 | * Description: Exercise 9.4 - Enhancing Time Class 7 | * 8 | * Version: 1.1 9 | * Created: 07/06/16 16:48:11 10 | * Revision: 09/06/16 14:09:07 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | class Time { 21 | private: 22 | int hour; 23 | int minute; 24 | int second; 25 | 26 | public: 27 | Time(); 28 | Time(int, int, int); 29 | 30 | // SETTERS 31 | void setTime(int, int, int); 32 | void setHour(int); 33 | void setMinute(int); 34 | void setSecond(int); 35 | 36 | // GETTERS 37 | int getHour(); 38 | int getMinute(); 39 | int getSecond(); 40 | 41 | void printUniversal(); 42 | void printStandard(); 43 | }; 44 | -------------------------------------------------------------------------------- /Chapter09/exercises/9.04/ex_904.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_904.cpp 5 | * 6 | * Description: Exercise 9.04 - Enhancing Time Class 7 | * 8 | * Version: 1.0 9 | * Created: 09/06/16 13:52:06 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | #include "Time.hpp" 21 | 22 | int main(int argc, const char *argv[]) { 23 | Time time1; 24 | Time time2(12, 12, 12); 25 | 26 | std::cout << "time1: "; 27 | time1.printUniversal(); 28 | std::cout << std::endl; 29 | time1.printStandard(); 30 | 31 | std::cout << "\n\ntime2: "; 32 | time2.printUniversal(); 33 | std::cout << std::endl; 34 | time2.printStandard(); 35 | std::cout << std::endl; 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Chapter09/exercises/9.05/Complex.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Complex.cpp 5 | * 6 | * Description: Exercise 9.05 - Complex Class 7 | * Complex number class representation 8 | * 9 | * Version: 1.0 10 | * Created: 09/06/16 14:42:36 11 | * Revision: none 12 | * Compiler: g++ 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include "Complex.hpp" 20 | 21 | Complex::Complex(double r, double i) { 22 | real = r; 23 | imaginary = i; 24 | } 25 | Complex::~Complex() {} 26 | // print complex number 27 | std::ostream& Complex::printComplex(std::ostream& out) { 28 | out << "(" << real << "," << imaginary << ")"; 29 | return out; 30 | } 31 | -------------------------------------------------------------------------------- /Chapter09/exercises/9.05/ex_905.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_905.cpp 5 | * 6 | * Description: Exercise 9.5 - Complex Class 7 | * 8 | * Version: 1.0 9 | * Created: 09/06/16 14:45:20 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "Complex.hpp" 19 | 20 | int main(int argc, const char *argv[]) { 21 | Complex c1; 22 | Complex c2(123, 456); 23 | 24 | Complex c3 = (c1 + c2); 25 | 26 | std::cout << "c1: " << c1 << "\nc2: " << c2 << "\nc3: " << c3 << std::endl; 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Chapter09/exercises/9.06/ex_906.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_906.cpp 5 | * 6 | * Description: Exercise 9.06 - Rational Class 7 | * 8 | * Version: 1.0 9 | * Created: 09/06/16 14:53:11 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "Rational.hpp" 19 | 20 | int main(int argc, const char *argv[]) { 21 | Rational r1; 22 | Rational r2(25, 50); 23 | 24 | std::cout << "r1: " << r1 << "\nr2: " << r2 << std::endl; 25 | 26 | Rational r3 = (r1 + r2); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Chapter09/exercises/9.08/ex_908.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_908.cpp 5 | * 6 | * Description: Exercise 9.08 - Enhancing Class Date 7 | * 8 | * Version: 1.0 9 | * Created: 09/06/16 16:10:28 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | #include "Date.hpp" 21 | 22 | int main(int argc, const char *argv[]) { 23 | Date d1(11, 30, 2015); 24 | 25 | for (int i = 0; i < 365; ++i) { 26 | d1.nextDay(); 27 | 28 | std::cout << d1 << std::endl; 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Chapter09/exercises/9.09/ex_909.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_909.cpp 5 | * 6 | * Description: Exercise 9.9 - Combining Class Time and Class Date 7 | * 8 | * Version: 1.0 9 | * Created: 09/06/16 16:56:49 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "DateAndTime.hpp" 19 | 20 | #include 21 | 22 | int main(int argc, const char *argv[]) { 23 | DateAndTime dt(1, 1, 2000, 23, 59, 59); 24 | 25 | std::cout << dt << std::endl; 26 | 27 | for (int i = 0; i < 10000; ++i) { 28 | dt.tick(); 29 | 30 | std::cout << dt << std::endl; 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Chapter09/exercises/9.10/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter09/exercises/9.10/empty -------------------------------------------------------------------------------- /Chapter09/exercises/9.11/Rectangle.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Rectangle.hpp 5 | * 6 | * Description: Exercise 9.11 - Rectangle Class 7 | * 8 | * Version: 1.0 9 | * Created: 09/06/16 17:27:54 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | class Rectangle { 21 | public: 22 | explicit Rectangle(double = 1.0f, double = 1.0f); 23 | 24 | // SETTERS 25 | void setLength(double); 26 | void setWidth(double); 27 | 28 | // GETTERS 29 | double getLength() { return length; } 30 | double getWidth() { return width; } 31 | double getPerimeter(); 32 | double getArea(); 33 | 34 | private: 35 | double length; 36 | double width; 37 | }; 38 | -------------------------------------------------------------------------------- /Chapter09/exercises/9.11/ex_911.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_911.cpp 5 | * 6 | * Description: Exercise 9.11 - Rectangle Class 7 | * 8 | * Version: 1.0 9 | * Created: 09/06/16 17:27:09 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | #include "Rectangle.hpp" 21 | 22 | int main(int argc, const char *argv[]) { 23 | Rectangle r1(19, 19); 24 | 25 | std::cout << "Area: " << r1.getArea() 26 | << "\nPerimeter: " << r1.getPerimeter() << std::endl; 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Chapter09/exercises/9.12/Coord2D.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Coord2D.hpp 5 | * 6 | * Description: Exercise 9.12 - 2D Coordinate Representation 7 | * 8 | * Version: 1.0 9 | * Created: 09/06/16 18:28:47 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | class Coord2D { 21 | public: 22 | explicit Coord2D(int X = 0, int Y = 0) { 23 | setX(X); 24 | setY(Y); 25 | } 26 | 27 | // SETTERS 28 | void setX(int X) { x = X; } 29 | void setY(int Y) { y = Y; } 30 | 31 | // GETTERS 32 | int getX() { return x; } 33 | int getY() { return y; } 34 | 35 | private: 36 | int x; 37 | int y; 38 | }; 39 | -------------------------------------------------------------------------------- /Chapter09/exercises/9.12/ex_912.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_912.cpp 5 | * 6 | * Description: Exercise 9.12 - Enhancing Class Rectangle 7 | * 8 | * Version: 1.0 9 | * Created: 09/06/16 18:19:16 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | #include "Rectangle.hpp" 21 | 22 | int main(int argc, const char *argv[]) { 23 | Coord2D tl(1, 1); 24 | Coord2D bl(1, 4); 25 | Coord2D tr(3, 1); 26 | Coord2D br(3, 4); 27 | 28 | Rectangle r1(tl, bl, tr, br); 29 | 30 | std::cout << "Width: " << r1.getWidth() << "\nLength: " << r1.getLength() 31 | << "\nArea: " << r1.getArea() 32 | << "\nPerimeter: " << r1.getPerimeter() << std::endl; 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Chapter09/exercises/9.13/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter09/exercises/9.13/empty -------------------------------------------------------------------------------- /Chapter09/exercises/9.15/ex_915.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_915.cpp 5 | * 6 | * Description: Exercise 9.15 - TicTacToe Class 7 | * 8 | * Version: 1.0 9 | * Created: 15/06/16 12:43:28 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | #include "TicTacToe.hpp" 21 | 22 | int main(int argc, const char *argv[]) { 23 | TicTacToe ttt(3, 3); 24 | 25 | ttt.go(); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Chapter10/README.md: -------------------------------------------------------------------------------- 1 | #### Chapter 10 Incomplete Solutions 2 | 3 | *If you have a solution feel free to contribute* 4 | 5 | - [10.15](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter10/exercises/10.15/) - *Project: Emergency Response Class* 6 | -------------------------------------------------------------------------------- /Chapter10/examples/10.04/Increment.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Increment.cpp 5 | * 6 | * Description: Fig. 10.5: Member function definitions for class Increment 7 | * demonstrate using a member initialiser to initialise a 8 | * constant of a built in data type. 9 | * 10 | * Version: 1.0 11 | * Created: 17/06/16 22:49:57 12 | * Revision: none 13 | * Compiler: g++ 14 | * 15 | * Author: Siidney Watson - siidney.watson.work@gmail.com 16 | * Organization: LolaDog Studio 17 | * 18 | * ===================================================================================== 19 | */ 20 | #include "Increment.hpp" 21 | 22 | #include 23 | 24 | Increment::Increment(int c, int i) : count(c), increment(i) {} 25 | // print count and increment values 26 | void Increment::print() const { 27 | std::cout << "count = " << count << ", increment = " << increment 28 | << std::endl; 29 | } 30 | -------------------------------------------------------------------------------- /Chapter10/examples/10.04/Increment.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Increment.h 5 | * 6 | * Description: Fig. 10.4: Definition of class increment 7 | * 8 | * Version: 1.0 9 | * Created: 17/06/16 22:47:29 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | class Increment { 21 | public: 22 | Increment(int c = 0, int i = 1); 23 | 24 | // function addIncrement definition 25 | void addIncrement() { count += increment; } 26 | void print() const; 27 | 28 | private: 29 | int count; 30 | 31 | const int increment; 32 | }; 33 | -------------------------------------------------------------------------------- /Chapter10/examples/10.04/fig10_06.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig10_06.cpp 5 | * 6 | * Description: Fig. 10.6: Program to test class Increment 7 | * 8 | * Version: 1.0 9 | * Created: 17/06/16 22:51:56 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "Increment.hpp" 19 | 20 | #include 21 | 22 | int main(int argc, const char *argv[]) { 23 | Increment value(10, 5); 24 | 25 | std::cout << "Before incrementing: "; 26 | value.print(); 27 | 28 | for (int j = 1; j <= 3; ++j) { 29 | value.addIncrement(); 30 | 31 | std::cout << "After increment " << j << ": "; 32 | value.print(); 33 | } 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Chapter10/examples/10.08/Date.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Date.h 5 | * 6 | * Description: Fig. 10.8: Date class definition 7 | * 8 | * Version: 1.0 9 | * Created: 17/06/16 23:46:34 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | class Date { 21 | public: 22 | static const int monthsPerYear = 12; 23 | 24 | Date(int = 1, int = 1, int = 1900); 25 | ~Date(); 26 | 27 | void print() const; 28 | 29 | private: 30 | int month; 31 | int day; 32 | int year; 33 | 34 | // utility functions 35 | int checkDay(int) const; 36 | }; 37 | -------------------------------------------------------------------------------- /Chapter10/examples/10.08/Employee.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Employee.h 5 | * 6 | * Description: Fig. 10.10: Employee Class definition showing composition 7 | * 8 | * Version: 1.0 9 | * Created: 18/06/16 00:42:18 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include "Date.hpp" 21 | 22 | #include 23 | 24 | class Employee { 25 | public: 26 | Employee(const std::string&, const std::string&, const Date&, const Date&); 27 | ~Employee(); 28 | 29 | void print() const; 30 | 31 | private: 32 | std::string firstName; 33 | std::string lastName; 34 | const Date birthDate; 35 | const Date hireDate; 36 | }; 37 | -------------------------------------------------------------------------------- /Chapter10/examples/10.08/fig10_12.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig10_12.cpp 5 | * 6 | * Description: Fig. 10.12: Demonstrating composition--an object with member 7 | * objects. 8 | * 9 | * Version: 1.0 10 | * Created: 18/06/16 00:48:39 11 | * Revision: none 12 | * Compiler: g++ 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include 20 | 21 | #include "Employee.hpp" 22 | 23 | int main(int argc, const char *argv[]) { 24 | Date birth(7, 24, 1949); 25 | Date hire(3, 12, 1988); 26 | Employee manager("Bob", "Blue", birth, hire); 27 | 28 | std::cout << std::endl; 29 | 30 | manager.print(); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Chapter10/examples/10.18/Employee.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Employee.h 5 | * 6 | * Description: Fig. 10.18: Employee class definition with a static data 7 | * member to track the number of Employee objects in memory. 8 | * 9 | * Version: 1.0 10 | * Created: 22/06/16 16:47:11 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #pragma once 20 | 21 | #include 22 | 23 | class Employee { 24 | public: 25 | Employee(const std::string&, const std::string&); 26 | ~Employee(); 27 | 28 | std::string getFirstName() const; 29 | std::string getLastName() const; 30 | 31 | static int getCount(); 32 | 33 | private: 34 | std::string firstName; 35 | std::string lastName; 36 | 37 | static int count; 38 | }; 39 | -------------------------------------------------------------------------------- /Chapter10/examples/10.21/Implementation.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Implementation.h 5 | * 6 | * Description: Fig. 10.21: Implementation class definition 7 | * 8 | * Version: 1.0 9 | * Created: 22/06/16 17:38:16 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | class Implementation { 21 | public: 22 | Implementation(int v) : value(v) {} 23 | 24 | void setValue(int v) { value = v; } 25 | 26 | int getValue() const { return value; } 27 | 28 | private: 29 | int value; 30 | }; 31 | -------------------------------------------------------------------------------- /Chapter10/examples/10.21/Interface.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Interface.cpp 5 | * 6 | * Description: Fig. 10.23; Implementation of class Interface--client 7 | * receives this file only as precompiled object code, keeping 8 | * the implementation hidden. 9 | * 10 | * Version: 1.0 11 | * Created: 22/06/16 17:42:39 12 | * Revision: none 13 | * Compiler: g++ 14 | * 15 | * Author: Siidney Watson - siidney.watson.work@gmail.com 16 | * Organization: LolaDog Studio 17 | * 18 | * ===================================================================================== 19 | */ 20 | #include "Interface.hpp" 21 | #include "Implementation.hpp" 22 | 23 | Interface::Interface(int v) : ptr(new Implementation(v)) {} 24 | Interface::~Interface() { delete ptr; } 25 | 26 | void Interface::setValue(int v) { ptr->setValue(v); } 27 | int Interface::getValue() const { return ptr->getValue(); } 28 | -------------------------------------------------------------------------------- /Chapter10/examples/10.21/fig10_24.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig10_24.cpp 5 | * 6 | * Description: Fig. 10.24: Hiding a class's private data with a proxy class 7 | * 8 | * Version: 1.0 9 | * Created: 22/06/16 17:45:08 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "Interface.hpp" 19 | 20 | #include 21 | 22 | int main(int argc, const char *argv[]) { 23 | Interface i(5); 24 | 25 | std::cout << "Interface contains " << i.getValue() << " before setValue" 26 | << std::endl; 27 | 28 | i.setValue(10); 29 | 30 | std::cout << "Interface contains " << i.getValue() << " after setValue" 31 | << std::endl; 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Chapter10/exercises/10.06/ex_1006.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_1006.cpp 5 | * 6 | * Description: Exercise 10.6: Date Class Modification 7 | * 8 | * Version: 1.0 9 | * Created: 28/06/16 15:53:22 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | #include "Date.hpp" 21 | 22 | int main(int argc, const char *argv[]) { 23 | Date d1; 24 | Date d2("February", 14, 1952); 25 | 26 | d1.printDayYear(); 27 | printf("\n"); 28 | d1.printShort(); 29 | printf("\n"); 30 | d1.printLong(); 31 | printf("\n\n"); 32 | 33 | d2.printDayYear(); 34 | printf("\n"); 35 | d2.printShort(); 36 | printf("\n"); 37 | d2.printLong(); 38 | std::cout << std::endl; 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /Chapter10/exercises/10.09/ex_1009.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_1009.cpp 5 | * 6 | * Description: Exercise 10.09: Time Class Modification 7 | * 8 | * Version: 1.0 9 | * Created: 04/07/16 14:21:47 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | #include "Time.hpp" 21 | 22 | int main(int argc, const char *argv[]) { 23 | Time t1(13, 25, 59); 24 | Time t2(7, 51, 12); 25 | 26 | t1.printUniversal(); 27 | printf("\n"); 28 | t2.printUniversal(); 29 | printf("\n"); 30 | t1.printStandard(); 31 | printf("\n"); 32 | t2.printStandard(); 33 | 34 | std::cout << std::endl; 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Chapter10/exercises/10.10/Card.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Card.hpp 5 | * 6 | * Description: Exercise 10.10: Card Shuffling and Dealing 7 | * 8 | * Version: 1.0 9 | * Created: 04/07/16 14:38:45 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include 21 | 22 | class Card { 23 | public: 24 | Card(int, int); 25 | 26 | std::string toString() const; 27 | 28 | private: 29 | static std::string suits[]; 30 | static std::string faces[]; 31 | 32 | int face; 33 | int suit; 34 | }; 35 | -------------------------------------------------------------------------------- /Chapter10/exercises/10.10/DeckOfCards.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Deck.hpp 5 | * 6 | * Description: Exercise 10.10: Card Shuffling and Dealing 7 | * 8 | * Version: 1.0 9 | * Created: 04/07/16 14:39:04 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | #include "Card.hpp" 24 | 25 | class DeckOfCards { 26 | public: 27 | DeckOfCards(); 28 | 29 | void shuffle(); 30 | Card dealCard(); 31 | bool moreCards() const; 32 | 33 | private: 34 | const int TOTAL_CARDS = 52; 35 | 36 | std::vector deck; 37 | 38 | int currentCard; 39 | 40 | std::mt19937 gen; 41 | 42 | int getRandomNumber(); 43 | }; 44 | -------------------------------------------------------------------------------- /Chapter10/exercises/10.10/ex_1010.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_1010.cpp 5 | * 6 | * Description: Exercise 10.10: Card Shuffling and Dealing 7 | * 8 | * Version: 1.0 9 | * Created: 04/07/16 14:39:28 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | #include "DeckOfCards.hpp" 21 | 22 | int main(int argc, const char *argv[]) { 23 | DeckOfCards deck1; 24 | 25 | deck1.shuffle(); 26 | 27 | while (deck1.moreCards()) { 28 | std::cout << deck1.dealCard().toString() << std::endl; 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Chapter10/exercises/10.11/Card.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Card.cpp 5 | * 6 | * Description: Exercise 10.11: Card Shuffling and Dealing 7 | * 8 | * Version: 1.0 9 | * Created: 04/07/16 14:38:59 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "Card.hpp" 19 | 20 | std::string Card::suits[5] = {"", "clubs", "diamonds", "hearts", "spades"}; 21 | std::string Card::faces[14] = {"", "ace", "two", "three", "four", 22 | "five", "six", "seven", "eight", "nine", 23 | "ten", "jack", "queen", "king"}; 24 | 25 | Card::Card(int f, int s) { 26 | face = f; 27 | suit = s; 28 | } 29 | std::string Card::toString() const { 30 | return faces[face] + " of " + suits[suit]; 31 | } 32 | -------------------------------------------------------------------------------- /Chapter10/exercises/10.11/Card.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Card.hpp 5 | * 6 | * Description: Exercise 10.11: Card Shuffling and Dealing 7 | * 8 | * Version: 1.1 9 | * Created: 04/07/16 14:38:45 10 | * Revision: 04/07/16 17:58:56 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include 21 | 22 | class Card { 23 | public: 24 | Card(int, int); 25 | 26 | std::string toString() const; 27 | 28 | std::string getSuit() const { return suits[suit]; } 29 | 30 | int getFace() const { return face; } 31 | 32 | private: 33 | static std::string suits[]; 34 | static std::string faces[]; 35 | 36 | int face; 37 | int suit; 38 | }; 39 | -------------------------------------------------------------------------------- /Chapter10/exercises/10.11/ex_1011.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_1011.cpp 5 | * 6 | * Description: Exercise 10.11: Card Shuffling and Dealing 7 | * 8 | * Version: 1.0 9 | * Created: 04/07/16 17:18:01 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | #include "DeckOfCards.hpp" 21 | 22 | int main(int argc, const char *argv[]) { 23 | DeckOfCards deck; 24 | 25 | deck.shuffle(); 26 | 27 | deck.dealHand(); 28 | deck.sortHand(); 29 | 30 | deck.showHand(); 31 | 32 | deck.getScore(); 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Chapter10/exercises/10.12/Card.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Card.cpp 5 | * 6 | * Description: Exercise 10.12: Card Shuffling and Dealing 7 | * 8 | * Version: 1.0 9 | * Created: 04/07/16 14:38:59 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "Card.hpp" 19 | 20 | std::string Card::suits[5] = {"", "clubs", "diamonds", "hearts", "spades"}; 21 | std::string Card::faces[14] = {"", "ace", "two", "three", "four", 22 | "five", "six", "seven", "eight", "nine", 23 | "ten", "jack", "queen", "king"}; 24 | 25 | Card::Card(int f, int s) { 26 | face = f; 27 | suit = s; 28 | } 29 | std::string Card::toString() const { 30 | return faces[face] + " of " + suits[suit]; 31 | } 32 | -------------------------------------------------------------------------------- /Chapter10/exercises/10.12/Card.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Card.h 5 | * 6 | * Description: Exercise 10.12: Card Shuffling and Dealing 7 | * 8 | * Version: 1.1 9 | * Created: 04/07/16 14:38:45 10 | * Revision: 04/07/16 17:58:56 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include 21 | 22 | class Card { 23 | public: 24 | Card(int, int); 25 | 26 | std::string toString() const; 27 | 28 | std::string getSuit() const { return suits[suit]; } 29 | 30 | int getFace() const { return face; } 31 | 32 | private: 33 | static std::string suits[]; 34 | static std::string faces[]; 35 | 36 | int face; 37 | int suit; 38 | }; 39 | -------------------------------------------------------------------------------- /Chapter10/exercises/10.13/Card.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Card.cpp 5 | * 6 | * Description: Exercise 10.13: Card Shuffling and Dealing 7 | * 8 | * Version: 1.0 9 | * Created: 04/07/16 14:38:59 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "Card.hpp" 19 | 20 | std::string Card::suits[5] = {"", "clubs", "diamonds", "hearts", "spades"}; 21 | std::string Card::faces[14] = {"", "ace", "two", "three", "four", 22 | "five", "six", "seven", "eight", "nine", 23 | "ten", "jack", "queen", "king"}; 24 | 25 | Card::Card(int f, int s) { 26 | face = f; 27 | suit = s; 28 | } 29 | std::string Card::toString() const { 30 | return faces[face] + " of " + suits[suit]; 31 | } 32 | -------------------------------------------------------------------------------- /Chapter10/exercises/10.13/Card.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Card.h 5 | * 6 | * Description: Exercise 10.13: Card Shuffling and Dealing 7 | * 8 | * Version: 1.1 9 | * Created: 04/07/16 14:38:45 10 | * Revision: 04/07/16 17:58:56 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include 21 | 22 | class Card { 23 | public: 24 | Card(int, int); 25 | 26 | std::string toString() const; 27 | 28 | std::string getSuit() const { return suits[suit]; } 29 | 30 | int getFace() const { return face; } 31 | 32 | private: 33 | static std::string suits[]; 34 | static std::string faces[]; 35 | 36 | int face; 37 | int suit; 38 | }; 39 | -------------------------------------------------------------------------------- /Chapter10/exercises/10.13/Poker.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Poker.hpp 5 | * 6 | * Description: Exercise 10.13: Card Shuffling and Dealing 7 | * 8 | * Version: 1.0 9 | * Created: 05/07/16 17:05:47 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include 21 | 22 | #include "Hand.hpp" 23 | 24 | class Poker { 25 | public: 26 | Poker(); 27 | 28 | void go(); 29 | 30 | private: 31 | unsigned int numPlayers; 32 | 33 | bool running; 34 | 35 | std::vector players; 36 | 37 | void setPlayers(); 38 | void processTurns(); 39 | void showResult(); 40 | bool playAgain(); 41 | }; 42 | -------------------------------------------------------------------------------- /Chapter10/exercises/10.13/ex_1013.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_1012.cpp 5 | * 6 | * Description: Exercise 10.13: Card Shuffling and Dealing 7 | * 8 | * Version: 1.1 9 | * Created: 04/07/16 17:18:01 10 | * Revision: 04/07/16 21:47:15 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "Poker.hpp" 19 | 20 | #include 21 | 22 | int main(int argc, const char *argv[]) { 23 | Poker poker; 24 | 25 | poker.go(); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Chapter10/exercises/10.15/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter10/exercises/10.15/empty -------------------------------------------------------------------------------- /Chapter11/README.md: -------------------------------------------------------------------------------- 1 | #### Chapter 10 Incomplete Solutions 2 | 3 | *If you have a solution feel free to contribute* 4 | 5 | - [11.09](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter11/exercises/11.09/) - *HugeInt Class* 6 | - [11.11](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter11/exercises/11.11/) - *Polynomial Class* 7 | -------------------------------------------------------------------------------- /Chapter11/examples/11.03/PhoneNumber.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: PhoneNumber.h 5 | * 6 | * Description: fig. 11.3: Phone Number class definition 7 | * 8 | * Version: 1.0 9 | * Created: 07/07/16 18:22:37 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | class PhoneNumber { 24 | public: 25 | friend std::ostream& operator<<(std::ostream&, const PhoneNumber&); 26 | friend std::istream& operator>>(std::istream&, PhoneNumber&); 27 | 28 | private: 29 | std::string areaCode; 30 | std::string exchange; 31 | std::string line; 32 | }; 33 | -------------------------------------------------------------------------------- /Chapter11/exercises/11.09/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter11/exercises/11.09/empty -------------------------------------------------------------------------------- /Chapter11/exercises/11.11/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter11/exercises/11.11/empty -------------------------------------------------------------------------------- /Chapter12/exercises/12.09/OvernightPackage.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: OvernightPackage.hpp 5 | * 6 | * Description: Exercise 12.9: Package Inheritance Hierarchy 7 | * 8 | * Version: 1.0 9 | * Created: 19/07/16 18:04:13 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include "Package.hpp" 21 | 22 | class OvernightPackage : public Package { 23 | public: 24 | OvernightPackage(const Person&, const Person&, double, double, double); 25 | 26 | double calculateCost() { 27 | return Package::getWeight() * 28 | (Package::getCostPerOunce() + feePerOunce); 29 | } 30 | 31 | void printDetails(); 32 | 33 | private: 34 | double feePerOunce; 35 | 36 | void setFee(double); 37 | }; 38 | -------------------------------------------------------------------------------- /Chapter12/exercises/12.09/TwoDayPackage.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: TwoDayPackage.hpp 5 | * 6 | * Description: Exercise 12.9: Package Inheritance Hierarchy 7 | * 8 | * Version: 1.0 9 | * Created: 19/07/16 17:59:57 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include "Package.hpp" 21 | 22 | class TwoDayPackage : public Package { 23 | public: 24 | TwoDayPackage(const Person&, const Person&, double, double, double); 25 | 26 | double calculateCost() { return Package::calculateCost() + flatFee; } 27 | 28 | void printDetails(); 29 | 30 | private: 31 | double flatFee; 32 | 33 | void setFee(double); 34 | }; 35 | -------------------------------------------------------------------------------- /Chapter12/exercises/12.10/Account.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Account.hpp 5 | * 6 | * Description: Exercise 12.10 - Account Inheritance Hierarchy 7 | * 8 | * Version: 1.0 9 | * Created: 24/07/16 20:26:07 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | class Account { 21 | public: 22 | explicit Account(double); 23 | 24 | void credit(double); 25 | bool debit(double); 26 | double getBalance() const { return balance; } 27 | 28 | private: 29 | double balance; 30 | }; 31 | -------------------------------------------------------------------------------- /Chapter12/exercises/12.10/CheckingAccount.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: CheckingAccount.hpp 5 | * 6 | * Description: Exercise 12.10 - Account Inheritance Hierarchy 7 | * 8 | * Version: 1.0 9 | * Created: 24/07/16 20:28:04 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include "Account.hpp" 21 | 22 | class CheckingAccount : public Account { 23 | public: 24 | CheckingAccount(double, double); 25 | 26 | void credit(double); 27 | void debit(double); 28 | 29 | private: 30 | double feePerTransaction; 31 | }; 32 | -------------------------------------------------------------------------------- /Chapter12/exercises/12.10/SavingsAccount.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: SavingsAccount.cpp 5 | * 6 | * Description: Exercise 12.10 - Account Inheritance Hierarchy 7 | * 8 | * Version: 1.0 9 | * Created: 24/07/16 20:28:01 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "SavingsAccount.hpp" 19 | 20 | SavingsAccount::SavingsAccount(double b, double ir) 21 | : Account(b), interestRate(ir) {} 22 | // calculate interest 23 | double SavingsAccount::calculateInterest() const { 24 | return Account::getBalance() * interestRate; 25 | } 26 | -------------------------------------------------------------------------------- /Chapter12/exercises/12.10/SavingsAccount.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: SavingsAccount.hpp 5 | * 6 | * Description: Exercise 12.10 - Account Inheritance Hierarchy 7 | * 8 | * Version: 1.0 9 | * Created: 24/07/16 20:27:54 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include "Account.hpp" 21 | 22 | class SavingsAccount : public Account { 23 | public: 24 | SavingsAccount(double, double); 25 | 26 | double calculateInterest() const; 27 | 28 | private: 29 | double interestRate; 30 | }; 31 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.13/Circle.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Circle.hpp 5 | * 6 | * Description: Exercise 13.13 - Shape Hierarchy 7 | * 2D Circle 8 | * 9 | * Version: 1.0 10 | * Created: 17/08/16 17:42:47 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #pragma once 20 | 21 | #include "TwoDimensionalShape.hpp" 22 | 23 | class Circle : public TwoDimensionalShape { 24 | public: 25 | explicit Circle(double = 0.0f); 26 | 27 | double getArea() const; 28 | virtual void print() const; 29 | 30 | void setRadius(double); 31 | double getRadius() const; 32 | 33 | private: 34 | const double PI = 3.14159; 35 | 36 | double radius; 37 | }; 38 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.13/Cube.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Cube.hpp 5 | * 6 | * Description: Exercise 13.13 - Shape Hierarchy 7 | * 3D Cube 8 | * 9 | * Version: 1.0 10 | * Created: 17/08/16 18:01:57 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #pragma once 20 | 21 | #include "ThreeDimensionalShape.hpp" 22 | 23 | class Cube : public ThreeDimensionalShape { 24 | public: 25 | explicit Cube(double = 0.0f, double = 0.0f, double = 0.0f); 26 | 27 | virtual double getArea() const; 28 | virtual double getVolume() const; 29 | virtual void print() const; 30 | 31 | private: 32 | }; 33 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.13/Cuboid.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Cuboid.hpp 5 | * 6 | * Description: Exercise 13.13 - Shape Hierarchy 7 | * 3D Cuboid 8 | * 9 | * Version: 1.0 10 | * Created: 17/08/16 18:47:08 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #pragma once 20 | 21 | #include "ThreeDimensionalShape.hpp" 22 | 23 | class Cuboid : public ThreeDimensionalShape { 24 | public: 25 | Cuboid(double, double, double); 26 | 27 | virtual double getArea() const; 28 | virtual double getVolume() const; 29 | void print() const; 30 | 31 | private: 32 | }; 33 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.13/Rectangle.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Rectangle.cpp 5 | * 6 | * Description: Exercise 13.13 - Shape Hierarchy 7 | * 2D Rectangle 8 | * 9 | * Version: 1.0 10 | * Created: 17/08/16 17:35:12 11 | * Revision: none 12 | * Compiler: g++ 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include 20 | 21 | #include "Rectangle.hpp" 22 | 23 | Rectangle::Rectangle(double l, double w) : TwoDimensionalShape(l, w) {} 24 | // get area 25 | double Rectangle::getArea() const { return getLength() * getWidth(); } 26 | // print 27 | void Rectangle::print() const { 28 | std::cout << "Rectangle:" 29 | << "\nLength: " << getLength() << "\nWidth : " << getWidth(); 30 | } 31 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.13/Rectangle.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Rectangle.hpp 5 | * 6 | * Description: Exercise 13.13 - Shape Hierarchy 7 | * 2D Rectangle 8 | * 9 | * Version: 1.0 10 | * Created: 17/08/16 17:33:46 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #pragma once 20 | 21 | #include "TwoDimensionalShape.hpp" 22 | 23 | class Rectangle : public TwoDimensionalShape { 24 | public: 25 | explicit Rectangle(double = 0.0f, double = 0.0f); 26 | 27 | virtual double getArea() const; 28 | virtual void print() const; 29 | 30 | private: 31 | }; 32 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.13/Shape.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Shape.hpp 5 | * 6 | * Description: Exercie 13.13 - Shape Hierarchy 7 | * 8 | * Version: 1.0 9 | * Created: 17/08/16 14:26:16 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | class Shape { 21 | public: 22 | explicit Shape(double = 0.0f, double = 0.0f); 23 | 24 | void setLength(double); 25 | double getLength() const; 26 | 27 | void setWidth(double); 28 | double getWidth() const; 29 | 30 | virtual void print() const = 0; 31 | 32 | private: 33 | double length; 34 | double width; 35 | }; 36 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.13/Sphere.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Sphere.hpp 5 | * 6 | * Description: Exercise 13.13 - Shape Hierarchy 7 | * 3D Sphere 8 | * 9 | * Version: 1.0 10 | * Created: 17/08/16 18:58:05 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #pragma once 20 | 21 | #include "ThreeDimensionalShape.hpp" 22 | 23 | class Sphere : public ThreeDimensionalShape { 24 | public: 25 | explicit Sphere(double); 26 | 27 | virtual double getArea() const; 28 | virtual double getVolume() const; 29 | virtual void print() const; 30 | 31 | void setRadius(double); 32 | double getRadius() const; 33 | 34 | private: 35 | const double PI = 3.14159; 36 | double radius; 37 | }; 38 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.13/Square.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Square.cpp 5 | * 6 | * Description: Exercise 13.13 - Shape Hierarchy 7 | * 2D Square 8 | * 9 | * Version: 1.0 10 | * Created: 17/08/16 15:11:30 11 | * Revision: none 12 | * Compiler: g++ 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include 20 | 21 | #include "Square.hpp" 22 | 23 | Square::Square(double l, double w) : TwoDimensionalShape(l, w) { 24 | if (w == 0) { setWidth(l); } 25 | } 26 | // get area 27 | double Square::getArea() const { 28 | // Square so both width and height are equal 29 | return getLength() * getWidth(); 30 | } 31 | // print 32 | void Square::print() const { 33 | std::cout << "Square: " 34 | << "\nLength: " << getLength() << "\nWidth : " << getWidth(); 35 | } 36 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.13/Square.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Square.hpp 5 | * 6 | * Description: Exercise 13.13 - Shape Hierarchy 7 | * 2D Square 8 | * 9 | * Version: 1.0 10 | * Created: 17/08/16 15:11:09 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #pragma once 20 | 21 | #include "TwoDimensionalShape.hpp" 22 | 23 | class Square : public TwoDimensionalShape { 24 | public: 25 | explicit Square(double = 0.0f, double = 0.0f); 26 | 27 | virtual double getArea() const; 28 | virtual void print() const; 29 | 30 | private: 31 | }; 32 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.13/ThreeDimensionalShape.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ThreeDimensionalShape.hpp 5 | * 6 | * Description: Exercie 13.13 - Shape Hierarchy 7 | * 8 | * Version: 1.0 9 | * Created: 17/08/16 14:28:21 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include "Shape.hpp" 21 | 22 | class ThreeDimensionalShape : public Shape { 23 | public: 24 | explicit ThreeDimensionalShape(double = 0.0f, double = 0.0f, double = 0.0f); 25 | 26 | virtual double getArea() const = 0; 27 | virtual double getVolume() const = 0; 28 | virtual void print() const = 0; 29 | 30 | void setHeight(double); 31 | double getHeight() const; 32 | 33 | private: 34 | double height; 35 | }; 36 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.13/Triangle.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Triangle.hpp 5 | * 6 | * Description: Exercise 13.13 - Shape Hierarchy 7 | * 2D Triangle 8 | * 9 | * Version: 1.0 10 | * Created: 17/08/16 17:53:50 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #pragma once 20 | 21 | #include "TwoDimensionalShape.hpp" 22 | 23 | class Triangle : public TwoDimensionalShape { 24 | public: 25 | explicit Triangle(double = 0.0f, double = 0.0f); 26 | 27 | virtual double getArea() const; 28 | virtual void print() const; 29 | 30 | void setBase(double); 31 | double getBase() const; 32 | 33 | void setHeight(double); 34 | double getHeight() const; 35 | 36 | private: 37 | double base; 38 | double height; 39 | }; 40 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.13/TwoDimensionalShape.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: TwoDimensionalShape.cpp 5 | * 6 | * Description: Exercie 13.13 - Shape Hierarchy 7 | * 8 | * Version: 1.0 9 | * Created: 17/08/16 14:28:11 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "TwoDimensionalShape.hpp" 19 | 20 | TwoDimensionalShape::TwoDimensionalShape(double l, double w) : Shape(l, w) {} 21 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.13/TwoDimensionalShape.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: TwoDimensionalShape.hpp 5 | * 6 | * Description: Exercie 13.13 - Shape Hierarchy 7 | * 8 | * Version: 1.0 9 | * Created: 17/08/16 14:28:03 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include "Shape.hpp" 21 | 22 | class TwoDimensionalShape : public Shape { 23 | public: 24 | explicit TwoDimensionalShape(double = 0.0f, double = 0.0f); 25 | 26 | virtual double getArea() const = 0; 27 | virtual void print() const = 0; 28 | 29 | private: 30 | }; 31 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.14/Circle.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Circle.hpp 5 | * 6 | * Description: Exercise 13.13 - Shape Hierarchy 7 | * 2D Circle 8 | * 9 | * Version: 1.0 10 | * Created: 17/08/16 17:42:47 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #pragma once 20 | 21 | #include "TwoDimensionalShape.hpp" 22 | 23 | class Circle : public TwoDimensionalShape { 24 | public: 25 | explicit Circle(int = 0, int = 0, int = 0, int = 0, char = 'x'); 26 | 27 | virtual char* draw(); 28 | 29 | private: 30 | }; 31 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.14/Rectangle.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Rectangle.hpp 5 | * 6 | * Description: Exercise 13.13 - Shape Hierarchy 7 | * 2D Rectangle 8 | * 9 | * Version: 1.0 10 | * Created: 17/08/16 17:33:46 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #pragma once 20 | 21 | #include "TwoDimensionalShape.hpp" 22 | 23 | class Rectangle : public TwoDimensionalShape { 24 | public: 25 | explicit Rectangle(int = 0, int = 0, int = 0, int = 0, char = 'x'); 26 | 27 | virtual char* draw(); 28 | }; 29 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.14/Square.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Square.hpp 5 | * 6 | * Description: Exercise 13.13 - Shape Hierarchy 7 | * 2D Square 8 | * 9 | * Version: 1.0 10 | * Created: 17/08/16 15:11:09 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #pragma once 20 | 21 | #include "TwoDimensionalShape.hpp" 22 | 23 | class Square : public TwoDimensionalShape { 24 | public: 25 | explicit Square(int = 0, int = 0, int = 0, int = 0, char = 'x'); 26 | 27 | virtual char* draw(); 28 | }; 29 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.14/Triangle.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Triangle.hpp 5 | * 6 | * Description: Exercise 13.13 - Shape Hierarchy 7 | * 2D Triangle 8 | * 9 | * Version: 1.0 10 | * Created: 17/08/16 17:53:50 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #pragma once 20 | 21 | #include "TwoDimensionalShape.hpp" 22 | 23 | class Triangle : public TwoDimensionalShape { 24 | public: 25 | explicit Triangle(int = 0, int = 0, int = 0, int = 0, char = 'x'); 26 | 27 | virtual char* draw(); 28 | }; 29 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.14/TwoDimensionalShape.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: TwoDimensionalShape.cpp 5 | * 6 | * Description: Exercie 13.13 - Shape Hierarchy 7 | * 8 | * Version: 1.0 9 | * Created: 17/08/16 14:28:11 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "TwoDimensionalShape.hpp" 19 | 20 | TwoDimensionalShape::TwoDimensionalShape(int w, int h, int x, int y, char f) 21 | : Shape(w, h, x, y), fillchar(f) {} 22 | TwoDimensionalShape::~TwoDimensionalShape() { 23 | if (img != nullptr) { delete img; } 24 | } 25 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.14/TwoDimensionalShape.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: TwoDimensionalShape.hpp 5 | * 6 | * Description: Exercie 13.13 - Shape Hierarchy 7 | * 8 | * Version: 1.0 9 | * Created: 17/08/16 14:28:03 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include "Shape.hpp" 21 | 22 | class TwoDimensionalShape : public Shape { 23 | public: 24 | explicit TwoDimensionalShape(int = 0, int = 0, int = 0, int = 0, char = 'x'); 25 | ~TwoDimensionalShape(); 26 | 27 | virtual char* draw() = 0; 28 | 29 | protected: 30 | char fillchar; 31 | char* img = nullptr; 32 | }; 33 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.15/OvernightPackage.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: OvernightPackage.hpp 5 | * 6 | * Description: Exercise 12.9: Package Inheritance Hierarchy 7 | * 8 | * Version: 1.0 9 | * Created: 19/07/16 18:04:13 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include "Package.hpp" 21 | 22 | class OvernightPackage : public Package { 23 | public: 24 | OvernightPackage(const Person&, const Person&, double, double, double); 25 | 26 | double calculateCost() { 27 | return Package::getWeight() * 28 | (Package::getCostPerOunce() + feePerOunce); 29 | } 30 | 31 | void printDetails(); 32 | 33 | private: 34 | double feePerOunce; 35 | 36 | void setFee(double); 37 | }; 38 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.15/TwoDayPackage.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: TwoDayPackage.hpp 5 | * 6 | * Description: Exercise 12.9: Package Inheritance Hierarchy 7 | * 8 | * Version: 1.0 9 | * Created: 19/07/16 17:59:57 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include "Package.hpp" 21 | 22 | class TwoDayPackage : public Package { 23 | public: 24 | TwoDayPackage(const Person&, const Person&, double, double, double); 25 | 26 | double calculateCost() { return Package::calculateCost() + flatFee; } 27 | 28 | void printDetails(); 29 | 30 | private: 31 | double flatFee; 32 | 33 | void setFee(double); 34 | }; 35 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.16/Account.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Account.hpp 5 | * 6 | * Description: Exercise 12.10 - Account Inheritance Hierarchy 7 | * 8 | * Version: 1.0 9 | * Created: 24/07/16 20:26:07 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include 21 | 22 | class Account { 23 | public: 24 | explicit Account(double); 25 | 26 | virtual void credit(double); 27 | virtual bool debit(double); 28 | 29 | double getBalance() const { return balance; } 30 | void setAccountType(const std::string& at) { accountType = at; } 31 | std::string getAccountType() const { return accountType; } 32 | 33 | private: 34 | double balance; 35 | std::string accountType; 36 | }; 37 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.16/CheckingAccount.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: CheckingAccount.hpp 5 | * 6 | * Description: Exercise 12.10 - Account Inheritance Hierarchy 7 | * 8 | * Version: 1.0 9 | * Created: 24/07/16 20:28:04 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include "Account.hpp" 21 | 22 | class CheckingAccount : public Account { 23 | public: 24 | CheckingAccount(double, double); 25 | 26 | void credit(double); 27 | bool debit(double); 28 | 29 | private: 30 | double feePerTransaction; 31 | }; 32 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.16/SavingsAccount.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: SavingsAccount.hpp 5 | * 6 | * Description: Exercise 12.10 - Account Inheritance Hierarchy 7 | * 8 | * Version: 1.0 9 | * Created: 24/07/16 20:27:54 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include "Account.hpp" 21 | 22 | class SavingsAccount : public Account { 23 | public: 24 | SavingsAccount(double, double); 25 | 26 | double calculateInterest() const; 27 | 28 | void credit(double); 29 | bool debit(double); 30 | 31 | private: 32 | double interestRate; 33 | }; 34 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.18/Bicycle.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Bicycle.cpp 5 | * 6 | * Description: Exercise 13.18 - CarbonFootprint Abstract Class: 7 | * Polymorphism 8 | * 9 | * Version: 1.0 10 | * Created: 02/09/16 17:19:04 11 | * Revision: none 12 | * Compiler: g++ 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include "Bicycle.hpp" 20 | 21 | Bicycle::Bicycle() {} 22 | // get carbon footprint 23 | double Bicycle::getCarbonFootprint() const { return 3; } 24 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.18/Bicycle.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Bicycle.hpp 5 | * 6 | * Description: Exercise 13.18 - CarbonFootprint Abstract Class: 7 | * Polymorphism 8 | * 9 | * Version: 1.0 10 | * Created: 02/09/16 17:18:58 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #pragma once 20 | 21 | #include "CarbonFootprint.hpp" 22 | 23 | class Bicycle : public CarbonFootprint { 24 | public: 25 | Bicycle(); 26 | 27 | virtual double getCarbonFootprint() const; 28 | 29 | private: 30 | }; 31 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.18/Building.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Building.cpp 5 | * 6 | * Description: Exercise 13.18 - CarbonFootprint Abstract Class: 7 | * Polymorphism 8 | * 9 | * Version: 1.0 10 | * Created: 02/09/16 17:18:36 11 | * Revision: none 12 | * Compiler: g++ 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include "Building.hpp" 20 | 21 | Building::Building() {} 22 | // calculate buildings carbon footprint 23 | double Building::getCarbonFootprint() const { return 1; } 24 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.18/Building.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Building.hpp 5 | * 6 | * Description: Exercise 13.18 - CarbonFootprint Abstract Class: 7 | * Polymorphism 8 | * 9 | * Version: 1.0 10 | * Created: 02/09/16 17:18:29 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #pragma once 20 | 21 | #include "CarbonFootprint.hpp" 22 | 23 | class Building : public CarbonFootprint { 24 | public: 25 | Building(); 26 | 27 | virtual double getCarbonFootprint() const; 28 | 29 | private: 30 | }; 31 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.18/Car.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Car.cpp 5 | * 6 | * Description: Exercise 13.18 - CarbonFootprint Abstract Class: 7 | * Polymorphism 8 | * 9 | * Version: 1.0 10 | * Created: 02/09/16 17:18:52 11 | * Revision: none 12 | * Compiler: g++ 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include "Car.hpp" 20 | 21 | Car::Car() {} 22 | // get carbon footprint 23 | double Car::getCarbonFootprint() const { return 2; } 24 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.18/Car.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Car.hpp 5 | * 6 | * Description: Exercise 13.18 - CarbonFootprint Abstract Class: 7 | * Polymorphism 8 | * 9 | * Version: 1.0 10 | * Created: 02/09/16 17:18:40 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #pragma once 20 | 21 | #include "CarbonFootprint.hpp" 22 | 23 | class Car : public CarbonFootprint { 24 | public: 25 | Car(); 26 | 27 | virtual double getCarbonFootprint() const; 28 | 29 | private: 30 | }; 31 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.18/CarbonFootprint.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: CarbonFootprint.hpp 5 | * 6 | * Description: Exercise 13.18 - CarbonFootprint Abstract Class: 7 | * Polymorphism 8 | * 9 | * Version: 1.0 10 | * Created: 02/09/16 17:18:08 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #pragma once 20 | 21 | class CarbonFootprint { 22 | public: 23 | virtual double getCarbonFootprint() const = 0; 24 | }; 25 | -------------------------------------------------------------------------------- /Chapter13/exercises/13.18/README.md: -------------------------------------------------------------------------------- 1 | Have not even started on the actual carbon emissions calculations as I can't be 2 | bothered sifting through the information out there. 3 | 4 | I could not find one standard method for calculating it so it shall stay as it 5 | is... 6 | -------------------------------------------------------------------------------- /Chapter14/exercises/14.06/README.md: -------------------------------------------------------------------------------- 1 | Need to complete the 2nd and 3rd parts of this exercise still. Couldn't be 2 | bothered at the time of writing. 3 | -------------------------------------------------------------------------------- /Chapter15/README.md: -------------------------------------------------------------------------------- 1 | #### Chapter 15 Incomplete Solutions 2 | 3 | *If you have a solution feel free to contribute* 4 | 5 | - [15.16](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter15/exercises/15.16/) - *Complex Class* 6 | - [15.18](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter15/exercises/15.18/) - *String-Terminating Null Character* 7 | -------------------------------------------------------------------------------- /Chapter15/examples/15.03/fig15_03.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig15_03.cpp 5 | * 6 | * Description: Fig. 15.3: Printing the address stored in a char * variable 7 | * 8 | * Version: 1.0 9 | * Created: 12/09/16 15:51:11 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | int main(int argc, const char* argv[]) { 21 | const char* const word = "again"; 22 | 23 | // display value of char *, then display value of char * 24 | // static_cast to void * 25 | std::cout << "Value of word is: " << word << std::endl 26 | << "Value of static_cast(word) is: " 27 | << static_cast(word) << std::endl; 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Chapter15/examples/15.15/fig15_15.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig15_15.cpp 5 | * 6 | * Description: Fig. 15.15: Printing an integer with internal spacing and 7 | * plus sign. 8 | * 9 | * Version: 1.0 10 | * Created: 21/09/16 14:40:37 11 | * Revision: none 12 | * Compiler: g++ 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include 20 | #include 21 | 22 | int main(int argc, const char *argv[]) { 23 | // display value with internal spacing and plus sign 24 | std::cout << std::internal << std::showpos << std::setw(10) << 123 25 | << std::endl; 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Chapter15/exercises/15.09/ex_1509.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_1509.cpp 5 | * 6 | * Description: Exercise 15.09 - Printing With Field Widths 7 | * 8 | * Version: 1.0 9 | * Created: 13/10/16 14:04:36 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | #include 20 | 21 | int main(int argc, const char *argv[]) { 22 | int i = 12345; 23 | float f = 1.2345; 24 | 25 | for (int j = 10; j > 1; --j) { 26 | std::cout << "-----\nWidth: " << j << "\n-----\n" 27 | << std::setw(j) << i << "\n" 28 | << std::setw(j) << f << std::endl; 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Chapter15/exercises/15.11/ex_1511.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_15.11.cpp 5 | * 6 | * Description: Exercise 15.11 - Length of a String 7 | * 8 | * Version: 1.0 9 | * Created: 13/10/16 17:50:53 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | #include 20 | #include 21 | 22 | int main(int argc, const char *argv[]) { 23 | std::string input; 24 | 25 | std::cout << "Enter a string: "; 26 | std::getline(std::cin, input); 27 | 28 | int i; 29 | for (i = 0; input[i] != '\0'; ++i) {} 30 | 31 | std::cout << "Length of string: " << input << " = " << i << std::endl; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Chapter15/exercises/15.14/PhoneNumber.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: PhoneNumber.hpp 5 | * 6 | * Description: fig. 11.3: Phone Number class definition 7 | * 8 | * Version: 1.0 9 | * Created: 07/07/16 18:22:37 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | class PhoneNumber { 24 | public: 25 | friend std::ostream& operator<<(std::ostream&, const PhoneNumber&); 26 | friend std::istream& operator>>(std::istream&, PhoneNumber&); 27 | 28 | private: 29 | char pNumber[15] = {}; 30 | std::string areaCode; 31 | std::string exchange; 32 | std::string line; 33 | }; 34 | -------------------------------------------------------------------------------- /Chapter15/exercises/15.15/Point.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Point.hpp 5 | * 6 | * Description: Exercise 15.15 - Point Class 7 | * 8 | * Version: 1.0 9 | * Created: 24/10/16 19:47:54 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include 21 | 22 | class Point { 23 | public: 24 | friend std::ostream& operator<<(std::ostream&, const Point&); 25 | friend std::istream& operator>>(std::istream&, Point&); 26 | 27 | private: 28 | int xCoordinate; 29 | int yCoordinate; 30 | }; 31 | -------------------------------------------------------------------------------- /Chapter15/exercises/15.15/ex_1515.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_1515.cpp 5 | * 6 | * Description: Exercise 15.15 - Point Class 7 | * 8 | * Version: 1.0 9 | * Created: 24/10/16 19:48:34 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | #include "Point.hpp" 21 | 22 | int main(int argc, const char *argv[]) { 23 | Point point; 24 | 25 | std::cout << "Enter space separated x y coordinates: "; 26 | std::cin >> point; 27 | 28 | std::cout << "You Entered: " << point << std::endl; 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Chapter15/exercises/15.16/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter15/exercises/15.16/empty -------------------------------------------------------------------------------- /Chapter15/exercises/15.18/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter15/exercises/15.18/empty -------------------------------------------------------------------------------- /Chapter16/examples/16.01/DivideByZeroException.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: DivideByZeroException.h 5 | * 6 | * Description: Fig. 16.1: Class DivideByZeroException Definition. 7 | * 8 | * Version: 1.0 9 | * Created: 25/10/16 18:08:11 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | #include // stdexcept header contains runtime_error 21 | 22 | // DivideByZeroException objects should be thrown by functions 23 | // upon detecting division-by-zero exceptions 24 | class DivideByZeroException : public std::runtime_error { 25 | public: 26 | // constructor specifies default error message 27 | DivideByZeroException() 28 | : std::runtime_error("attempted to divide by zero") {} 29 | }; 30 | -------------------------------------------------------------------------------- /Chapter16/examples/16.07/Integer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Integer.cpp 5 | * 6 | * Description: Fig. 16.8: Integer member function definitions. 7 | * 8 | * Version: 1.0 9 | * Created: 25/10/16 22:04:22 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "Integer.hpp" 19 | 20 | #include 21 | 22 | Integer::Integer(int i) : value(i) { 23 | std::cout << "Constructor for Integer " << value << std::endl; 24 | } 25 | Integer::~Integer() { 26 | std::cout << "Destructor for Integer " << value << std::endl; 27 | } 28 | // set Integer value 29 | void Integer::setInteger(int i) { value = i; } 30 | // get Integer value 31 | int Integer::getInteger() const { return value; } 32 | -------------------------------------------------------------------------------- /Chapter16/examples/16.07/Integer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Integer.h 5 | * 6 | * Description: Fig. 16.7: Integer class definition 7 | * 8 | * Version: 1.0 9 | * Created: 25/10/16 22:03:11 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #pragma once 19 | 20 | class Integer { 21 | public: 22 | Integer(int i = 0); 23 | ~Integer(); 24 | 25 | void setInteger(int i); 26 | int getInteger() const; 27 | 28 | private: 29 | int value; 30 | }; 31 | -------------------------------------------------------------------------------- /Chapter16/exercises/16.23/ex_1623.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_1623.cpp 5 | * 6 | * Description: Exercise 16.23 - Throwing the Result of a Coditional 7 | * Expression 8 | * 9 | * Version: 1.0 10 | * Created: 27/10/16 16:08:51 11 | * Revision: none 12 | * Compiler: g++ 13 | * 14 | * Author: Siidney Watson - siidney.watson.work@gmail.com 15 | * Organization: LolaDog Studio 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include 20 | #include 21 | 22 | int main(int argc, const char *argv[]) { 23 | try { 24 | int i = 6; 25 | double d = 6.5; 26 | 27 | false ? throw i : throw d; // double should throw 28 | } catch (int &i) { 29 | std::cout << "i was thrown" << std::endl; 30 | } catch (double &d) { 31 | std::cout << "d was thrown" << std::endl; 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Chapter16/exercises/16.26/ex_1626.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_1626.cpp 5 | * 6 | * Description: Exercise 16.26 - Catching All Exceptions 7 | * 8 | * Version: 1.0 9 | * Created: 27/10/16 18:12:00 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | #include 20 | 21 | int main(int argc, const char *argv[]) { 22 | // uncomment to see that it Pokèmon's them all 23 | try { 24 | // throw std::exception(); 25 | // throw std::invalid_argument("invalid argument");; 26 | throw std::out_of_range("out of range"); 27 | } catch (...) { 28 | std::cout << "Exception Caught" << std::endl; 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Chapter16/exercises/16.27/ex_1627.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_1627.cpp 5 | * 6 | * Description: Exercise 16.27 - Order of Exception Handlers 7 | * 8 | * Version: 1.0 9 | * Created: 27/10/16 18:17:52 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | #include 20 | 21 | int main(int argc, const char *argv[]) { 22 | try { 23 | throw std::exception(); 24 | } catch (std::exception &e) { 25 | std::cout << "Executed as first: " << e.what() << std::endl; 26 | } catch (std::exception &e) { 27 | std::cout << "Executed IF first" << e.what() << std::endl; 28 | } 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Chapter16/exercises/16.28/ex_1628.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_1628.cpp 5 | * 6 | * Description: Exercise 16.28 - Constructors Throwing Exceptions 7 | * 8 | * Version: 1.0 9 | * Created: 27/10/16 18:24:18 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | 20 | class C1 { 21 | public: 22 | C1() { throw 99; } 23 | }; 24 | 25 | int main(int argc, const char *argv[]) { 26 | try { 27 | C1 c; 28 | } catch (int &e) { 29 | std::cerr << "Exception: " << e << std::endl; 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Chapter16/exercises/16.29/ex_1629.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_1629.cpp 5 | * 6 | * Description: Exercise 16.29 - Rethrowing Exceptions 7 | * 8 | * Version: 1.0 9 | * Created: 27/10/16 18:33:16 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | #include 20 | 21 | int main(int argc, const char *argv[]) { 22 | try { 23 | try { 24 | throw std::exception(); 25 | } catch (std::exception) { 26 | std::cout << "Original throw caught" << std::endl; 27 | throw; 28 | } 29 | } catch (std::exception) { 30 | std::cout << "Rethrow caught" << std::endl; 31 | } 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Chapter17/examples/17.03/clients.txt: -------------------------------------------------------------------------------- 1 | 17 jim 200 2 | -------------------------------------------------------------------------------- /Chapter17/examples/17.06/clients.txt: -------------------------------------------------------------------------------- 1 | 100 Jones 24.98 2 | 200 Doe 345.67 3 | 300 White 0 4 | 400 Stone -42.16 5 | 500 Rich 224.62 6 | -------------------------------------------------------------------------------- /Chapter17/examples/17.07/clients.txt: -------------------------------------------------------------------------------- 1 | 100 Jones 24.98 2 | 200 Doe 345.67 3 | 300 White 0 4 | 400 Stone -42.16 5 | 500 Rich 224.62 6 | -------------------------------------------------------------------------------- /Chapter17/examples/17.09/credit.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter17/examples/17.09/credit.dat -------------------------------------------------------------------------------- /Chapter17/examples/17.12/credit.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter17/examples/17.12/credit.dat -------------------------------------------------------------------------------- /Chapter17/examples/17.13/credit.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter17/examples/17.13/credit.dat -------------------------------------------------------------------------------- /Chapter17/examples/17.14/credit.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter17/examples/17.14/credit.dat -------------------------------------------------------------------------------- /Chapter17/examples/17.14/print.txt: -------------------------------------------------------------------------------- 1 | Account Last Name First Name Balance 2 | -------------------------------------------------------------------------------- /Chapter17/exercises/17.07/oldmast.dat: -------------------------------------------------------------------------------- 1 | 100 Alan Jones 348.17 2 | 300 Mary Smith 27.19 3 | 500 Sam Sharp 0 4 | 700 Suzy Green -14.22 5 | -------------------------------------------------------------------------------- /Chapter17/exercises/17.07/trans.dat: -------------------------------------------------------------------------------- 1 | 100 27.14 2 | 300 62.11 3 | 700 80.78 4 | 700 1.53 5 | -------------------------------------------------------------------------------- /Chapter17/exercises/17.09/newmast.dat: -------------------------------------------------------------------------------- 1 | 100 Alan Jones 375.31 2 | 300 Mary Smith 89.3 3 | 500 Sam Sharp 0 4 | 700 Suzy Green 68.09 5 | -------------------------------------------------------------------------------- /Chapter17/exercises/17.09/oldmast.dat: -------------------------------------------------------------------------------- 1 | 100 Alan Jones 348.17 2 | 300 Mary Smith 27.19 3 | 500 Sam Sharp 0 4 | 700 Suzy Green -14.22 5 | -------------------------------------------------------------------------------- /Chapter17/exercises/17.09/trans.dat: -------------------------------------------------------------------------------- 1 | 100 27.14 2 | 300 62.11 3 | 700 80.78 4 | 700 1.53 5 | -------------------------------------------------------------------------------- /Chapter17/exercises/17.11/hardware.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter17/exercises/17.11/hardware.dat -------------------------------------------------------------------------------- /Chapter17/exercises/17.12/phone.dat: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Chapter17/exercises/17.14/phising_list.txt: -------------------------------------------------------------------------------- 1 | label 1 2 | invoice 2 3 | post 2 4 | document 1 5 | postal 2 6 | calculations 2 7 | copy 1 8 | fedex 3 9 | statement 3 10 | financial 3 11 | dhl 3 12 | usps 3 13 | 8 1 14 | notification 2 15 | n 1 16 | irs 3 17 | ups 3 18 | no 2 19 | delivery 2 20 | ticket 2 21 | bank 3 22 | help 3 23 | nigeria 3 24 | inheritance 3 25 | prince 3 26 | lawyer 3 27 | overseas 3 28 | transfer 3 29 | wire 2 30 | number 1 31 | -------------------------------------------------------------------------------- /Chapter17/exercises/17.14/test.txt: -------------------------------------------------------------------------------- 1 | The total score of this file should be 15. 2 | a label and an invoice walked into the fedex office. 3 | 4 | They had a beer overseas. The irs came and wrote the number 8 and letter n copy, 5 | -------------------------------------------------------------------------------- /Chapter18/README.md: -------------------------------------------------------------------------------- 1 | #### Chapter 18 Incomplete Solutions 2 | 3 | *If you have a solution feel free to contribute* 4 | 5 | - [18.25](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter18/exercises/18.25/) - *Simple Decryption* 6 | -------------------------------------------------------------------------------- /Chapter18/examples/18.03/fig18_03.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig18_03.cpp 5 | * 6 | * Description: Fig. 18.3 - Demonstrating string member function substr 7 | * 8 | * Version: 1.0 9 | * Created: 09/02/17 16:21:38 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | #include 20 | 21 | int main(int argc, const char* argv[]) { 22 | std::string string1("The airplane landed on time."); 23 | 24 | // retrieve substring "plane" which begins at 25 | // subscript 7 and consists of 5 characters 26 | std::cout << string1.substr(7, 5) << std::endl; 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Chapter18/examples/18.04/fig18_04.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: fig18_04.cpp 5 | * 6 | * Description: Fig. 18.04 - Using the swap function to swap two strings 7 | * 8 | * Version: 1.0 9 | * Created: 09/02/17 16:23:42 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | #include 20 | 21 | int main(int argc, const char* argv[]) { 22 | std::string first("one"); 23 | std::string second("two"); 24 | 25 | // output strings 26 | std::cout << "Before swap:\n first: " << first << "\nsecond: " << second; 27 | 28 | first.swap(second); 29 | 30 | std::cout << "\n\nAfter swap:\n first: " << first << "\nsecond: " << second 31 | << std::endl; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Chapter18/exercises/18.08/ex_1808.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_1808.cpp 5 | * 6 | * Description: Exercise 18.08 - Using string Iterators 7 | * 8 | * Version: 1.0 9 | * Created: 10/02/17 16:23:07 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | #include 20 | 21 | int main(int argc, const char* argv[]) { 22 | std::string str = "now step live..."; 23 | 24 | std::string::reverse_iterator rit = str.rbegin(); 25 | 26 | while (rit != str.rend()) { 27 | std::cout << *(rit++); 28 | } 29 | std::cout << std::endl; 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Chapter18/exercises/18.15/ex_1815.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: ex_1815.cpp 5 | * 6 | * Description: Exercise 18.15 - Solving Cryptograms 7 | * 8 | * Version: 1.0 9 | * Created: 19/02/18 09:53:51 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ============================================================================= 17 | */ 18 | #include "Cryptograms.hpp" 19 | 20 | /** 21 | * This is the main method. 22 | * @param argc. 23 | * @param argv[]. 24 | * @return int. 25 | */ 26 | int main(int argc, char* argv[]) { 27 | Cryptograms cr; 28 | 29 | cr.play(); 30 | 31 | return 0; 32 | } // end method main 33 | -------------------------------------------------------------------------------- /Chapter18/exercises/18.18/ex_1818.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_1818.cpp 5 | * 6 | * Description: Exercise 18.18 - String Insertion 7 | * 8 | * Version: 1.0 9 | * Created: 20/02/17 11:50:45 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | #include 20 | 21 | int main(int argc, const char* argv[]) { 22 | std::cout << "Enter a string: "; 23 | 24 | std::string base; 25 | std::getline(std::cin, base); 26 | 27 | std::string insertStr = "******"; 28 | 29 | base.insert((base.length() / 2), insertStr); 30 | 31 | std::cout << "\nNew String:\n" << base << std::endl; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Chapter18/exercises/18.23/ex_1823.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_1823.cpp 5 | * 6 | * Description: Exercise 18.23 - Using the erase Function with Iterator 7 | * Arguments 8 | * NOTE: Lifted straight from 9 | * http://www.cplusplus.com/reference/string/string/erase/ 10 | * 11 | * Version: 1.0 12 | * Created: 20/02/17 17:25:25 13 | * Revision: none 14 | * Compiler: g++ 15 | * 16 | * Author: Siidney Watson - siidney.watson.work@gmail.com 17 | * Organization: LolaDog Studio 18 | * 19 | * ===================================================================================== 20 | */ 21 | #include 22 | #include 23 | 24 | int main(int argc, const char* argv[]) { 25 | std::string str("This is an sentence"); 26 | 27 | str.erase(str.begin() + 9); 28 | std::cout << str << std::endl; 29 | 30 | str.erase(str.begin() + 5, str.end() - 9); 31 | std::cout << str << std::endl; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Chapter18/exercises/18.25/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter18/exercises/18.25/empty -------------------------------------------------------------------------------- /Chapter18/exercises/18.28/alternatives: -------------------------------------------------------------------------------- 1 | sour creme;1;cup 2 | yogurt;1;cup 3 | 4 | milk;1;cup 5 | evaporated milk;0.5;cup 6 | water;0.5;cup 7 | 8 | lemon juice;1;teaspoon 9 | vinegar;0.5;teaspoon 10 | 11 | sugar;1;cup 12 | honey;0.5;cup 13 | molasses;1;cup 14 | agave nectar;0.25;cup 15 | 16 | butter;1;cup 17 | margarine;1;cup 18 | yogurt;1;cup 19 | 20 | mayonnaise;1;cup 21 | cottage cheese;1;cup 22 | mayonnaise;0.125;cup 23 | yogurt;0.875;cup 24 | 25 | egg;1;whole 26 | cornstarch;2;tablespoons 27 | arrowroot flower;2;tablespoons 28 | potato starch;2;tablespoons 29 | egg whites;2;whole 30 | large banana;0.5;mushed 31 | 32 | milk;1;cup 33 | soy milk;1;cup 34 | 35 | oil;0.25;cup 36 | applesauce;0.25;cup 37 | 38 | white bread;1;slice 39 | whole-grain bread;1;slice 40 | 41 | flour;1;cup 42 | rye;1;cup 43 | rice;1;cup 44 | -------------------------------------------------------------------------------- /Chapter18/exercises/18.28/ex_1828.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_1828.cpp 5 | * 6 | * Description: Exercise 18.28 - Cooking with Healthier Ingredients 7 | * 8 | * Version: 1.0 9 | * Created: 03/03/17 17:00:51 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "IngredientSwitcher.hpp" 19 | 20 | int main(int argc, const char* argv[]) { 21 | IngredientSwitcher is; 22 | 23 | is.run(); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Chapter18/exercises/18.29/README.md: -------------------------------------------------------------------------------- 1 | This is the same as [17.14](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter17/exercises/17.14/) simply using a different list of words. 2 | 3 | There is no point in replicating it here. 4 | -------------------------------------------------------------------------------- /Chapter18/exercises/18.30/ex_1830.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: ex_1830.cpp 5 | * 6 | * Description: Exercise 18.30 - SMS Language 7 | * 8 | * Version: 1.0 9 | * Created: 05/03/17 19:35:05 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "SMSDecoder.hpp" 19 | 20 | int main(int argc, const char* argv[]) { 21 | SMSDecoder smsd; 22 | 23 | smsd.run(); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Chapter18/exercises/README.md: -------------------------------------------------------------------------------- 1 | Exercise 18.25 - Incomplete 2 | -------------------------------------------------------------------------------- /Chapter19/README.md: -------------------------------------------------------------------------------- 1 | #### Chapter 19 Incomplete Solutions 2 | 3 | *If you have a solution feel free to contribute* 4 | 5 | - [19.07](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter19/exercises/19.07) - *Bucket Sort* 6 | -------------------------------------------------------------------------------- /Chapter19/exercises/19.07/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter19/exercises/19.07/empty -------------------------------------------------------------------------------- /Chapter20/README.md: -------------------------------------------------------------------------------- 1 | #### Chapter 20 Incomplete Solutions 2 | 3 | *If you have a solution feel free to contribute* 4 | 5 | - [20.22](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter20/exercises/20.22/) - *Binary Tree Delete* 6 | - [20.30](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter20/exercises/20.30/) - *Indexed Lists* 7 | -------------------------------------------------------------------------------- /Chapter20/exercises/20.22/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter20/exercises/20.22/empty -------------------------------------------------------------------------------- /Chapter20/exercises/20.30/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter20/exercises/20.30/empty -------------------------------------------------------------------------------- /Chapter21/README.md: -------------------------------------------------------------------------------- 1 | #### Chapter 21 Incomplete Solutions 2 | 3 | *If you have a solution feel free to contribute* 4 | 5 | - [21.12](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter21/exercises/21.12/) - *Reversing Bits* 6 | - [21.28](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter21/exercises/21.28/) - *Write Your Own String Conversion Functions* 7 | - [21.35](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter21/exercises/21.35/) - *Limericks* 8 | - [21.40](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter21/exercises/21.40/) - *Write You Own String Copy and Concatenation Functions* 9 | -------------------------------------------------------------------------------- /Chapter21/examples/21.02/fig21_04.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: fig21_04.cpp 5 | * 6 | * Description: Fig. 21.4: Card Shuffling and dealing program. 7 | * 8 | * Version: 1.0 9 | * Created: 21/02/18 12:33:37 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ============================================================================= 17 | */ 18 | #include "DeckOfCards.h" 19 | 20 | /** 21 | * This is the main method. 22 | * @param argc. 23 | * @param argv[]. 24 | * @return int. 25 | */ 26 | int main(int argc, char* argv[]) { 27 | DeckOfCards deckOfCards; // create DeckOfCards object 28 | deckOfCards.shuffle(); // shuffle the cards in the deck 29 | deckOfCards.deal(); // deal the cards in the deck 30 | 31 | return 0; 32 | } // end method main 33 | -------------------------------------------------------------------------------- /Chapter21/examples/21.14/fig21_16.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: fig21_16.cpp 5 | * 6 | * Description: Fig. 21.16: Card shuffling and dealing program. 7 | * 8 | * Version: 1.0 9 | * Created: 26/02/18 10:02:16 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ============================================================================= 17 | */ 18 | #include "DeckOfCards.h" 19 | 20 | /** 21 | * This is the main method. 22 | * @param argc. 23 | * @param argv[]. 24 | * @return int. 25 | */ 26 | int main(int argc, char* argv[]) { 27 | DeckOfCards deckOfCards; // create DeckOfCards object 28 | deckOfCards.deal(); 29 | 30 | return 0; 31 | } // end method main 32 | -------------------------------------------------------------------------------- /Chapter21/examples/21.28/fig21_28.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: fig21_28.cpp 5 | * 6 | * Description: Fig. 21.29: Using atof. 7 | * 8 | * Version: 1.0 9 | * Created: 27/02/18 11:10:16 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ============================================================================= 17 | */ 18 | #include 19 | #include // atof prototype 20 | 21 | /** 22 | * This is the main method. 23 | * @param argc. 24 | * @param argv[]. 25 | * @return int. 26 | */ 27 | int main(int argc, char* argv[]) { 28 | double d = atof("99.0"); // convert string to double 29 | 30 | std::cout << "The string \"99.0\" converted to double is " << d 31 | << "\nThe converted value divided by 2 is " << d / 2.0 << std::endl; 32 | 33 | return 0; 34 | } // end method main 35 | -------------------------------------------------------------------------------- /Chapter21/examples/21.29/fig21_29.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: fig21_29.cpp 5 | * 6 | * Description: Fig. 21.29: Using atoi. 7 | * 8 | * Version: 1.0 9 | * Created: 27/02/18 11:13:01 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ============================================================================= 17 | */ 18 | #include 19 | #include // atoi prototype 20 | 21 | /** 22 | * This is the main method. 23 | * @param argc. 24 | * @param argv[]. 25 | * @return int. 26 | */ 27 | int main(int argc, char* argv[]) { 28 | int i = atoi("2593"); // convert string to int 29 | 30 | std::cout << "The string \"2593\" converted to int is " << i 31 | << "\nThe converted value minus 593 is " << i - 593 << std::endl; 32 | 33 | return 0; 34 | } // end method main 35 | -------------------------------------------------------------------------------- /Chapter21/examples/21.30/fig21_30.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: fig21_30.cpp 5 | * 6 | * Description: Fig. 21.30: Using atol. 7 | * 8 | * Version: 1.0 9 | * Created: 27/02/18 11:15:08 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ============================================================================= 17 | */ 18 | #include 19 | #include // atol prototype 20 | 21 | /** 22 | * This is the main method. 23 | * @param argc. 24 | * @param argv[]. 25 | * @return int. 26 | */ 27 | int main(int argc, char* argv[]) { 28 | long x = atol("10000000"); // convert string to long 29 | 30 | std::cout << "The string \"10000000\" converted to long is " << x 31 | << "\nThe converted value divided by 2 is " << x / 2 << std::endl; 32 | 33 | return 0; 34 | } // end method main 35 | -------------------------------------------------------------------------------- /Chapter21/examples/21.43/fig21_43.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: fig21_43.cpp 5 | * 6 | * Description: Fig. 21.43: Using memove. 7 | * 8 | * Version: 1.0 9 | * Created: 27/02/18 11:54:40 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ============================================================================= 17 | */ 18 | #include 19 | #include // memove prototype 20 | 21 | /** 22 | * This is the main method. 23 | * @param argc. 24 | * @param argv[]. 25 | * @return int. 26 | */ 27 | int main(int argc, char* argv[]) { 28 | char x[] = "Home Sweet Home"; 29 | 30 | std::cout << "The string in array x before memove is: " << x; 31 | std::cout << "\nThe string in array x after memove is: " 32 | << static_cast(memmove(x, &x[5], 10)) << std::endl; 33 | 34 | return 0; 35 | } // end method main 36 | -------------------------------------------------------------------------------- /Chapter21/examples/21.45/fig21_45.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: fig21_45.cpp 5 | * 6 | * Description: Fig. 21.45: Using memchr 7 | * 8 | * Version: 1.0 9 | * Created: 27/02/18 12:03:10 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ============================================================================= 17 | */ 18 | #include 19 | #include // memchr prototype 20 | 21 | /** 22 | * This is the main method. 23 | * @param argc. 24 | * @param argv[]. 25 | * @return int. 26 | */ 27 | int main(int argc, char* argv[]) { 28 | char s[] = "This is a string"; 29 | 30 | std::cout << "s = " << s << "\n" << std::endl; 31 | std::cout << "The remainder of s after character 'r' is found is \"" 32 | << static_cast(memchr(s, 'r', 16)) << '\"' << std::endl; 33 | 34 | return 0; 35 | } // end method main 36 | -------------------------------------------------------------------------------- /Chapter21/examples/21.46/fig21_46.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: fig21_46.cpp 5 | * 6 | * Description: Fig. 21.46: Using memset. 7 | * 8 | * Version: 1.0 9 | * Created: 27/02/18 12:05:30 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ============================================================================= 17 | */ 18 | #include 19 | #include // memset prototype 20 | 21 | /** 22 | * This is the main method. 23 | * @param argc. 24 | * @param argv[]. 25 | * @return int. 26 | */ 27 | int main(int argc, char* argv[]) { 28 | char string1[15] = "BBBBBBBBBBBBBB"; 29 | 30 | std::cout << "string1 = " << string1 << std::endl; 31 | std::cout << "string1 after memset = " 32 | << static_cast(memset(string1, 'b', 7)) << std::endl; 33 | 34 | return 0; 35 | } // end method main 36 | -------------------------------------------------------------------------------- /Chapter21/exercises/21.05/ex_2105.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: ex_2105.cpp 5 | * 6 | * Description: Exercise 21.05 - Card Shuffling and Dealing. 7 | * 8 | * Version: 1.0 9 | * Created: 27/02/18 12:17:04 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ============================================================================= 17 | */ 18 | #include "DeckOfCards.hpp" 19 | 20 | /** 21 | * This is the main method. 22 | * @param argc. 23 | * @param argv[]. 24 | * @return int. 25 | */ 26 | int main(int argc, char* argv[]) { 27 | DeckOfCards deck; 28 | 29 | deck.shuffle(); 30 | deck.deal(); 31 | 32 | return 0; 33 | } // end method main 34 | -------------------------------------------------------------------------------- /Chapter21/exercises/21.06/ex_2106.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: ex_2106.cpp 5 | * 6 | * Description: Exercise 21.06 - Shifting and Printing an Integer. 7 | * 8 | * Version: 1.0 9 | * Created: 27/02/18 12:32:25 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ============================================================================= 17 | */ 18 | #include 19 | #include 20 | 21 | /** 22 | * This is the main method. 23 | * @param argc. 24 | * @param argv[]. 25 | * @return int. 26 | */ 27 | int main(int argc, char* argv[]) { 28 | int i = 16; 29 | 30 | std::cout << "i = " << std::bitset<8>(i) << "\ni >> 4 = "; 31 | i = i >> 4; 32 | std::cout << std::bitset<8>(i) << std::endl; 33 | 34 | return 0; 35 | } // end method main 36 | -------------------------------------------------------------------------------- /Chapter21/exercises/21.09/README.md: -------------------------------------------------------------------------------- 1 | See [21.08](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter21/exercises/21.08/ex_2108.cpp) 2 | -------------------------------------------------------------------------------- /Chapter21/exercises/21.11/README.md: -------------------------------------------------------------------------------- 1 | See [21.10](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter21/exercises/21.10/ex_2110.cpp) 2 | -------------------------------------------------------------------------------- /Chapter21/exercises/21.12/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter21/exercises/21.12/empty -------------------------------------------------------------------------------- /Chapter21/exercises/21.33/ex_2133.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: ex_2133.cpp 5 | * 6 | * Description: Exercise 21.33 - Comparing Strings 7 | * 8 | * Version: 1.0 9 | * Created: 19/03/18 15:49:23 10 | * Revision: none 11 | * Compiler: g++ 12 | * 13 | * Author: Siidney Watson - siidney.watson.work@gmail.com 14 | * Organization: LolaDog Studio 15 | * 16 | * ============================================================================= 17 | */ 18 | #include 19 | #include 20 | 21 | /** 22 | * This is the main method. 23 | * @param argc. 24 | * @param argv[]. 25 | * @return int. 26 | */ 27 | int main(int argc, char* argv[]) { 28 | char str[][5] = { "ZXab", "zxAB", "ZXbc" }; 29 | 30 | for (int i = 0; i < 3; ++i) { 31 | if (strncmp(str[i], "ZXxx", 2) == 0) { printf("Found: %s\n", str[i]); } 32 | } 33 | 34 | return 0; 35 | } // end method main 36 | -------------------------------------------------------------------------------- /Chapter21/exercises/21.35/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siidney/Cpp-How-To-Program-9E/4a9064016efea74bea2af2af8f05bb42f70e4c00/Chapter21/exercises/21.35/empty -------------------------------------------------------------------------------- /Chapter21/exercises/21.41/README.md: -------------------------------------------------------------------------------- 1 | Solutions included with [21.40](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter21/exercises/21.40/) - *Write You Own String Copy and Concatenation Functions* 2 | 3 | -------------------------------------------------------------------------------- /Chapter21/exercises/21.42/README.md: -------------------------------------------------------------------------------- 1 | Solutions included with [21.40](https://gitlab.com/siidney/Cpp-How-To-Program-9E/blob/master/Chapter21/exercises/21.40/) - *Write You Own String Copy and Concatenation Functions* 2 | 3 | --------------------------------------------------------------------------------