Loading problems/LabFour_ChapterEleven.h +75 −3 Original line number Diff line number Diff line Loading @@ -2,7 +2,79 @@ // Created by Ari Trachtenberg on 11/1/24. // #ifndef CURRENT_LABFOUR_CHAPTERELEVEN_H #define CURRENT_LABFOUR_CHAPTERELEVEN_H // Chapter 11 #include <vector> using namespace std; #endif //CURRENT_LABFOUR_CHAPTERELEVEN_H /** * Recursively count the number of different ways of exchanging * [dollars] dollars for the following bills: $1, $5, $20, $100. * * Two approaches are different if and only if they differ in the * number of at least one denomination of bills. So $8 = $1+$2+$5 * is the same as $8 = $5+$2+1, but different from $5 + 3*$1. * * @param dollars The amount of dollars to exchange * @return the number of different ways of generating [dollars] * dollars with the permitted bills * * @example labFour_pTwo_exchange(8) = 6 corresponding to the * following ways to exchange $8: * 1. 8*$1 * 2. 6*$1+$2 * 3. 4*$1+2*$2 * 4. 4*$2 * 5. 3*$1 +$5 * 6. $1 +$2 +$5 */ int labFour_pTwo_exchange(int dollars); /** * Recursively computes the a term in a Generalized Fibonacce sequence. * * The nn-th term in the sequence is the dot-product between * the filter and the last filter.size() previous elements of * the sequence, with negatively-indexed sequence elements all * being 1. * * @param filter The filter for the sequence. * @param nn The term in the sequence that is desired, with nn=0 being * the first term. * @return the [nn]th number in a Generalized Fibonacci sequence with * filter [filter]. * * @example 1 * labFour_pThree_genFib({1,1},n) produces the n+4-th Fibonacci numbers: * n | labFour_pThree_genFib({1,1},n) * -2 | 1 // hard-coded * -1 | 1 // hard-coded * 0 | 2 = 1+1 * 1 | 3 = 2+1 * 2 | 5 = 3+2 * 3 | 8 = 5*3 * * @example 2 * labFour_pThree_genFib({1,0,1},n) produces: * n | labFour_pThree_genFib({1,0,1},n) * -3 | 1 // hard-coded * -2 | 1 // hard-coded * -1 | 1 // hard-coded * 0 | 2 = 1+1 * 1 | 3 = 2+1 * 2 | 4 = 3+1 * 3 | 6 = 4+2 * 4 | 9 = 6+3 * * @example 3 * labFour_pThree_genFib({0.25 ,0.25 ,0.25, 0.25},n) produces: * n | labFour_pThree_genFib({0.25 ,0.25 ,0.5, 0.5},n) * -4 | 1 // hard-coded * -3 | 1 // hard-coded * -2 | 1 // hard-coded * -1 | 1 // hard-coded * 0 | 1.5 = 0.25+ 0.25+ 0.5+ 0.5 * 1 | 1.75 = 0.25+ 0.25+ 0.5+ 0.75 * 2 | 1.875 = 0.25+ 0.25+ 0.75+ 0.875 * 3 | 2.4375 = 0.25+ 0.375+ 0.875+ 0.9375 */ int labFour_pThree_genFib(vector<float> filter, int nn); No newline at end of file problems/LabFour_ChapterTen.h +42 −17 Original line number Diff line number Diff line Loading @@ -42,15 +42,35 @@ class labFour_pZero_Instructor; * * labFour_pOne_Square - a concrete class representing a square * * labFour_pOne_Rhombus - a concrete class representing a rhombus * * labFour_pOne_Circle - a concrete class representing a cicle * Feel free to modify the inheritance structure, as you see fit. * FEEL FREE to modify the inheritance structure, as you see fit. * * EACH concrete class must at least have methods with the signatures noted below * and also: * float getPerimeter() - returns the perimeter of the object * float getArea() - returns the area o the object * * @example * labFour_pOne_Quadrilateral q1( * {1, 1}, * {1, 2}, * {2, 2}, * {2, 1}); // area 1, perimeter 4 * labFour_pOne_Rectangle re1({0, 0}, 1, 2); // area 2, perimeter 6 * labFour_pOne_Square s1({1, 3}, 3); //area 9, perimeter 12 * labFour_pOne_Rhombus rh1({1, 1}, 1, 45); // area sqrt(2)/2, perimeter 4 * labFour_pOne_Circle({0, 0}, 1); // area pi, perimeter 2*pi * * vector<labFour_pOne_GeometricThing> things = {q1, re1, s1, rh1}; * * labFour_pOne_GeometricThing::sumAreas(things); // returns 2+9+sqrt(2)/2+pi = 14.8487... * labFour_pOne_GeometricThing::sumPerimeters(things); // returns 6+12+4+2*pi = 28.2832... * */ class labFour_pOne_GeometricThing { public: /** * Represents a two-dimensional point. */ class Point { public: Point(int Xcor, int Ycor) : x(Xcor), y(Ycor) {} Loading @@ -75,13 +95,14 @@ public: class labFour_pOne_Quadrilateral : public labFour_pOne_GeometricThing { public: /** * Constructs a Quadrilateral on four points p0-p3, provided in clock-wise order. * Constructs a Quadrilateral on four points p0-p3, provided * in clock-wise order. */ labFour_pOne_Quadrilateral(Point p0, Point p1, Point p2, Point p3); }; class labFour_pOne_Rectangle : public labFour_pOne_GeometricThing { public: /** * Constructs a rectangle. * @param UpperLeft The upper-left point of the rectangle. Loading @@ -92,6 +113,7 @@ class labFour_pOne_Rectangle : public labFour_pOne_GeometricThing { }; class labFour_pOne_Square : public labFour_pOne_GeometricThing { public: /** * Constructs a square. * @param UpperLeft The upper-left point of the square. Loading @@ -101,16 +123,19 @@ class labFour_pOne_Square : public labFour_pOne_GeometricThing { }; class labFour_pOne_Rhombus : public labFour_pOne_GeometricThing { public: /** * Constructs a rhombus. * @param UpperLeft The upper-left point of the rhombus. * @param length The length of a side of the rhombus. * @param angle The smallest angle between two sides of the rhombus. * @param angle The smallest angle between * two sides of the rhombus, in degrees. */ labFour_pOne_Rhombus(Point UpperLeft, int length, float angle); }; class labFour_pOne_Circle : public labFour_pOne_GeometricThing { public: /** * Constructs a circle. * @param center The center of the circle. Loading Loading
problems/LabFour_ChapterEleven.h +75 −3 Original line number Diff line number Diff line Loading @@ -2,7 +2,79 @@ // Created by Ari Trachtenberg on 11/1/24. // #ifndef CURRENT_LABFOUR_CHAPTERELEVEN_H #define CURRENT_LABFOUR_CHAPTERELEVEN_H // Chapter 11 #include <vector> using namespace std; #endif //CURRENT_LABFOUR_CHAPTERELEVEN_H /** * Recursively count the number of different ways of exchanging * [dollars] dollars for the following bills: $1, $5, $20, $100. * * Two approaches are different if and only if they differ in the * number of at least one denomination of bills. So $8 = $1+$2+$5 * is the same as $8 = $5+$2+1, but different from $5 + 3*$1. * * @param dollars The amount of dollars to exchange * @return the number of different ways of generating [dollars] * dollars with the permitted bills * * @example labFour_pTwo_exchange(8) = 6 corresponding to the * following ways to exchange $8: * 1. 8*$1 * 2. 6*$1+$2 * 3. 4*$1+2*$2 * 4. 4*$2 * 5. 3*$1 +$5 * 6. $1 +$2 +$5 */ int labFour_pTwo_exchange(int dollars); /** * Recursively computes the a term in a Generalized Fibonacce sequence. * * The nn-th term in the sequence is the dot-product between * the filter and the last filter.size() previous elements of * the sequence, with negatively-indexed sequence elements all * being 1. * * @param filter The filter for the sequence. * @param nn The term in the sequence that is desired, with nn=0 being * the first term. * @return the [nn]th number in a Generalized Fibonacci sequence with * filter [filter]. * * @example 1 * labFour_pThree_genFib({1,1},n) produces the n+4-th Fibonacci numbers: * n | labFour_pThree_genFib({1,1},n) * -2 | 1 // hard-coded * -1 | 1 // hard-coded * 0 | 2 = 1+1 * 1 | 3 = 2+1 * 2 | 5 = 3+2 * 3 | 8 = 5*3 * * @example 2 * labFour_pThree_genFib({1,0,1},n) produces: * n | labFour_pThree_genFib({1,0,1},n) * -3 | 1 // hard-coded * -2 | 1 // hard-coded * -1 | 1 // hard-coded * 0 | 2 = 1+1 * 1 | 3 = 2+1 * 2 | 4 = 3+1 * 3 | 6 = 4+2 * 4 | 9 = 6+3 * * @example 3 * labFour_pThree_genFib({0.25 ,0.25 ,0.25, 0.25},n) produces: * n | labFour_pThree_genFib({0.25 ,0.25 ,0.5, 0.5},n) * -4 | 1 // hard-coded * -3 | 1 // hard-coded * -2 | 1 // hard-coded * -1 | 1 // hard-coded * 0 | 1.5 = 0.25+ 0.25+ 0.5+ 0.5 * 1 | 1.75 = 0.25+ 0.25+ 0.5+ 0.75 * 2 | 1.875 = 0.25+ 0.25+ 0.75+ 0.875 * 3 | 2.4375 = 0.25+ 0.375+ 0.875+ 0.9375 */ int labFour_pThree_genFib(vector<float> filter, int nn); No newline at end of file
problems/LabFour_ChapterTen.h +42 −17 Original line number Diff line number Diff line Loading @@ -42,15 +42,35 @@ class labFour_pZero_Instructor; * * labFour_pOne_Square - a concrete class representing a square * * labFour_pOne_Rhombus - a concrete class representing a rhombus * * labFour_pOne_Circle - a concrete class representing a cicle * Feel free to modify the inheritance structure, as you see fit. * FEEL FREE to modify the inheritance structure, as you see fit. * * EACH concrete class must at least have methods with the signatures noted below * and also: * float getPerimeter() - returns the perimeter of the object * float getArea() - returns the area o the object * * @example * labFour_pOne_Quadrilateral q1( * {1, 1}, * {1, 2}, * {2, 2}, * {2, 1}); // area 1, perimeter 4 * labFour_pOne_Rectangle re1({0, 0}, 1, 2); // area 2, perimeter 6 * labFour_pOne_Square s1({1, 3}, 3); //area 9, perimeter 12 * labFour_pOne_Rhombus rh1({1, 1}, 1, 45); // area sqrt(2)/2, perimeter 4 * labFour_pOne_Circle({0, 0}, 1); // area pi, perimeter 2*pi * * vector<labFour_pOne_GeometricThing> things = {q1, re1, s1, rh1}; * * labFour_pOne_GeometricThing::sumAreas(things); // returns 2+9+sqrt(2)/2+pi = 14.8487... * labFour_pOne_GeometricThing::sumPerimeters(things); // returns 6+12+4+2*pi = 28.2832... * */ class labFour_pOne_GeometricThing { public: /** * Represents a two-dimensional point. */ class Point { public: Point(int Xcor, int Ycor) : x(Xcor), y(Ycor) {} Loading @@ -75,13 +95,14 @@ public: class labFour_pOne_Quadrilateral : public labFour_pOne_GeometricThing { public: /** * Constructs a Quadrilateral on four points p0-p3, provided in clock-wise order. * Constructs a Quadrilateral on four points p0-p3, provided * in clock-wise order. */ labFour_pOne_Quadrilateral(Point p0, Point p1, Point p2, Point p3); }; class labFour_pOne_Rectangle : public labFour_pOne_GeometricThing { public: /** * Constructs a rectangle. * @param UpperLeft The upper-left point of the rectangle. Loading @@ -92,6 +113,7 @@ class labFour_pOne_Rectangle : public labFour_pOne_GeometricThing { }; class labFour_pOne_Square : public labFour_pOne_GeometricThing { public: /** * Constructs a square. * @param UpperLeft The upper-left point of the square. Loading @@ -101,16 +123,19 @@ class labFour_pOne_Square : public labFour_pOne_GeometricThing { }; class labFour_pOne_Rhombus : public labFour_pOne_GeometricThing { public: /** * Constructs a rhombus. * @param UpperLeft The upper-left point of the rhombus. * @param length The length of a side of the rhombus. * @param angle The smallest angle between two sides of the rhombus. * @param angle The smallest angle between * two sides of the rhombus, in degrees. */ labFour_pOne_Rhombus(Point UpperLeft, int length, float angle); }; class labFour_pOne_Circle : public labFour_pOne_GeometricThing { public: /** * Constructs a circle. * @param center The center of the circle. Loading