Skip to content
Commits on Source (142)
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/settings.json
......@@ -2,14 +2,17 @@ stages:
- labm1
- lab0
- lab1
#stages:
# - prebuild
# - compile
# - lint
# - test
- lab2
- lab3
- lab4
- lab5
- tests
include:
- local: 'ci_cd/labm1.yml' # Lab -1
- local: 'ci_cd/lab0.yml' # Lab 0
- local: 'ci_cd/lab1.yml' # Lab 1
\ No newline at end of file
- local: 'ci_cd/lab1.yml' # Lab 1
- local: 'ci_cd/lab2.yml' # Lab 2
- local: 'ci_cd/lab3.yml' # Lab 3
- local: 'ci_cd/lab4.yml' # Lab 4
- local: 'ci_cd/lab5.yml' # Lab 5
\ No newline at end of file
......@@ -2,13 +2,38 @@
prebuild_lab_0:
stage: lab0
script:
- echo "LAB SUBMISSIONS ARE NOW CLOSED FOR THE SEMESTER";
- exit 1
- |
# Check if lab0.cpp exists
if [ ! -f "lab0.cpp" ]; then
echo "lab0.cpp does not exist";
exit 1;
fi
# Check if lab-1.cpp has been merged into master
# git fetch origin master # Fetch the latest master branch
# if git ls-tree -r origin/master --name-only | grep -q 'lab-1.cpp'; then
# echo "Lab -1 complete";
# else
# echo "Please have lab -1 merged first";
# exit 1;
# fi
- git clone https://agile.bu.edu/gitlab/configs/ec327/lab-configs/current.git base_0
artifacts:
paths:
- base_0
rules:
- changes:
- lab0.cpp
- if: '$CI_COMMIT_REF_NAME == "lab0"'
tags: [c++-17]
prebuild_lab_0_SKIP:
stage: lab0
script:
- echo "SKIPPING Lab 0 checks because the branch name is not 'lab0'"
rules:
- if: '$CI_COMMIT_REF_NAME != "lab0"'
tags: [c++-17]
compile_lab_0:
......@@ -20,8 +45,7 @@ compile_lab_0:
paths:
- base_0
rules:
- changes:
- lab0.cpp
- if: '$CI_COMMIT_REF_NAME == "lab0"'
dependencies:
- prebuild_lab_0
tags: [c++-17]
......@@ -36,8 +60,7 @@ lint_lab_0:
paths:
- base_0
rules:
- changes:
- lab0.cpp
- if: '$CI_COMMIT_REF_NAME == "lab0"'
dependencies:
- prebuild_lab_0
tags: [cppcheck]
......@@ -51,8 +74,19 @@ test_lab_0:
- cd base_0/tests
- make lab0
rules:
- changes:
- lab0.cpp
- if: '$CI_COMMIT_REF_NAME == "lab0"'
dependencies:
- compile_lab_0
tags: [c++-17]
\ No newline at end of file
tags: [c++-17]
# trigger internal tests only upon a merge request into master
internal_tests_lab_0:
stage: tests
script:
- git clone https://trachten-gitlab:$INTERNAL_LAB_TESTS@agile.bu.edu/gitlab/ec327/ec327-staff/lab-tests.git
- cp -f lab0.cpp lab-tests/internal_tests/
- cd lab-tests/internal_tests
- make lab0
rules:
- if: '$CI_COMMIT_REF_NAME == "lab0" && $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
tags: [ c++-17 ]
......@@ -2,13 +2,40 @@
prebuild_lab_1:
stage: lab1
script:
- echo "LAB SUBMISSIONS ARE NOW CLOSED FOR THE SEMESTER";
- exit 1
- echo "Changes Detected (if any):";
- git diff --name-only $CI_COMMIT_SHA~ $CI_COMMIT_SHA || echo "No changes found";
- |
# Check if lab0.cpp exists
if [ ! -f "lab1.cpp" ]; then
echo "lab1.cpp does not exist";
exit 1;
fi
# Check if lab0.cpp has been merged into master
# git fetch origin master # Fetch the latest master branch
# if git ls-tree -r origin/master --name-only | grep -q 'lab0.cpp'; then
# echo "Lab 0 complete";
# else
# echo "Please have lab 0 merged first";
# exit 1;
# fi
- git clone https://agile.bu.edu/gitlab/configs/ec327/lab-configs/current.git base_1
artifacts:
paths:
- base_1
rules:
- changes:
- lab1.cpp
- if: '$CI_COMMIT_REF_NAME == "lab1"'
tags: [c++-17]
prebuild_lab_1_SKIP:
stage: lab1
script:
- echo "SKIPPING Lab 1 checks because the branch name is not 'lab1'"
rules:
- if: '$CI_COMMIT_REF_NAME != "lab1"'
tags: [c++-17]
compile_lab_1:
......@@ -22,8 +49,7 @@ compile_lab_1:
dependencies:
- prebuild_lab_1
rules:
- changes:
- lab1.cpp
- if: '$CI_COMMIT_REF_NAME == "lab1"'
tags: [c++-17]
lint_lab_1:
......@@ -38,8 +64,7 @@ lint_lab_1:
dependencies:
- prebuild_lab_1
rules:
- changes:
- lab1.cpp
- if: '$CI_COMMIT_REF_NAME == "lab1"'
tags: [cppcheck]
test_lab_1:
......@@ -53,6 +78,17 @@ test_lab_1:
dependencies:
- compile_lab_1
rules:
- changes:
- lab1.cpp
tags: [c++-17]
\ No newline at end of file
- if: '$CI_COMMIT_REF_NAME == "lab1"'
tags: [c++-17]
# trigger internal tests only upon a merge request into master
internal_tests_lab_1:
stage: tests
script:
- git clone https://trachten-gitlab:$INTERNAL_LAB_TESTS@agile.bu.edu/gitlab/ec327/ec327-staff/lab-tests.git
- cp -f lab1.cpp lab-tests/internal_tests/
- cd lab-tests/internal_tests
- make lab1
rules:
- if: '$CI_COMMIT_REF_NAME == "lab1" && $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
tags: [ c++-17 ]
### Lab 2
prebuild_lab_2:
stage: lab2
script:
- echo "LAB SUBMISSIONS ARE NOW CLOSED FOR THE SEMESTER";
- exit 1
- echo "Changes Detected (if any):";
- git diff --name-only $CI_COMMIT_SHA~ $CI_COMMIT_SHA || echo "No changes found";
- FILES_ADDED=$(git diff --name-only --diff-filter=A HEAD~1 | wc -l)
- |
# Check if lab2.cpp exists
if [ ! -f "lab2.cpp" ]; then
echo "lab2.cpp does not exist";
exit 1;
fi
# Check that only one file was checked in
if [ "FILES_ADDED" -ne 1 ]; then
echo "Error: Only one file should be committed.";
exit 1;
fi
# Check if lab1.cpp has been merged into master
# if git ls-tree -r origin/master --name-only | grep -q 'lab1.cpp'; then
# echo "Lab 1 complete";
# else
# echo "Please have lab 1 merged first";
# exit 1;
# fi
- git clone https://agile.bu.edu/gitlab/configs/ec327/lab-configs/current.git base_2
artifacts:
paths:
- base_2
rules:
- if: '$CI_COMMIT_REF_NAME == "lab2"'
tags: [c++-17]
prebuild_lab_2_SKIP:
stage: lab2
script:
- echo "SKIPPING Lab 2 checks because the branch name is not 'lab2'"
rules:
- if: '$CI_COMMIT_REF_NAME != "lab2"'
tags: [c++-17]
compile_lab_2:
stage: lab2
script:
- echo "Compiling lab2.cpp"
- g++ -c lab2.cpp
artifacts:
paths:
- base_2
dependencies:
- prebuild_lab_2
rules:
- if: '$CI_COMMIT_REF_NAME == "lab2"'
tags: [c++-17]
lint_lab_2:
stage: lab2
script:
- echo "Static code check of lab2.cpp"
- cppcheck --check-config --enable=all --inconclusive --error-exitcode=1 lab2.cpp tests/LabTwo.cpp
allow_failure: false
artifacts:
paths:
- base_2
dependencies:
- prebuild_lab_2
rules:
- if: '$CI_COMMIT_REF_NAME == "lab2"'
tags: [cppcheck]
test_lab_2:
stage: lab2
script:
- echo "Testing Lab 2";
- git clone https://agile.bu.edu/gitlab/configs/ec327/lab-configs/current.git base_2
- cp lab2.cpp base_2/tests
- cd base_2/tests
- make lab2
dependencies:
- compile_lab_2
rules:
- if: '$CI_COMMIT_REF_NAME == "lab2"'
tags: [c++-17]
# trigger internal tests only upon a merge request into master
internal_tests_lab_2:
stage: tests
script:
- git clone https://trachten-gitlab:$INTERNAL_LAB_TESTS@agile.bu.edu/gitlab/ec327/ec327-staff/lab-tests.git
- cp -f lab2.cpp lab-tests/internal_tests/
- cd lab-tests/internal_tests
- make lab2
rules:
- if: '$CI_COMMIT_REF_NAME == "lab2" && $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
tags: [ c++-17 ]
### Lab 3
prebuild_lab_3:
stage: lab3
script:
- echo "LAB SUBMISSIONS ARE NOW CLOSED FOR THE SEMESTER";
- exit 1
- echo "Changes Detected (if any):";
- git diff --name-only $CI_COMMIT_SHA~ $CI_COMMIT_SHA || echo "No changes found";
- FILES_ADDED=$(git diff --name-only --diff-filter=A HEAD~1 | wc -l)
- |
# Check if lab3.cpp exists
if [ ! -f "lab3.cpp" ]; then
echo "lab3.cpp does not exist";
exit 1;
fi
# Check that only one file was checked in
if [ "FILES_ADDED" -ne 1 ]; then
echo "Error: Only one file should be committed.";
exit 1;
fi
# Check if lab2.cpp has been merged into master
# if git ls-tree -r origin/master --name-only | grep -q 'lab2.cpp'; then
# echo "Lab 2 complete";
# else
# echo "Please have lab 2 merged first";
# exit 1;
# fi
- git clone https://agile.bu.edu/gitlab/configs/ec327/lab-configs/current.git base_3
artifacts:
paths:
- base_3
rules:
- if: '$CI_COMMIT_REF_NAME == "lab3"'
tags: [c++-17]
prebuild_lab_3_SKIP:
stage: lab3
script:
- echo "SKIPPING Lab 3 checks because the branch name is not 'lab3'"
rules:
- if: '$CI_COMMIT_REF_NAME != "lab3"'
tags: [c++-17]
compile_lab_3:
stage: lab3
script:
- echo "Compiling lab3.cpp"
- g++ -c lab3.cpp
artifacts:
paths:
- base_3
dependencies:
- prebuild_lab_3
rules:
- if: '$CI_COMMIT_REF_NAME == "lab3"'
tags: [c++-17]
lint_lab_3:
stage: lab3
script:
- echo "Static code check of lab3.cpp"
- cppcheck --check-config --enable=all --inconclusive --error-exitcode=1 lab3.cpp tests/LabTwo.cpp
allow_failure: false
artifacts:
paths:
- base_3
dependencies:
- prebuild_lab_3
rules:
- if: '$CI_COMMIT_REF_NAME == "lab3"'
tags: [cppcheck]
test_lab_3:
stage: lab3
script:
- echo "Testing Lab 3";
- git clone https://agile.bu.edu/gitlab/configs/ec327/lab-configs/current.git base_3
- cp lab3.cpp base_3/tests
- cd base_3/tests
- make lab3
dependencies:
- compile_lab_3
rules:
- if: '$CI_COMMIT_REF_NAME == "lab3"'
tags: [c++-17]
# trigger internal tests only upon a merge request into master
internal_tests_lab_3:
stage: tests
script:
- git clone https://trachten-gitlab:$INTERNAL_LAB_TESTS@agile.bu.edu/gitlab/ec327/ec327-staff/lab-tests.git
- cp -f lab3.cpp lab-tests/internal_tests/
- cd lab-tests/internal_tests
- make lab3
rules:
- if: '$CI_COMMIT_REF_NAME == "lab3" && $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
tags: [ c++-17 ]
### Lab 4
prebuild_lab_4:
stage: lab4
script:
- echo "LAB SUBMISSIONS ARE NOW CLOSED FOR THE SEMESTER";
- exit 1
- echo "Changes Detected (if any):";
- git diff --name-only $CI_COMMIT_SHA~ $CI_COMMIT_SHA || echo "No changes found";
- FILES_ADDED=$(git diff --name-only --diff-filter=A HEAD~1 | wc -l)
- |
# Check if lab4.cpp exists
if [ ! -f "lab4.cpp" ]; then
echo "lab4.cpp does not exist";
exit 1;
fi
# Check that only one file was checked in
if [ "FILES_ADDED" -ne 1 ]; then
echo "Error: Only one file should be committed.";
exit 1;
fi
# Check if lab3.cpp has been merged into master
# if git ls-tree -r origin/master --name-only | grep -q 'lab3.cpp'; then
# echo "Lab 3 complete";
# else
# echo "Please have lab 3 merged first";
# exit 1;
# fi
- git clone https://agile.bu.edu/gitlab/configs/ec327/lab-configs/current.git base_4
artifacts:
paths:
- base_4
rules:
- if: '$CI_COMMIT_REF_NAME == "lab4"'
tags: [c++-17]
prebuild_lab_4_SKIP:
stage: lab4
script:
- echo "SKIPPING Lab 4 checks because the branch name is not 'lab4'"
rules:
- if: '$CI_COMMIT_REF_NAME != "lab4"'
tags: [c++-17]
compile_lab_4:
stage: lab4
script:
- echo "Compiling lab4.cpp"
- g++ -c lab4.cpp
artifacts:
paths:
- base_4
dependencies:
- prebuild_lab_4
rules:
- if: '$CI_COMMIT_REF_NAME == "lab4"'
tags: [c++-17]
lint_lab_4:
stage: lab4
script:
- echo "Static code check of lab4.cpp"
- cppcheck --check-config --enable=all --inconclusive --error-exitcode=1 lab4.cpp tests/LabFour.cpp
allow_failure: false
artifacts:
paths:
- base_4
dependencies:
- prebuild_lab_4
rules:
- if: '$CI_COMMIT_REF_NAME == "lab4"'
tags: [cppcheck]
test_lab_4:
stage: lab4
script:
- echo "Testing Lab 4";
- git clone https://agile.bu.edu/gitlab/configs/ec327/lab-configs/current.git base_4
- cp lab4.cpp base_4/tests
- cd base_4/tests
- make lab4
dependencies:
- compile_lab_4
rules:
- if: '$CI_COMMIT_REF_NAME == "lab4"'
tags: [c++-17]
# trigger internal tests only upon a merge request into master
internal_tests_lab_4:
stage: tests
script:
- git clone https://trachten-gitlab:$INTERNAL_LAB_TESTS@agile.bu.edu/gitlab/ec327/ec327-staff/lab-tests.git
- cp -f lab4.cpp lab-tests/internal_tests/
- cd lab-tests/internal_tests
- make lab4
rules:
- if: '$CI_COMMIT_REF_NAME == "lab4" && $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
tags: [ c++-17 ]
### Lab 5
prebuild_lab_5:
stage: lab5
script:
- echo "LAB SUBMISSIONS ARE NOW CLOSED FOR THE SEMESTER";
- exit 1
- echo "Changes Detected (if any):";
- git diff --name-only $CI_COMMIT_SHA~ $CI_COMMIT_SHA || echo "No changes found";
- FILES_ADDED=$(git diff --name-only --diff-filter=A HEAD~1 | wc -l)
- |
# Check if lab5.cpp exists
if [ ! -f "lab5.cpp" ]; then
echo "lab5.cpp does not exist";
exit 1;
fi
# Check that only one file was checked in
if [ "FILES_ADDED" -ne 1 ]; then
echo "Error: Only one file should be committed.";
exit 1;
fi
# Check if lab4.cpp has been merged into master
# if git ls-tree -r origin/master --name-only | grep -q 'lab4.cpp'; then
# echo "Lab 4 complete";
# else
# echo "Please have lab 4 merged first";
# exit 1;
# fi
- git clone https://agile.bu.edu/gitlab/configs/ec327/lab-configs/current.git base_5
artifacts:
paths:
- base_5
rules:
- if: '$CI_COMMIT_REF_NAME == "lab5"'
tags: [c++-17]
prebuild_lab_5_SKIP:
stage: lab5
script:
- echo "SKIPPING Lab 5 checks because the branch name is not 'lab5'"
rules:
- if: '$CI_COMMIT_REF_NAME != "lab5"'
tags: [c++-17]
compile_lab_5:
stage: lab5
script:
- echo "Compiling lab5.cpp"
- g++ -c lab5.cpp
artifacts:
paths:
- base_5
dependencies:
- prebuild_lab_5
rules:
- if: '$CI_COMMIT_REF_NAME == "lab5"'
tags: [c++-17]
lint_lab_5:
stage: lab5
script:
- echo "Static code check of lab5.cpp"
- cppcheck --check-config --enable=all --inconclusive --error-exitcode=1 lab5.cpp tests/LabFive.cpp
allow_failure: false
artifacts:
paths:
- base_5
dependencies:
- prebuild_lab_5
rules:
- if: '$CI_COMMIT_REF_NAME == "lab5"'
tags: [cppcheck]
test_lab_5:
stage: lab5
script:
- echo "Testing Lab 5";
- git clone https://agile.bu.edu/gitlab/configs/ec327/lab-configs/current.git base_5
- cp lab5.cpp base_5/tests
- cd base_5/tests
- make lab5
dependencies:
- compile_lab_5
rules:
- if: '$CI_COMMIT_REF_NAME == "lab5"'
tags: [c++-17]
# trigger internal tests only upon a merge request into master
internal_tests_lab_5:
stage: tests
script:
- git clone https://trachten-gitlab:$INTERNAL_LAB_TESTS@agile.bu.edu/gitlab/ec327/ec327-staff/lab-tests.git
- cp -f lab5.cpp lab-tests/internal_tests/
- cd lab-tests/internal_tests
- make lab5
rules:
- if: '$CI_COMMIT_REF_NAME == "lab5" && $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
tags: [ c++-17 ]
......@@ -8,9 +8,16 @@ prebuild_lab_m1:
exit 1;
fi
rules:
- changes:
- lab-1.cpp
tags: [shell]
- if: '$CI_COMMIT_REF_NAME == "lab-1"'
tags: [c++-17]
prebuild_lab_m1_SKIP:
stage: labm1
script:
- echo "SKIPPING Lab -1 checks because the branch name is not 'lab-1'"
rules:
- if: '$CI_COMMIT_REF_NAME != "lab-1"'
tags: [c++-17]
compile_lab_m1:
stage: labm1
......@@ -18,8 +25,7 @@ compile_lab_m1:
- echo "Compiling lab-1.cpp"
- g++ -c lab-1.cpp
rules:
- changes:
- lab-1.cpp
- if: '$CI_COMMIT_REF_NAME == "lab-1"'
tags: [c++-17]
lint_lab_m1:
......@@ -29,15 +35,14 @@ lint_lab_m1:
- cppcheck --enable=all --inconclusive --error-exitcode=1 lab-1.cpp
allow_failure: false
rules:
- changes:
- lab-1.cpp
- if: '$CI_COMMIT_REF_NAME == "lab-1"'
tags: [cppcheck]
# don't run the test in the master branch
test_lab_m1:
stage: labm1
rules:
- if: '$CI_COMMIT_BRANCH != "master" && $CI_COMMIT_TAG == null'
- if: '$CI_COMMIT_REF_NAME == "lab-1" && $CI_COMMIT_BRANCH != "master" && $CI_COMMIT_TAG == null'
script:
- echo "Testing Lab -1";
- |
......@@ -45,7 +50,4 @@ test_lab_m1:
echo "Could not find your WikiName $GITLAB_USER_LOGIN in file lab-1.cpp";
exit 1;
fi
rules:
- changes:
- lab-1.cpp
tags: [shell]
\ No newline at end of file
//
// Created by Ari Trachtenberg on 11/1/24.
//
// Chapter 13
/**
* A graph is a collection of vertices, together with edges connecting
* some of the vertices.
*
* Implement a Graph class with the following properties:
* - There is only one public default constructor that produces an
* empty graph with no vertices (or edges).
* - operator+= is used to add a vertex with a given ID to the graph.
* if a vertex already has the given ID, a logic_error exception
* should be thrown.
* - hasEdge(int ID1, int ID2) returns true iff an edge between vertices
* with ids ID1 and ID2 exists.
* - addEdge(int ID1, int ID2) adds an edge between vertices with
* ids ID1 and ID2, respectively.
* if one of the IDs does not exist, or the edge already exists,
* an invalid_argument exception should be thrown.
* - operator[](int ii) returns the ii-th vertex in the graph (0-indexed)
* - numVertices() returns the number of vertices in the graph
* - numEdges() returns the number of edges in the graph
*
* @example
* Graph G;
* G+=3;
* G+=5;
* G+=3; // throws logic_error
* G.hasEdge(3,5); // returns false
* G.addEdge(5,3); // adds an edge connecting vertex 5 and 3.
* G.hasEdge(3,5); // returns true (edge between 5 to 3 == between 3 and 5).
* G[0]; // returns 3
* G.numVertices(); // returns 2 - vertex ID 3 and ID 5
* G.numEdges(); // returns 1 - between vertex ID 3 and ID 5
*/
class Graph;
\ No newline at end of file
//
// Created by Ari Trachtenberg on 11/1/24.
//
// Chapter 11
#include <vector>
using namespace std;
/**
* Recursively count the number of different ways of exchanging
* [dollars] dollars for the following bills: $1, $2, $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.
*
* You may use a helper function so long as you solver the problem in a recursive manner.
*
* @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) = 7 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
* 7. 2*$1 + 3*$2
*/
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 ,5, 0.5},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 | 2.125 = 0.25+ 0.25+ 0.75+ 0.875
* 3 | 2.5625 = 0.25+ 0.375+ 0.875+ 1.0625
*/
float labFour_pThree_genFib(vector<float> filter, int nn);
\ No newline at end of file
//
// Created by Ari Trachtenberg on 11/1/24.
//
#include <ctime>
#include <vector>
using namespace std;
// Chapter 10
/**
* Implement three classes:
* 0. labFour_pZero_Person represents a person with a name and a birthday.
* 1. labFour_pZero_Student derives from labFour_pZero_Person and includes
* a major.
* 2. labFour_pZero_Instructor derives from labFour_pZero_Person and has
* a salary.
* Complete the class definitions and implementations, including constructors,
* destructors, setters, getters, and an external override of stream operator<< and operator>>
* to input and output each object.
*
* When overloading the ostream operators, the output should be formatted such that it includes all fields of the object.
* @example
* labFour_pZero_Person James("James");
* Jim.setBirthday("2010-02-28");
* cout << James; // outputs "James, 2010-02-28"
*
* When overloading the instream operators, the input should be formatted such that it includes all fields of the object.
* @example
* labFour_pZero_Person James;
* std::stringstream input("James, 2010-02-28");
* input >> James; // inputs "James, 2010-02-28"
*
* @example
* labFour_pZero_Person Jim("James");
* Jim.setBirthday("2010-02-28"); // Jim's birthday is on February 28, 2010
* labFour_pZero_Student Jane("Jane","2020-03-15");
* Jane.setMajor("COMPUTER_ENGINEERING");
* labFour_pZero_Instructor Gabi("Gabriella");
* Gabi.setBirthday("2000-01-03");
* Gabi.setSalary(100000); // $100,000 per year
*/
class labFour_pZero_Person;
class labFour_pZero_Student;
class labFour_pZero_Instructor;
/**
* Implement the following classes:
* * labFour_pOne_GeometricThing - an abstract class representing a GeometricThing
* * labFour_pOne_Quadrilateral - a concrete class representing an arbitrary quadrilateral
* * labFour_pOne_Rectangle - a concrete class representing a rectangle
* * 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 circle
* 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 c1({0, 0}, 1); // area pi, perimeter 2*pi
*
* vector<labFour_pOne_GeometricThing *> things = {&q1, &re1, &s1, &rh1, &c1};
*
* labFour_pOne_GeometricThing::sumAreas(things); // returns 1+2+9+sqrt(2)/2+pi = 15.8487...
* labFour_pOne_GeometricThing::sumPerimeters(things); // returns 4+6+12+4+2*pi = 32.2832...
*
*/
class labFour_pOne_GeometricThing {
public:
/**
* Represents a two-dimensional point.
*/
class Point {
public:
Point(int Xcor, int Ycor) : x(Xcor), y(Ycor) {}
int x;
int y;
};
/**
* @param things A vector of geometric things whose areas are to be summed.
* @return The sum of the areas of all geometric things in the vector [things].
*/
static float sumAreas(vector<labFour_pOne_GeometricThing *> things);
/**
* @param things A vector of geometric things whose areas are to be summed.
* @return The sum of the areas of all geometric things in the vector [things].
*/
static float sumPerimeters(vector<labFour_pOne_GeometricThing *> things);
};
class labFour_pOne_Quadrilateral : public labFour_pOne_GeometricThing {
public:
/**
* 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.
* @param length The length of the rectangle.
* @param width The width of the rectangle.
*/
labFour_pOne_Rectangle(Point UpperLeft, int length, int width);
};
class labFour_pOne_Square : public labFour_pOne_GeometricThing {
public:
/**
* Constructs a square.
* @param UpperLeft The upper-left point of the square.
* @param length The length of a side of the square.
*/
labFour_pOne_Square(Point UpperLeft, int length);
};
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, 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.
* @param radius The radius of the circle.
*/
labFour_pOne_Circle(Point center, float radius);
};
......@@ -38,14 +38,14 @@ string labOne_pFive(string str);
* @return true if and only if [str] is a palindrome
* @see https://en.wikipedia.org/wiki/Palindrome
*
* @example 1
* @example 0
* labOne_pSix("deed") == true because "deed" is the same forward as backward.
*
* @example 2
* @example 1
* labOne_pSix("deeds") == false because "deeds" backwards is "sdeed", and the
* two strings are different.
*
* @example 3
* @example 2
* labOne_pSix("aibophpobia") == true because the string is the same forward as backward.
*
*/
......@@ -57,15 +57,15 @@ bool labOne_pSix(string str);
* @see https://en.wikipedia.org/wiki/Factorial
* @see https://en.wikipedia.org/wiki/Factorial_number_system
*
* @example 1
* @example 0
* labOne_pSeven(3) returns 11 because:
* 3 = 1*2! + 1*1!
*
* @example 2
* @example 1
* labOne_pSeven(10) returns 120 because:
* 10 = 1*3! + 2*2! + 0*1!
*
* @example 3
* @example 2
* labOne_pSeven(463) returns 34101 because:
* 463 = 3*5! + 4*4! + 1*3! + 0*2! + 1*1!
*/
......
......@@ -10,14 +10,14 @@
* @note You may use only *one* loop in your code - no
* nested loops.
*
* @example 1
* @example 0
* height: 3
* width: 4
* ****
* ****
* ****
*
* @example 2
* @example 1
* height: 1
* width: 10
* **********
......@@ -33,7 +33,7 @@ void labOne_pZero();
* @note: You must use *loops* to compute the component sums.
* @see https://en.wikipedia.org/wiki/Square_number
*
* @example 1
* @example 0
* Max: 2
* 5
*
......@@ -42,14 +42,14 @@ void labOne_pZero();
* b. The sum of all squares between 1 and 2 (inclusive) (i.e., 1)
* c. The sum of all positive powers of two less than or equal to 2 (i.e., 2)
*
* @example 2
* @example 1
* Max: 9
* 47
* 48
*
* This is because 20+14+13 = 47:
* This is because 20+14+13 = 48:
* a. 2+4+6+8 = 20
* b. 1+4+9 = 14
* c. 1+4+8 = 13
* c. 2+4+8 = 14
*/
void labOne_pOne();
......
//
// Created by Ari Trachtenberg on 10/9/24.
//
// CHAPTER 8
/**
* Reads in the contents of a file, and return the (case-insensitive)
* English-letter frequencies within the file.
* @param filename The name of the file to read.
* @return A new array (allocated on the *heap*) whose i-th entry contains
* the number of times the i-th letter of the English alphabet appears
* within the file, either as a capital or lower-case letter.
*
* @example
* If the file "example.txt" contains the following text:
* The quick brown fox jumped over the lazy dog.
*
* Then labThree_pZero("example.txt") will return a 26-integer
* array with, among others, the following values:
* - Its 0th entry will be 1 - because the letter 'a' appears just once in the file.
* - Its 3rd entry will be 2 - there are two 'd' 's in the file.
* - It's 14th entry will be 4 - there are four 'o' 's in the file
*/
int *labThree_pZero(string filename);
/**
* @param filenameCSV A file in CSV (comma-separated values) format,
* in which each table row is a line of fields, separated by commas,
* following these rules:
* - Fields may be enclosed in double quotes, or not.
* - Fields *must* be enclosed in quotes if they contain a comma or
* double-quote mark.
* - Double-quotation marks inside quoted fields are doubled.
* @return The maximum number of fields in any line of the file.
*
* @example 1
* Suppose the file "example.csv" contains the following, single line:
* 1729, San Francisco, "Hello, World", "He asked: ""Quo vadis?"""
*
* Then labThree_pOne("example.csv") should return 4, corresponding to the
* four fields:
* - 1729
* - San Francisco
* - Hello, World
* - He asked: ""Quo vadis?""
*
* @example 2
* Supples the file "example2.csv" contains the following lines:
* a,b,c
* "a", "b", "c", "d"
* 1, 2
*
* Then labThree_pOne(example2.csv") should return 4, corresponding to the
* line with the most fields ("a", "b", "c", "d").
*/
int labThree_pOne(string filenameCSV);
\ No newline at end of file
//
// Created by Ari Trachtenberg on 10/9/24.
//
// Chapter 9
#include <string>
using namespace std;
/**
* This class represents a student with the following properties:
* - It has a name (string) and quiz score(s) (int).
* - It can be constructed with a name, or with a name and a quiz score.
* - It has an appropriate destructor.
* - Quiz scores can be added, one at a time, to it with a method addQuizScore.
* - It has a method getAverageScore() that returns the average
* of all scores entered for the student.
*
* @example
* labThree_pTwo student("Jack Daniels");
* student.addQuizScore(100);
* student.addQuizScore(70);
* student.addQuizScore(70);
* Then student.getAverageScore() should return 80, the average of 100, 70, and 70.
*/
// please provide the implementation in your cpp file
class labThree_pTwo {
};
/**
* This class represents a person with the following properties:
* - It has a constructor that creates a person with a given name
* (as a string) and no friends.
* - It has member functions matching the signatures below.
*
* @example
* labThree_pThree person1 = labThree_pThree("Jim");
* labThree_pThree person2 = labThree_pThree("Jane");
* labThree_pThree person3 = labThree_pThree("Bob");
*
* person1.befriend(person2);
* person1.befriend(person3);
* person2.befriend(person1);
*
* person1.getFriendCount() - returns 2 (friends)
* person2.getFriendCount() - returns 1 (friend)
* person3.getFriendCount() - returns 0
*
* person1.getFriends() - returns "Jane, Bob"
* person2.getFriends() - returns "Jim"
*
* person1.getFriendsOfFriends() - returns "Jim"
* person2.getFriendsOfFriends() - returns "Jane, Bob"
*
*/
class labThree_pThree {
public:
labThree_pThree(char *name);
/**
* Adds thePerson as a friend of this person.
* @param thePerson person to add as a friend.
*/
void befriend(labThree_pThree thePerson);
/**
* Removes thePerson as a friend of this person. If the
* person was not a friend, then this does nothing.
* @param thePerson The person to remove.
*/
void unfriend(labThree_pThree thePerson);
/**
* @return The number of friends this person has.
*/
int getFriendCount();
/**
* @return A comma-separated list of the names of all friends
* of this person, in any order.
*/
string getFriends();
/**
*
* @return A comma separated list of the names of all friends
* of the friends of this person, in any order.
*/
string getFriendsOfFriends();
};
\ No newline at end of file
//
// Created by Ari Trachtenberg on 9/24/24.
//
// CHAPTER 7
/**
* @param arr an array of at least three double values
* @param size The size of [arr], which must be >=3
* @return A pointer to the third largest value of [arr]
*
* @example 0
* double A[] = {1,5,3,2}
* labTwo_pThree(A,4) returns a pointer to 2 (i.e., A+3) because it is
* the third largest element in the array.
*
* @example 1
* double B[] = {3,1,4,1,5,9,2,6,5,3,5,6}
* labTwo_pThree(A,12) returns a pointer to 6 (i.e., either A+7 or A+11).
*/
double* labTwo_pThree(double* arr, int size);
/**
* @param arr1 An array of characters, terminated with a null character '\0'.
* @param arr2 Another null-terminated array of characters.
* @param result An unallocated array of characters.
*
* @example 0
* char *result0;
* const char arr00[] = {'H','e','l','l','o','\0'};
* const char arr01[] = {'W','o','r','l','d','\0'};
*
* @example 1
* char *result1;
* const char arr10[] = {'B','o','s','t','o','n','\0'};
* const char arr11[] = {'U','n','i','v','e','r','s','i','t','y','\0'};
*
* This method concatenates [arr1] and [arr2] into [result]. The array
* [result] must be sufficiently allocated with "new" to contain the non-null
* contents of [arr1], [arr2], and a terminating null character.
*/
void labTwo_pFour(const char arr1[], const char arr2[], char*& result);
/**
* @param src A null-terminated array of characters, representing the source string.
* @param seek A null-terminated array of characters, representing the pattern to seek.
* @param replace A null-terminated array of characters, representing the replacement pattern.
* @return A new null-terminated array of characters that is a copy of [src], but with
* each contiguous substring [seek] replaced by [replace].
*
* @example 0
* const char *src0 = "Hatty";
* const char *seek0 = "t";
* const char *replace0 = "p";
* labTwo_pFive(src0, seek0, replace0) returns "Happy", because the "t"'s have been
* replaced by "p"'s in "Hatty".
*
* @example 1
* const char *src1 = "Hatty";
* const char *seek1 = "tt";
* const char *replace1 = "ppil";
* labTwo_pFive(src1, seek1, replace1) returns "Happily", because the
* "tt" is replaced with "pp".
*
* @example 2
* const char *src2 = "Happy";
* const char *seek2 = "p";
* const char *replace2 = "";
* labTwo_pFive(src2, seek2, replace2) returns "Hay", because the "p" are each replaced
* with the empty string "".
*/
char *labTwo_pFive(const char src[], const char seek[], const char replace[]);
\ No newline at end of file
//
// Created by Ari Trachtenberg on 9/10/24.
//
// CHAPTER 6
/**
* @param arr An array of [size] integers
* @param size The number of integers stored in array [arr]
* @return The sum of the following for [arr]:
* * Every element at even index or zero index
* * Every even element.
* * The product of the first and last element.
*
* @example 1
* int test[] = {1,2,3};
* labTwo_pZero(test,3) returns 9 as the sum of:
* * 1+3 (elements at even index)
* * 2 (even elements)
* * 3 (first*last element)
*
* @example 2
* int test2[] = {1,2,3,4};
* labTwo_pZero(test,4) returns 14 as the sum of:
* * 1+3 (elements at even index)
* * 2+4 (even elements)
* * 4 (first*last element)
*/
int labTwo_pZero(int arr[], int size);
/**
* @param arr1 An array of [size] integers
* @param arr2 An array of [size] integers
* @param size The size of arrays [arr1] and [arr2]
* @return true iff arr1 and arr2 have the same elements (in any order),
* with the same multiplicities (in the case of duplicate elements).
*
* @example 1
* int A1[] = {1,4,9,16,9,7,4,9,11}
* int A2[] = {11,1,4,9,16,9,7,4,9}
* labTwo_pOne(A1,A2,9) returns true because both arrays contain the
* elements 1, 4 (appears twice), 7, 9 (appears 3 times), 11
*
* @example 2
* int B1[] = {1,4,9,16,9,7,4,9,11}
* int B2[] = {11,11,7,9,16,4,1,4,9}
* labTwo_pOne(B1,B2,9) returns false because:
* * B1 contains only one 11, and B2 contains 2
* * B2 contains 16, which B1 does not
*/
bool labTwo_pOne(int arr1[], int arr2[], int size);
/**
* @param arr An array of the integers 1 ... size, in some order
* @param size The size of array [arr], which must also be a perfect square.
* @return true iff arr, arranged row-by-row into a sqrt(size) x sqrt(size) matrix,
* produces a magic square.
* @see https://en.wikipedia.org/wiki/Magic_square - A magice square is a matrix
* each of whose rows, columns, and both diagonals sum to the same value.
*
* @example 0
* int A[] = {1,2,3,5}
* labTwo_pTwo(A,4) returns false, because A is arranged into the following matrix:
* 1 2
* 3 5
* The sum of the first row is 3, but the sum of the second row is 8.
* Similarly, the sum of the diagonal from top-left to bottom right is 6, whereas the
* sum of the contrary diagonal is 5.
*
* @example 1
* int A[] = {2,7,6,9,5,1,4,3,8}
* labTwo_pTwo(A,9) returns true, because A is arranged into the following matrix:
* 2 7 6
* 9 5 1
* 4 3 8
* The sum of any row, column, or diagonal of the matrix equals 15.
*
* @example 2
* int B[] = {16,3,2,13,5,10,11,8,9,6,7,12,4,15,14,1}
* labTwo_pTwo(A,16) returns true, because A is arranged into the following matrix:
* 16 3 2 13
* 5 10 11 8
* 9 6 7 12
* 4 15 14 1
* The sum of any row, column, or diagonal of the matrix equals 34.
*/
bool labTwo_pTwo(int arr[], int size);
\ No newline at end of file
......@@ -17,23 +17,23 @@
void labZero_pThree();
/**
* @input read in four pairs of integral x y coordinates, one per line.
* @input read in four pairs of integral x y coordinates, one per line, in clock-wise order
* @output outputs the most specific description of the
* four points among the following choices:
* square, rectangle, trapezoid, rhombus, none of these
*
* @example 1
* @example 0
* 0 0
* 0 1
* 1 0
* 1 1
* 1 0
* square
*
* @example 2
* @example 1
* 0 0
* 0 1
* 2 0
* 1 1
* 2 0
* trapezoid
*/
void labZero_pFour();
......
......@@ -24,12 +24,12 @@ void labZero_pZero();
* times, in the format "[h] hours [m] minutes" for appropriate
* values [h] and [m].
*
* @example 1
* @example 0
* Please enter the first time: 0900
* Please enter the second time: 1730
* 8 hours 30 minutes
*
* @example 2
* @example 1
* Please enter the first time: 1730
* Please enter the second time: 0900
* 15 hours 30 minutes
......