├── labs ├── arrays │ ├── numbers │ │ ├── utils.h │ │ ├── src │ │ │ └── utils.h │ │ └── Makefile │ └── modulo │ │ ├── data │ │ ├── 1.ans │ │ ├── 2.ans │ │ ├── 3.ans │ │ ├── 1.in │ │ ├── 3.in │ │ └── 2.in │ │ ├── src │ │ ├── modulo.h │ │ ├── modulo.cpp │ │ └── main.cpp │ │ └── Makefile ├── pointers │ ├── timeloop │ │ ├── main.cpp │ │ ├── data │ │ │ ├── a.in │ │ │ ├── b.in │ │ │ ├── a.ans │ │ │ └── b.ans │ │ ├── timeloop.yaml │ │ ├── src │ │ │ ├── timeloop.h │ │ │ ├── timeloop.cpp │ │ │ └── main.cpp │ │ └── Makefile │ └── pointers │ │ ├── Makefile │ │ └── src │ │ └── utils.h ├── conditionals │ ├── twostones │ │ ├── data │ │ │ ├── 2.in │ │ │ ├── 1.in │ │ │ ├── 3.in │ │ │ ├── 1.ans │ │ │ ├── 2.ans │ │ │ └── 3.ans │ │ ├── src │ │ │ ├── twostones.h │ │ │ ├── twostones.cpp │ │ │ └── main.cpp │ │ ├── Makefile │ │ └── tests │ │ │ └── test_twostones.cpp │ └── menu │ │ ├── Makefile │ │ └── src │ │ ├── main.cpp │ │ └── utils.h ├── math │ ├── dfyrirdreki │ │ ├── data │ │ │ ├── 1.ans │ │ │ ├── 2.ans │ │ │ ├── 3.ans │ │ │ ├── 1.in │ │ │ ├── 2.in │ │ │ └── 3.in │ │ ├── src │ │ │ ├── roots.h │ │ │ ├── roots.cpp │ │ │ └── main.cpp │ │ ├── dfyrirdreki.yaml │ │ ├── Makefile │ │ └── tests │ │ │ └── test_roots.cpp │ ├── addtwonumbers │ │ ├── data │ │ │ ├── 1.ans │ │ │ ├── 1.in │ │ │ ├── 2.ans │ │ │ └── 2.in │ │ ├── src │ │ │ ├── addtwo.h │ │ │ ├── addtwo.cpp │ │ │ └── main.cpp │ │ ├── addtwonumbers.yaml │ │ ├── tests │ │ │ └── test_addtwo.cpp │ │ └── Makefile │ └── circle │ │ └── Makefile ├── loops │ ├── nostragglers │ │ ├── data │ │ │ ├── 1.ans │ │ │ ├── 2.ans │ │ │ ├── 1.in │ │ │ └── 2.in │ │ ├── nostragglers.yaml │ │ ├── src │ │ │ ├── utils.h │ │ │ └── nostragglers.cpp │ │ └── Makefile │ ├── doggopher │ │ ├── data │ │ │ ├── 1.ans │ │ │ ├── 1.in │ │ │ ├── 2.ans │ │ │ └── 2.in │ │ ├── doggopher.yaml │ │ ├── src │ │ │ ├── doggopher.h │ │ │ └── doggopher.cpp │ │ ├── tests │ │ │ └── test_doggopher.cpp │ │ └── Makefile │ └── shapes │ │ ├── src │ │ └── shapes.h │ │ ├── tests │ │ └── test_shapes.cpp │ │ └── Makefile ├── maps │ ├── sevenwonders │ │ ├── data │ │ │ ├── 1.ans │ │ │ ├── 1.in │ │ │ ├── 2.ans │ │ │ ├── 2.in │ │ │ ├── 3.ans │ │ │ └── 3.in │ │ ├── sevenwonders.yaml │ │ ├── src │ │ │ ├── sevenwonders.h │ │ │ └── main.cpp │ │ └── Makefile │ ├── morsecodepalindromes │ │ ├── data │ │ │ ├── 0.ans │ │ │ ├── 1.ans │ │ │ ├── 1.in │ │ │ ├── 2.ans │ │ │ ├── 3.ans │ │ │ ├── 4.ans │ │ │ ├── 4.in │ │ │ ├── 5.ans │ │ │ ├── 5.in │ │ │ ├── 6.ans │ │ │ ├── 0.in │ │ │ ├── 6.in │ │ │ ├── m0000.ans │ │ │ ├── m0001.ans │ │ │ ├── m0001.in │ │ │ ├── m0002.ans │ │ │ ├── m0003.ans │ │ │ ├── m0004.ans │ │ │ ├── m0004.in │ │ │ ├── m0005.ans │ │ │ ├── m0005.in │ │ │ ├── 3.in │ │ │ ├── m0000.in │ │ │ ├── m0003.in │ │ │ ├── 2.in │ │ │ └── m0002.in │ │ ├── morsecodepalindromes.yaml │ │ ├── Makefile │ │ ├── src │ │ │ ├── morsecode.h │ │ │ └── main.cpp │ │ └── tests │ │ │ └── test_morsecode.cpp │ └── baconeggsandspam │ │ ├── data │ │ ├── 1.in │ │ ├── sample.in │ │ ├── 1.ans │ │ └── sample.ans │ │ ├── baconeggsandspam.yaml │ │ ├── src │ │ ├── bacon.h │ │ └── main.cpp │ │ └── Makefile ├── unittest │ ├── mclimbroad │ │ ├── data │ │ │ ├── 1.ans │ │ │ ├── 2.ans │ │ │ ├── 1.in │ │ │ └── 2.in │ │ ├── mclimbroad.yaml │ │ ├── src │ │ │ ├── util.h │ │ │ ├── mclimbroad.cpp │ │ │ └── main.cpp │ │ └── Makefile │ ├── triarea │ │ ├── data │ │ │ ├── sample1.ans │ │ │ ├── sample1.in │ │ │ ├── sample2.ans │ │ │ └── sample2.in │ │ ├── triarea.yaml │ │ ├── src │ │ │ ├── triarea.h │ │ │ ├── triarea.cpp │ │ │ └── main.cpp │ │ ├── Makefile │ │ └── tests │ │ │ └── test_triarea.cpp │ └── points │ │ └── Makefile ├── functions │ ├── thelastproblem │ │ ├── data │ │ │ ├── 1.in │ │ │ ├── 2.in │ │ │ ├── 2.ans │ │ │ └── 1.ans │ │ ├── thelastproblem.yaml │ │ ├── src │ │ │ ├── helper.cpp │ │ │ ├── helper.h │ │ │ └── thelastproblem.cpp │ │ ├── tests │ │ │ └── test_helper.cpp │ │ └── Makefile │ └── library │ │ ├── src │ │ ├── my_math.h │ │ └── my_math.cpp │ │ ├── tests │ │ └── test_my_math.cpp │ │ └── Makefile ├── strings │ ├── simonsays │ │ ├── sample_tests │ │ │ ├── 1.ans │ │ │ ├── 1.in │ │ │ ├── 3.ans │ │ │ ├── 2.ans │ │ │ ├── 3.in │ │ │ └── 2.in │ │ └── Makefile │ ├── hissingmicrophone │ │ ├── sample_tests │ │ │ ├── 1.ans │ │ │ ├── 1.in │ │ │ ├── 3.ans │ │ │ ├── 3.in │ │ │ ├── 2.ans │ │ │ └── 2.in │ │ ├── Makefile │ │ └── main.cpp │ └── palindrome │ │ └── Makefile ├── vectors │ ├── foxsays │ │ ├── 1.ans │ │ ├── 1.in │ │ └── Makefile │ └── numSystem │ │ └── Makefile ├── namespaces │ ├── grafaholur │ │ ├── data │ │ │ ├── 1.ans │ │ │ ├── 2.ans │ │ │ ├── 1.in │ │ │ └── 2.in │ │ ├── grafaholur.yaml │ │ ├── src │ │ │ ├── dig.h │ │ │ ├── dig.cpp │ │ │ └── main.cpp │ │ ├── tests │ │ │ └── test_dig.cpp │ │ └── Makefile │ └── namespace │ │ ├── Makefile │ │ └── src │ │ └── utils.h ├── fileio │ ├── data │ │ ├── integers.txt │ │ └── output.txt │ ├── src │ │ ├── fileio.h │ │ └── main.cpp │ └── Makefile ├── stdio │ ├── ascii │ │ ├── util.h │ │ ├── util.cpp │ │ └── Makefile │ └── ascii1 │ │ └── Makefile └── variables │ └── ascii │ ├── Makefile │ └── main.cpp ├── notebooks ├── demos │ ├── stdio │ │ ├── carrots │ │ │ ├── 1.ans │ │ │ ├── 2.ans │ │ │ ├── 3.ans │ │ │ ├── 2.in │ │ │ ├── 1.in │ │ │ ├── 3.in │ │ │ ├── carrots.cpp │ │ │ └── Makefile │ │ ├── demo1 │ │ │ ├── Makefile │ │ │ └── main.cpp │ │ ├── decToBin │ │ │ └── Makefile │ │ └── rectangle │ │ │ ├── Makefile │ │ │ └── main.cpp │ ├── file_io │ │ ├── outputfile1.txt │ │ ├── outputfile.txt │ │ ├── studentgrades.txt │ │ ├── triangle │ │ │ ├── triangles_db.txt │ │ │ ├── triangles_results.txt │ │ │ └── Makefile │ │ ├── inputfile.txt │ │ ├── formatted_output.txt │ │ └── studentgradereport.txt │ ├── structs │ │ └── triangle │ │ │ ├── triangles_db.txt │ │ │ └── Makefile │ ├── vectors │ │ ├── triangle │ │ │ ├── triangles_db.txt │ │ │ ├── output.txt │ │ │ ├── triangles_report.txt │ │ │ └── Makefile │ │ └── splitString │ │ │ └── Makefile │ ├── header_files │ │ ├── triangle │ │ │ ├── triangles_db.txt │ │ │ ├── utility.h │ │ │ ├── test.h │ │ │ ├── Makefile │ │ │ ├── utility.cpp │ │ │ ├── triangle.h │ │ │ └── test.cpp │ │ └── header │ │ │ ├── utility.h │ │ │ ├── utility.cpp │ │ │ ├── main.cpp │ │ │ └── Makefile │ ├── unittest │ │ ├── assert1 │ │ │ ├── Makefile │ │ │ └── unittesting.cpp │ │ ├── assert2 │ │ │ ├── Makefile │ │ │ └── unittesting2.cpp │ │ ├── assert3 │ │ │ └── Makefile │ │ ├── assert │ │ │ ├── Makefile │ │ │ └── assertdebug.cpp │ │ └── doctest │ │ │ ├── Makefile │ │ │ └── src │ │ │ ├── fruitful.h │ │ │ └── fruitful.cpp │ ├── functions │ │ ├── rectangle │ │ │ └── Makefile │ │ ├── func_prototype │ │ │ ├── Makefile │ │ │ └── func_prototype.cpp │ │ └── helloworld │ │ │ └── helloworld.cpp │ ├── intro │ │ ├── Makefile │ │ └── helloworld.cpp │ ├── makefiles │ │ ├── demo1 │ │ │ ├── Makefile │ │ │ └── hello.cpp │ │ ├── demo2 │ │ │ ├── Makefile │ │ │ └── hello.cpp │ │ ├── demo4 │ │ │ ├── Makefile │ │ │ └── hello.cpp │ │ ├── demo3 │ │ │ ├── Makefile │ │ │ └── hello.cpp │ │ ├── demo5 │ │ │ ├── hello.cpp │ │ │ └── Makefile │ │ └── Makefile_template │ ├── classes │ │ └── points │ │ │ ├── Makefile │ │ │ ├── src │ │ │ ├── main.cpp │ │ │ ├── point.hpp │ │ │ └── point.cpp │ │ │ └── tests │ │ │ └── test_point.cpp │ ├── variables │ │ └── exercise1.cpp │ ├── library │ │ └── printf │ │ │ ├── printf_demo.cpp │ │ │ └── Makefile │ ├── arrays │ │ ├── buffer_overflow1 │ │ │ ├── Makefile │ │ │ └── buffer_overflow1.cpp │ │ ├── overflow_fixed │ │ │ └── Makefile │ │ └── buffer_overflow2 │ │ │ ├── Makefile │ │ │ └── buffer_overflow2.cpp │ ├── loops │ │ ├── rectangle │ │ │ └── Makefile │ │ ├── countdown │ │ │ └── Makefile │ │ └── input_validate │ │ │ ├── Makefile │ │ │ └── input_validation.cpp │ ├── pointers │ │ └── rectangle │ │ │ └── Makefile │ ├── conditionals │ │ ├── rectangle │ │ │ └── Makefile │ │ ├── menu │ │ │ └── Makefile │ │ ├── main_arg1 │ │ │ ├── Makefile │ │ │ └── main_arg1.cpp │ │ └── main_arg2 │ │ │ └── Makefile │ └── maps │ │ └── letter_frequency │ │ └── Makefile ├── data │ ├── studentgrades.txt │ └── studentgradereport.txt ├── assets │ ├── Map.png │ ├── array.png │ ├── record.png │ ├── records.png │ ├── switch.png │ ├── Compiler.png │ ├── For-Loop.png │ ├── Intrepreter.png │ ├── While-Loop.png │ ├── chess-board.jpg │ ├── ifstatement.png │ ├── launchbinder.png │ ├── russiandolls.png │ ├── string_rep.png │ ├── tic-tac-toe.png │ ├── BuildingBlocks.png │ ├── CPPDevelopment.png │ ├── Do-While-Loop.png │ ├── MemorySegments.png │ ├── memory-layout.png │ ├── ifelsestatement.png │ ├── multi-wayselector.png │ ├── pointers-in-cpp.jpg │ ├── range-begin-end.png │ ├── range-rbegin-rend.png │ ├── VariablesAndMemory.png │ ├── Cartesian-coordinates.png │ └── scopesandnameresolution.png └── codespaces+zany-pancake-57rgjjwrxgfr5r:.inetloc ├── .env ├── requirements.txt ├── pdfs ├── Maps.pdf ├── Arrays.pdf ├── FileIO.pdf ├── Kattis.pdf ├── Loops.pdf ├── Unions.pdf ├── Pointers.pdf ├── Strings.pdf ├── Vectors.pdf ├── HeaderFiles.pdf ├── Structures.pdf ├── Conditionals.pdf ├── Introduction.pdf ├── StdInputOutput.pdf ├── 00-TableOfContents.pdf ├── DevEnvironmentSetup.pdf ├── LibraryAndFunction.pdf ├── JupyterNotebookSetup.pdf ├── UserDefinedFunctions.pdf ├── Namespaces-Enumerations.pdf └── DataVariablesAndOperations.pdf ├── run-docker.sh ├── latex └── resources │ ├── Map.png │ ├── array.png │ ├── Compiler.png │ ├── For-Loop.png │ ├── record.png │ ├── records.png │ ├── switch.png │ ├── While-Loop.png │ ├── string_rep.png │ ├── Do-While-Loop.png │ ├── Intrepreter.png │ ├── chess-board.jpg │ ├── ifstatement.png │ ├── launchbinder.png │ ├── memory-layout.png │ ├── tic-tac-toe.png │ ├── BuildingBlocks.png │ ├── CPPDevelopment.png │ ├── ifelsestatement.png │ ├── pointers-in-cpp.jpg │ ├── range-begin-end.png │ ├── VariablesAndMemory.png │ ├── multi-wayselector.png │ ├── range-rbegin-rend.png │ ├── Cartesian-coordinates.png │ └── scopesandnameresolution.png ├── oryx-build-commands.txt ├── exercises ├── stdio │ ├── hangman │ │ └── Hangman-README.pdf │ └── BMI │ │ └── Makefile ├── intro │ └── helloworld │ │ ├── main.cpp │ │ └── Makefile ├── variables │ └── exercise1 │ │ ├── main.cpp │ │ └── Makefile ├── library │ └── rectangle │ │ └── Makefile ├── loops │ └── BMI │ │ └── Makefile ├── conditionals │ ├── BMI │ │ └── Makefile │ ├── vote1 │ │ └── Makefile │ └── vote2 │ │ └── Makefile ├── functions │ └── BMI │ │ └── Makefile └── header_files │ └── exercise1 │ └── Makefile ├── create_environment.sh ├── environment.yml ├── .gitignore ├── docker-compose.yml └── LICENSE /labs/arrays/numbers/utils.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /labs/pointers/timeloop/main.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /labs/arrays/modulo/data/1.ans: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /labs/arrays/modulo/data/2.ans: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /labs/arrays/modulo/data/3.ans: -------------------------------------------------------------------------------- 1 | 6 2 | -------------------------------------------------------------------------------- /labs/conditionals/twostones/data/2.in: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /labs/math/dfyrirdreki/data/1.ans: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /labs/math/dfyrirdreki/data/2.ans: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /labs/math/dfyrirdreki/data/3.ans: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /labs/pointers/timeloop/data/a.in: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /labs/conditionals/twostones/data/1.in: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /labs/conditionals/twostones/data/3.in: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /labs/loops/nostragglers/data/1.ans: -------------------------------------------------------------------------------- 1 | 44 2 | -------------------------------------------------------------------------------- /labs/maps/sevenwonders/data/1.ans: -------------------------------------------------------------------------------- 1 | 21 2 | -------------------------------------------------------------------------------- /labs/maps/sevenwonders/data/1.in: -------------------------------------------------------------------------------- 1 | TCGTTC 2 | -------------------------------------------------------------------------------- /labs/maps/sevenwonders/data/2.ans: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /labs/maps/sevenwonders/data/2.in: -------------------------------------------------------------------------------- 1 | CCC 2 | -------------------------------------------------------------------------------- /labs/maps/sevenwonders/data/3.ans: -------------------------------------------------------------------------------- 1 | 26 2 | -------------------------------------------------------------------------------- /labs/maps/sevenwonders/data/3.in: -------------------------------------------------------------------------------- 1 | TTCCGG 2 | -------------------------------------------------------------------------------- /labs/math/addtwonumbers/data/1.ans: -------------------------------------------------------------------------------- 1 | 7 2 | -------------------------------------------------------------------------------- /labs/math/addtwonumbers/data/1.in: -------------------------------------------------------------------------------- 1 | 3 4 2 | -------------------------------------------------------------------------------- /labs/math/addtwonumbers/data/2.ans: -------------------------------------------------------------------------------- 1 | 1010 2 | -------------------------------------------------------------------------------- /labs/pointers/timeloop/data/b.in: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /labs/unittest/mclimbroad/data/1.ans: -------------------------------------------------------------------------------- 1 | 316 2 | -------------------------------------------------------------------------------- /labs/unittest/mclimbroad/data/2.ans: -------------------------------------------------------------------------------- 1 | 21 2 | -------------------------------------------------------------------------------- /notebooks/demos/stdio/carrots/1.ans: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /notebooks/demos/stdio/carrots/2.ans: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /notebooks/demos/stdio/carrots/3.ans: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /labs/conditionals/twostones/data/1.ans: -------------------------------------------------------------------------------- 1 | Alice 2 | -------------------------------------------------------------------------------- /labs/conditionals/twostones/data/2.ans: -------------------------------------------------------------------------------- 1 | Bob 2 | -------------------------------------------------------------------------------- /labs/conditionals/twostones/data/3.ans: -------------------------------------------------------------------------------- 1 | Alice 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/0.ans: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/1.ans: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/1.in: -------------------------------------------------------------------------------- 1 | 159 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/2.ans: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/3.ans: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/4.ans: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/4.in: -------------------------------------------------------------------------------- 1 | SOS 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/5.ans: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/5.in: -------------------------------------------------------------------------------- 1 | A E 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/6.ans: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /labs/math/addtwonumbers/data/2.in: -------------------------------------------------------------------------------- 1 | 987 23 2 | -------------------------------------------------------------------------------- /labs/unittest/mclimbroad/data/1.in: -------------------------------------------------------------------------------- 1 | 3 2 | 50 3 | -------------------------------------------------------------------------------- /labs/unittest/mclimbroad/data/2.in: -------------------------------------------------------------------------------- 1 | 2 2 | 500 3 | -------------------------------------------------------------------------------- /labs/unittest/triarea/data/sample1.ans: -------------------------------------------------------------------------------- 1 | 0.5 2 | -------------------------------------------------------------------------------- /labs/unittest/triarea/data/sample1.in: -------------------------------------------------------------------------------- 1 | 1 1 2 | -------------------------------------------------------------------------------- /labs/unittest/triarea/data/sample2.ans: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /labs/unittest/triarea/data/sample2.in: -------------------------------------------------------------------------------- 1 | 2 2 2 | -------------------------------------------------------------------------------- /labs/functions/thelastproblem/data/1.in: -------------------------------------------------------------------------------- 1 | Twilight 2 | -------------------------------------------------------------------------------- /labs/functions/thelastproblem/data/2.in: -------------------------------------------------------------------------------- 1 | Luster 2 | -------------------------------------------------------------------------------- /labs/loops/nostragglers/data/2.ans: -------------------------------------------------------------------------------- 1 | NO STRAGGLERS 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/0.in: -------------------------------------------------------------------------------- 1 | hello 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/6.in: -------------------------------------------------------------------------------- 1 | % ! & 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/m0000.ans: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/m0001.ans: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/m0001.in: -------------------------------------------------------------------------------- 1 | 159 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/m0002.ans: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/m0003.ans: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/m0004.ans: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/m0004.in: -------------------------------------------------------------------------------- 1 | SOS 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/m0005.ans: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/m0005.in: -------------------------------------------------------------------------------- 1 | A E 2 | -------------------------------------------------------------------------------- /labs/math/dfyrirdreki/data/1.in: -------------------------------------------------------------------------------- 1 | -5 2 | 1 3 | 1 4 | -------------------------------------------------------------------------------- /labs/math/dfyrirdreki/data/2.in: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | 1 4 | -------------------------------------------------------------------------------- /labs/math/dfyrirdreki/data/3.in: -------------------------------------------------------------------------------- 1 | 2 2 | 4 3 | 2 4 | -------------------------------------------------------------------------------- /labs/strings/simonsays/sample_tests/1.ans: -------------------------------------------------------------------------------- 1 | smile. 2 | -------------------------------------------------------------------------------- /labs/vectors/foxsays/1.ans: -------------------------------------------------------------------------------- 1 | wa pa pa pa pa pa pow 2 | -------------------------------------------------------------------------------- /notebooks/demos/file_io/outputfile1.txt: -------------------------------------------------------------------------------- 1 | 2 + 2 = 4 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/3.in: -------------------------------------------------------------------------------- 1 | footstool 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/m0000.in: -------------------------------------------------------------------------------- 1 | hello 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/m0003.in: -------------------------------------------------------------------------------- 1 | footstool 2 | -------------------------------------------------------------------------------- /labs/strings/hissingmicrophone/sample_tests/1.ans: -------------------------------------------------------------------------------- 1 | hiss 2 | -------------------------------------------------------------------------------- /labs/strings/hissingmicrophone/sample_tests/1.in: -------------------------------------------------------------------------------- 1 | amiss 2 | -------------------------------------------------------------------------------- /labs/strings/hissingmicrophone/sample_tests/3.ans: -------------------------------------------------------------------------------- 1 | hiss 2 | -------------------------------------------------------------------------------- /labs/strings/hissingmicrophone/sample_tests/3.in: -------------------------------------------------------------------------------- 1 | hiss 2 | -------------------------------------------------------------------------------- /notebooks/demos/file_io/outputfile.txt: -------------------------------------------------------------------------------- 1 | Hello World! 2 | -------------------------------------------------------------------------------- /labs/loops/doggopher/data/1.ans: -------------------------------------------------------------------------------- 1 | The gopher cannot escape. 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/2.in: -------------------------------------------------------------------------------- 1 | Madam I'm Adam 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/data/m0002.in: -------------------------------------------------------------------------------- 1 | Madam I'm Adam 2 | -------------------------------------------------------------------------------- /labs/namespaces/grafaholur/data/1.ans: -------------------------------------------------------------------------------- 1 | 2.000000000000000 2 | -------------------------------------------------------------------------------- /labs/namespaces/grafaholur/data/2.ans: -------------------------------------------------------------------------------- 1 | 0.833333333333333 2 | -------------------------------------------------------------------------------- /labs/strings/hissingmicrophone/sample_tests/2.ans: -------------------------------------------------------------------------------- 1 | no hiss 2 | -------------------------------------------------------------------------------- /labs/strings/hissingmicrophone/sample_tests/2.in: -------------------------------------------------------------------------------- 1 | octopuses 2 | -------------------------------------------------------------------------------- /notebooks/demos/stdio/carrots/2.in: -------------------------------------------------------------------------------- 1 | 1 5 2 | sovl problmz 3 | -------------------------------------------------------------------------------- /.env: -------------------------------------------------------------------------------- 1 | CONTAINER_NAME=cs1 2 | IMAGE_NAME=cs1 3 | REPO_NAME=cs1 4 | -------------------------------------------------------------------------------- /labs/namespaces/grafaholur/data/1.in: -------------------------------------------------------------------------------- 1 | 4 2 | 4 3 | 4 4 | 2 5 | 1 6 | -------------------------------------------------------------------------------- /labs/namespaces/grafaholur/data/2.in: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | -------------------------------------------------------------------------------- /labs/strings/simonsays/sample_tests/1.in: -------------------------------------------------------------------------------- 1 | 1 2 | Simon says smile. 3 | -------------------------------------------------------------------------------- /labs/strings/simonsays/sample_tests/3.ans: -------------------------------------------------------------------------------- 1 | raise your left hand. 2 | -------------------------------------------------------------------------------- /notebooks/demos/stdio/carrots/1.in: -------------------------------------------------------------------------------- 1 | 2 1 2 | carrots? 3 | bunnies 4 | -------------------------------------------------------------------------------- /notebooks/demos/stdio/carrots/3.in: -------------------------------------------------------------------------------- 1 | 1000 10 2 | team1 3 | team2 4 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pytest 2 | jupyter 3 | requests 4 | kattis-cli 5 | -------------------------------------------------------------------------------- /labs/fileio/data/integers.txt: -------------------------------------------------------------------------------- 1 | 100 2 | 10 3 | 5 4 | 0 5 | -99 6 | 10 7 | 99 8 | -------------------------------------------------------------------------------- /labs/functions/thelastproblem/data/2.ans: -------------------------------------------------------------------------------- 1 | Thank you, Luster, and farewell! 2 | -------------------------------------------------------------------------------- /labs/loops/doggopher/data/1.in: -------------------------------------------------------------------------------- 1 | 1.000 1.000 2.000 2.000 2 | 1.500 1.500 3 | -------------------------------------------------------------------------------- /labs/functions/thelastproblem/data/1.ans: -------------------------------------------------------------------------------- 1 | Thank you, Twilight, and farewell! 2 | -------------------------------------------------------------------------------- /labs/loops/nostragglers/data/1.in: -------------------------------------------------------------------------------- 1 | 3 2 | STU IN 10 3 | VIS IN 38 4 | STU OUT 4 5 | -------------------------------------------------------------------------------- /pdfs/Maps.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/pdfs/Maps.pdf -------------------------------------------------------------------------------- /run-docker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | docker compose up -d 4 | docker exec -it cs1 zsh 5 | -------------------------------------------------------------------------------- /labs/loops/doggopher/data/2.ans: -------------------------------------------------------------------------------- 1 | The gopher can escape through the hole at (2.500,2.500). 2 | -------------------------------------------------------------------------------- /labs/loops/doggopher/data/2.in: -------------------------------------------------------------------------------- 1 | 2.000 2.000 1.000 1.000 2 | 1.500 1.500 3 | 2.500 2.500 4 | -------------------------------------------------------------------------------- /pdfs/Arrays.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/pdfs/Arrays.pdf -------------------------------------------------------------------------------- /pdfs/FileIO.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/pdfs/FileIO.pdf -------------------------------------------------------------------------------- /pdfs/Kattis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/pdfs/Kattis.pdf -------------------------------------------------------------------------------- /pdfs/Loops.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/pdfs/Loops.pdf -------------------------------------------------------------------------------- /pdfs/Unions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/pdfs/Unions.pdf -------------------------------------------------------------------------------- /labs/math/addtwonumbers/src/addtwo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | long add_two_numbers(int, int); 4 | -------------------------------------------------------------------------------- /labs/strings/simonsays/sample_tests/2.ans: -------------------------------------------------------------------------------- 1 | raise your right hand. 2 | raise your left hand. 3 | -------------------------------------------------------------------------------- /pdfs/Pointers.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/pdfs/Pointers.pdf -------------------------------------------------------------------------------- /pdfs/Strings.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/pdfs/Strings.pdf -------------------------------------------------------------------------------- /pdfs/Vectors.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/pdfs/Vectors.pdf -------------------------------------------------------------------------------- /labs/arrays/modulo/data/1.in: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | -------------------------------------------------------------------------------- /pdfs/HeaderFiles.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/pdfs/HeaderFiles.pdf -------------------------------------------------------------------------------- /pdfs/Structures.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/pdfs/Structures.pdf -------------------------------------------------------------------------------- /latex/resources/Map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/Map.png -------------------------------------------------------------------------------- /notebooks/data/studentgrades.txt: -------------------------------------------------------------------------------- 1 | John Smith 100 95 85 2 | Jane Doe 85 89 99 3 | Jill Jones 56 89 99 100 4 | -------------------------------------------------------------------------------- /pdfs/Conditionals.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/pdfs/Conditionals.pdf -------------------------------------------------------------------------------- /pdfs/Introduction.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/pdfs/Introduction.pdf -------------------------------------------------------------------------------- /pdfs/StdInputOutput.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/pdfs/StdInputOutput.pdf -------------------------------------------------------------------------------- /labs/arrays/modulo/data/3.in: -------------------------------------------------------------------------------- 1 | 39 2 | 40 3 | 41 4 | 42 5 | 43 6 | 44 7 | 82 8 | 83 9 | 84 10 | 85 11 | -------------------------------------------------------------------------------- /labs/loops/nostragglers/data/2.in: -------------------------------------------------------------------------------- 1 | 5 2 | STU IN 10 3 | VIS IN 38 4 | STU OUT 4 5 | VIS OUT 38 6 | STU OUT 6 7 | -------------------------------------------------------------------------------- /latex/resources/array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/array.png -------------------------------------------------------------------------------- /notebooks/assets/Map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/Map.png -------------------------------------------------------------------------------- /labs/arrays/modulo/data/2.in: -------------------------------------------------------------------------------- 1 | 42 2 | 84 3 | 252 4 | 420 5 | 840 6 | 126 7 | 42 8 | 84 9 | 420 10 | 126 11 | -------------------------------------------------------------------------------- /latex/resources/Compiler.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/Compiler.png -------------------------------------------------------------------------------- /latex/resources/For-Loop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/For-Loop.png -------------------------------------------------------------------------------- /latex/resources/record.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/record.png -------------------------------------------------------------------------------- /latex/resources/records.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/records.png -------------------------------------------------------------------------------- /latex/resources/switch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/switch.png -------------------------------------------------------------------------------- /notebooks/assets/array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/array.png -------------------------------------------------------------------------------- /notebooks/assets/record.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/record.png -------------------------------------------------------------------------------- /notebooks/assets/records.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/records.png -------------------------------------------------------------------------------- /notebooks/assets/switch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/switch.png -------------------------------------------------------------------------------- /notebooks/demos/file_io/studentgrades.txt: -------------------------------------------------------------------------------- 1 | John Smith 100 95 85 2 | Jane Doe 85 89 99 3 | Jill Jones 56 89 99 100 4 | -------------------------------------------------------------------------------- /notebooks/demos/file_io/triangle/triangles_db.txt: -------------------------------------------------------------------------------- 1 | Triangle's side1, side2, side3 2 | 7 9 11 3 | 3 4 5 4 | 4 5 6 5 | -------------------------------------------------------------------------------- /notebooks/demos/structs/triangle/triangles_db.txt: -------------------------------------------------------------------------------- 1 | Triangle's side1, side2, side3 2 | 7 9 11 3 | 3 4 5 4 | 4 5 6 5 | -------------------------------------------------------------------------------- /pdfs/00-TableOfContents.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/pdfs/00-TableOfContents.pdf -------------------------------------------------------------------------------- /pdfs/DevEnvironmentSetup.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/pdfs/DevEnvironmentSetup.pdf -------------------------------------------------------------------------------- /pdfs/LibraryAndFunction.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/pdfs/LibraryAndFunction.pdf -------------------------------------------------------------------------------- /labs/pointers/timeloop/data/a.ans: -------------------------------------------------------------------------------- 1 | 1 Abracadabra 2 | 2 Abracadabra 3 | 3 Abracadabra 4 | 4 Abracadabra 5 | 5 Abracadabra 6 | -------------------------------------------------------------------------------- /latex/resources/While-Loop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/While-Loop.png -------------------------------------------------------------------------------- /latex/resources/string_rep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/string_rep.png -------------------------------------------------------------------------------- /notebooks/assets/Compiler.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/Compiler.png -------------------------------------------------------------------------------- /notebooks/assets/For-Loop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/For-Loop.png -------------------------------------------------------------------------------- /pdfs/JupyterNotebookSetup.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/pdfs/JupyterNotebookSetup.pdf -------------------------------------------------------------------------------- /pdfs/UserDefinedFunctions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/pdfs/UserDefinedFunctions.pdf -------------------------------------------------------------------------------- /latex/resources/Do-While-Loop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/Do-While-Loop.png -------------------------------------------------------------------------------- /latex/resources/Intrepreter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/Intrepreter.png -------------------------------------------------------------------------------- /latex/resources/chess-board.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/chess-board.jpg -------------------------------------------------------------------------------- /latex/resources/ifstatement.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/ifstatement.png -------------------------------------------------------------------------------- /latex/resources/launchbinder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/launchbinder.png -------------------------------------------------------------------------------- /latex/resources/memory-layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/memory-layout.png -------------------------------------------------------------------------------- /latex/resources/tic-tac-toe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/tic-tac-toe.png -------------------------------------------------------------------------------- /notebooks/assets/Intrepreter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/Intrepreter.png -------------------------------------------------------------------------------- /notebooks/assets/While-Loop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/While-Loop.png -------------------------------------------------------------------------------- /notebooks/assets/chess-board.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/chess-board.jpg -------------------------------------------------------------------------------- /notebooks/assets/ifstatement.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/ifstatement.png -------------------------------------------------------------------------------- /notebooks/assets/launchbinder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/launchbinder.png -------------------------------------------------------------------------------- /notebooks/assets/russiandolls.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/russiandolls.png -------------------------------------------------------------------------------- /notebooks/assets/string_rep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/string_rep.png -------------------------------------------------------------------------------- /notebooks/assets/tic-tac-toe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/tic-tac-toe.png -------------------------------------------------------------------------------- /notebooks/demos/vectors/triangle/triangles_db.txt: -------------------------------------------------------------------------------- 1 | Triangle's side1, side2, side3 2 | 7 9 11 3 | 3 4 5 4 | 4 5 6 5 | 1 2 3 6 | -------------------------------------------------------------------------------- /pdfs/Namespaces-Enumerations.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/pdfs/Namespaces-Enumerations.pdf -------------------------------------------------------------------------------- /latex/resources/BuildingBlocks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/BuildingBlocks.png -------------------------------------------------------------------------------- /latex/resources/CPPDevelopment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/CPPDevelopment.png -------------------------------------------------------------------------------- /latex/resources/ifelsestatement.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/ifelsestatement.png -------------------------------------------------------------------------------- /latex/resources/pointers-in-cpp.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/pointers-in-cpp.jpg -------------------------------------------------------------------------------- /latex/resources/range-begin-end.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/range-begin-end.png -------------------------------------------------------------------------------- /notebooks/assets/BuildingBlocks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/BuildingBlocks.png -------------------------------------------------------------------------------- /notebooks/assets/CPPDevelopment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/CPPDevelopment.png -------------------------------------------------------------------------------- /notebooks/assets/Do-While-Loop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/Do-While-Loop.png -------------------------------------------------------------------------------- /notebooks/assets/MemorySegments.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/MemorySegments.png -------------------------------------------------------------------------------- /notebooks/assets/memory-layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/memory-layout.png -------------------------------------------------------------------------------- /notebooks/demos/header_files/triangle/triangles_db.txt: -------------------------------------------------------------------------------- 1 | Triangle's side1, side2, side3 2 | 3 4 5 3 | 4 5 6 4 | 9 4 10 5 | 7 9 11 6 | -------------------------------------------------------------------------------- /pdfs/DataVariablesAndOperations.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/pdfs/DataVariablesAndOperations.pdf -------------------------------------------------------------------------------- /labs/strings/simonsays/sample_tests/3.in: -------------------------------------------------------------------------------- 1 | 3 2 | Raise your right hand. 3 | Lower your right hand. 4 | Simon says raise your left hand. 5 | -------------------------------------------------------------------------------- /latex/resources/VariablesAndMemory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/VariablesAndMemory.png -------------------------------------------------------------------------------- /latex/resources/multi-wayselector.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/multi-wayselector.png -------------------------------------------------------------------------------- /latex/resources/range-rbegin-rend.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/range-rbegin-rend.png -------------------------------------------------------------------------------- /notebooks/assets/ifelsestatement.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/ifelsestatement.png -------------------------------------------------------------------------------- /notebooks/assets/multi-wayselector.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/multi-wayselector.png -------------------------------------------------------------------------------- /notebooks/assets/pointers-in-cpp.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/pointers-in-cpp.jpg -------------------------------------------------------------------------------- /notebooks/assets/range-begin-end.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/range-begin-end.png -------------------------------------------------------------------------------- /notebooks/assets/range-rbegin-rend.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/range-rbegin-rend.png -------------------------------------------------------------------------------- /notebooks/demos/file_io/inputfile.txt: -------------------------------------------------------------------------------- 1 | this is first sentence. 2 | this is 2nd sentence 3 | some numbers are below 4 | 10 5 | 20 6 | 30 7 | -------------------------------------------------------------------------------- /oryx-build-commands.txt: -------------------------------------------------------------------------------- 1 | PlatformWithVersion=Python 2 | BuildCommands=conda env create --file environment.yml --prefix ./venv --quiet 3 | -------------------------------------------------------------------------------- /notebooks/assets/VariablesAndMemory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/VariablesAndMemory.png -------------------------------------------------------------------------------- /exercises/stdio/hangman/Hangman-README.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/exercises/stdio/hangman/Hangman-README.pdf -------------------------------------------------------------------------------- /labs/maps/baconeggsandspam/data/1.in: -------------------------------------------------------------------------------- 1 | 3 2 | Alice bacon eggs spam 3 | Sue pancakes sausage ham 4 | David eggs spam 5 | 1 6 | Bill diet-coke 7 | 0 8 | -------------------------------------------------------------------------------- /labs/math/dfyrirdreki/src/roots.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | long long find_discriminant(int a, int b, int c); 4 | int find_roots(long long discriminant); -------------------------------------------------------------------------------- /labs/strings/simonsays/sample_tests/2.in: -------------------------------------------------------------------------------- 1 | 3 2 | Simon says raise your right hand. 3 | Lower your right hand. 4 | Simon says raise your left hand. 5 | -------------------------------------------------------------------------------- /latex/resources/Cartesian-coordinates.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/Cartesian-coordinates.png -------------------------------------------------------------------------------- /latex/resources/scopesandnameresolution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/latex/resources/scopesandnameresolution.png -------------------------------------------------------------------------------- /notebooks/assets/Cartesian-coordinates.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/Cartesian-coordinates.png -------------------------------------------------------------------------------- /labs/maps/baconeggsandspam/data/sample.in: -------------------------------------------------------------------------------- 1 | 3 2 | Alice bacon eggs spam 3 | Sue pancakes sausage ham 4 | David eggs spam 5 | 1 6 | Bill diet-coke 7 | 0 8 | -------------------------------------------------------------------------------- /notebooks/assets/scopesandnameresolution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/HEAD/notebooks/assets/scopesandnameresolution.png -------------------------------------------------------------------------------- /labs/stdio/ascii/util.h: -------------------------------------------------------------------------------- 1 | // Utility functions for ASCII art 2 | #pragma once // header guard 3 | 4 | #include 5 | 6 | std::string center_text(int, const std::string &); -------------------------------------------------------------------------------- /notebooks/demos/header_files/triangle/utility.h: -------------------------------------------------------------------------------- 1 | // utility functions 2 | #pragma once // include guard; tells the compiler to only include this file once 3 | 4 | void clear(); -------------------------------------------------------------------------------- /labs/maps/baconeggsandspam/data/1.ans: -------------------------------------------------------------------------------- 1 | bacon Alice 2 | eggs Alice David 3 | ham Sue 4 | pancakes Sue 5 | sausage Sue 6 | spam Alice David 7 | 8 | diet-coke Bill 9 | 10 | -------------------------------------------------------------------------------- /labs/maps/baconeggsandspam/data/sample.ans: -------------------------------------------------------------------------------- 1 | bacon Alice 2 | eggs Alice David 3 | ham Sue 4 | pancakes Sue 5 | sausage Sue 6 | spam Alice David 7 | 8 | diet-coke Bill 9 | 10 | -------------------------------------------------------------------------------- /labs/loops/doggopher/doggopher.yaml: -------------------------------------------------------------------------------- 1 | accepted: 0 2 | cpu_limit: 1 second 3 | difficulty: 2.2 Easy 4 | mem_limit: 1024 MB 5 | problemid: doggopher 6 | submissions: 0 7 | title: Dog & Gopher 8 | -------------------------------------------------------------------------------- /labs/unittest/triarea/triarea.yaml: -------------------------------------------------------------------------------- 1 | accepted: 1 2 | cpu_limit: 1 second 3 | difficulty: 1.2 Easy 4 | mem_limit: 1024 MB 5 | problemid: triarea 6 | submissions: 1 7 | title: Triangle Area 8 | -------------------------------------------------------------------------------- /create_environment.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | mamba create -n xeus-cling -c conda-forge cmake xeus-zmq cling nlohmann_json=3.11.2 cppzmq xtl pugixml doctest cpp-argparse 3 | source activate xeus-cling 4 | -------------------------------------------------------------------------------- /labs/math/dfyrirdreki/dfyrirdreki.yaml: -------------------------------------------------------------------------------- 1 | accepted: 1 2 | cpu_limit: 1 second 3 | difficulty: 1.2 Easy 4 | mem_limit: 1024 MB 5 | problemid: dfyrirdreki 6 | submissions: 1 7 | title: D Fyrir Dreki 8 | -------------------------------------------------------------------------------- /labs/unittest/mclimbroad/mclimbroad.yaml: -------------------------------------------------------------------------------- 1 | accepted: 0 2 | cpu_limit: 1 second 3 | difficulty: 1.4 Easy 4 | mem_limit: 1024 MB 5 | problemid: mclimbroad 6 | submissions: 0 7 | title: M-Climb Road 8 | -------------------------------------------------------------------------------- /environment.yml: -------------------------------------------------------------------------------- 1 | name: cpp 2 | channels: 3 | - conda-forge 4 | - defaults 5 | dependencies: 6 | - xeus-cling 7 | - python 8 | - pip: 9 | - -r requirements.txt 10 | -------------------------------------------------------------------------------- /labs/loops/nostragglers/nostragglers.yaml: -------------------------------------------------------------------------------- 1 | accepted: 1 2 | cpu_limit: 3 seconds 3 | difficulty: 1.3 Easy 4 | mem_limit: 1024 MB 5 | problemid: nostragglers 6 | submissions: 1 7 | title: No Stragglers 8 | -------------------------------------------------------------------------------- /labs/maps/sevenwonders/sevenwonders.yaml: -------------------------------------------------------------------------------- 1 | accepted: 1 2 | cpu_limit: 1 second 3 | difficulty: 1.5 Easy 4 | mem_limit: 1024 MB 5 | problemid: sevenwonders 6 | submissions: 1 7 | title: Seven Wonders 8 | -------------------------------------------------------------------------------- /labs/namespaces/grafaholur/grafaholur.yaml: -------------------------------------------------------------------------------- 1 | accepted: 1 2 | cpu_limit: 1 second 3 | difficulty: 1.3 - 1.4 Easy 4 | mem_limit: 1024 MB 5 | problemid: grafaholur 6 | submissions: 1 7 | title: Diggy Hole 8 | -------------------------------------------------------------------------------- /labs/pointers/timeloop/timeloop.yaml: -------------------------------------------------------------------------------- 1 | accepted: 0 2 | cpu_limit: 1 second 3 | difficulty: 1.2 Easy 4 | mem_limit: 1024 MB 5 | problemid: timeloop 6 | submissions: 0 7 | title: Stuck In A Time Loop 8 | -------------------------------------------------------------------------------- /labs/math/addtwonumbers/addtwonumbers.yaml: -------------------------------------------------------------------------------- 1 | accepted: 0 2 | cpu_limit: 1 second 3 | difficulty: 1.2 Easy 4 | mem_limit: 1024 MB 5 | problemid: addtwonumbers 6 | submissions: 0 7 | title: Add Two Numbers 8 | -------------------------------------------------------------------------------- /labs/unittest/mclimbroad/src/util.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // FUNCTION PROTOTYPES 4 | int convert_miles_to_feet(const int miles); 5 | int calculate_answer(const int total_feet, const int numb_students); 6 | -------------------------------------------------------------------------------- /labs/vectors/foxsays/1.in: -------------------------------------------------------------------------------- 1 | 1 2 | toot woof wa ow ow ow pa blub blub pa toot pa blub pa pa ow pow toot 3 | dog goes woof 4 | fish goes blub 5 | elephant goes toot 6 | seal goes ow 7 | what does the fox say? 8 | -------------------------------------------------------------------------------- /notebooks/demos/header_files/header/utility.h: -------------------------------------------------------------------------------- 1 | #pragma once // include guard; tells the compiler to only include this file once 2 | 3 | long add(int, int); 4 | void print(long); 5 | void getData(int &, int &); -------------------------------------------------------------------------------- /labs/functions/thelastproblem/thelastproblem.yaml: -------------------------------------------------------------------------------- 1 | accepted: 0 2 | cpu_limit: 1 second 3 | difficulty: 1.4 Easy 4 | mem_limit: 1024 MB 5 | problemid: thelastproblem 6 | submissions: 1 7 | title: The Last Problem 8 | -------------------------------------------------------------------------------- /labs/maps/baconeggsandspam/baconeggsandspam.yaml: -------------------------------------------------------------------------------- 1 | accepted: 2 2 | cpu_limit: 1 second 3 | difficulty: 1.9 Easy 4 | mem_limit: 1024 MB 5 | problemid: baconeggsandspam 6 | submissions: 2 7 | title: Bacon, Eggs, and Spam 8 | -------------------------------------------------------------------------------- /labs/pointers/timeloop/data/b.ans: -------------------------------------------------------------------------------- 1 | 1 Abracadabra 2 | 2 Abracadabra 3 | 3 Abracadabra 4 | 4 Abracadabra 5 | 5 Abracadabra 6 | 6 Abracadabra 7 | 7 Abracadabra 8 | 8 Abracadabra 9 | 9 Abracadabra 10 | 10 Abracadabra 11 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/morsecodepalindromes.yaml: -------------------------------------------------------------------------------- 1 | accepted: 0 2 | cpu_limit: 1 second 3 | difficulty: 3.9 Medium 4 | mem_limit: 2048 MB 5 | problemid: morsecodepalindromes 6 | submissions: 0 7 | title: Morse Code Palindromes 8 | -------------------------------------------------------------------------------- /labs/math/addtwonumbers/src/addtwo.cpp: -------------------------------------------------------------------------------- 1 | #include "addtwo.h" 2 | 3 | long add_two_numbers(int num1, int num2) 4 | { 5 | // FIXME4: implement the function to add two numbers and return the result 6 | return 0; // placeholder return 7 | } -------------------------------------------------------------------------------- /notebooks/demos/file_io/triangle/triangles_results.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 sides length: 7 9 11 3 | area: 31.4195 4 | perimeter: 27 5 | 6 | 3 sides length: 3 4 5 7 | area: 6 8 | perimeter: 12 9 | 10 | 3 sides length: 4 5 6 11 | area: 9.92157 12 | perimeter: 15 13 | -------------------------------------------------------------------------------- /labs/fileio/data/output.txt: -------------------------------------------------------------------------------- 1 | List of Numbers: 100 10 5 0 -99 10 99 2 | 3 | ======================================== 4 | Statistical Results 5 | ======================================== 6 | Max Min Mean Median Range 7 | 100 -99 17.86 10 199 -------------------------------------------------------------------------------- /labs/functions/thelastproblem/src/helper.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "helper.h" 3 | 4 | using namespace std; 5 | // Function implementation 6 | string twilight(const string &input) 7 | { 8 | string ans = "Thank you, " + input + ", and farewell!"; 9 | return ans; 10 | } -------------------------------------------------------------------------------- /labs/loops/nostragglers/src/utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Function prototypes can be added here if needed in the future 4 | int total_stragglers(int students, int visitors, int faculty); 5 | void update_count(char type, char in_out, int count, int &students, int &visitors, int &faculty); 6 | -------------------------------------------------------------------------------- /labs/unittest/triarea/src/triarea.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | const float MAX_ERROR = 0.00000001; 4 | 5 | // FUNCTION PROTOTYPES 6 | // Function finds the area of a right triangle given height and base 7 | float area_of_triangle(const unsigned, const unsigned); 8 | 9 | void test_area_with_assert(); -------------------------------------------------------------------------------- /notebooks/demos/unittest/assert1/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | 3 | CXXFLAGS = -c -g -Wall -std=c++17 4 | 5 | PROGRAM = unittest.exe 6 | 7 | CPPFILES = unittesting.cpp 8 | 9 | all: 10 | $(CXX) $(CXXFLAGS) $(CPPFILES) 11 | $(CXX) -o $(PROGRAM) *.o 12 | 13 | clean: 14 | rm -f $(PROGRAM) *.o -------------------------------------------------------------------------------- /notebooks/demos/functions/rectangle/Makefile: -------------------------------------------------------------------------------- 1 | 2 | CXX = g++ 3 | 4 | CXXFLAGS = -c -g -Wall -std=c++17 5 | 6 | PROGRAM = rectangle.exe 7 | 8 | CPPFILES = main.cpp 9 | 10 | all: 11 | $(CXX) $(CXXFLAGS) $(CPPFILES) 12 | $(CXX) -o $(PROGRAM) *.o 13 | 14 | clean: 15 | rm -f $(PROGRAM) *.o -------------------------------------------------------------------------------- /labs/loops/doggopher/src/doggopher.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define TOLERANCE 1e-6 // 10^-6 or 0.000001 4 | 5 | // Function prototypes 6 | // Function finds the the Euclidean distance given two points (x1, y1) and (x2, y2) 7 | float distance(const float x1, const float y1, const float x2, const float y2); 8 | -------------------------------------------------------------------------------- /labs/loops/shapes/src/shapes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | // Function prototypes for shapes lab 5 | std::stringstream get_triangle(int height); 6 | std::stringstream get_flipped_triangle(int height); 7 | void print_shape(const std::string); 8 | std::stringstream get_square(int height); 9 | void clear_scren(); -------------------------------------------------------------------------------- /notebooks/demos/unittest/assert2/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | 3 | CXXFLAGS = -c -g -Wall -std=c++17 4 | 5 | PROGRAM = unittest.exe 6 | 7 | CPPFILES = unittesting2.cpp 8 | 9 | all: 10 | $(CXX) $(CXXFLAGS) $(CPPFILES) 11 | $(CXX) -o $(PROGRAM) *.o 12 | 13 | clean: 14 | rm -f $(PROGRAM) *.o 15 | 16 | run: 17 | ./$(PROGRAM) 18 | -------------------------------------------------------------------------------- /notebooks/demos/unittest/assert3/Makefile: -------------------------------------------------------------------------------- 1 | 2 | CXX = g++ 3 | 4 | CXXFLAGS = -c -g -Wall -std=c++17 5 | 6 | PROGRAM = unittest.exe 7 | 8 | CPPFILES = unittesting3.cpp 9 | 10 | all: 11 | $(CXX) $(CXXFLAGS) $(CPPFILES) 12 | $(CXX) -o $(PROGRAM) *.o 13 | 14 | clean: 15 | rm -f $(PROGRAM) *.o 16 | 17 | run: 18 | ./$(PROGRAM) -------------------------------------------------------------------------------- /notebooks/demos/header_files/triangle/test.h: -------------------------------------------------------------------------------- 1 | #pragma once // include guard; tells the compiler to only include this file once 2 | 3 | // function prototypes of test functions 4 | void test_validTriangle(); 5 | void test_trianglePerimeter(); 6 | void assertAlmostEqual(float value1, float value2, int precision); 7 | void test_triangleArea(); 8 | -------------------------------------------------------------------------------- /labs/namespaces/grafaholur/src/dig.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // declare dig namespace and header file contents 3 | namespace dig 4 | { 5 | double calculate_rate_per_worker(int n_workers, int h_hours, int x_cubic_meters); 6 | double calculate_time_needed(int m_workers, double rate_per_worker, int y_cubic_meters); 7 | const double EPSILON = 1e-1; 8 | } -------------------------------------------------------------------------------- /notebooks/demos/header_files/header/utility.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | long add(int x, int y) { 5 | return x+y; 6 | } 7 | 8 | void print(long x) { 9 | cout << x << endl; 10 | } 11 | 12 | void getData(int & x, int & y) { 13 | cout << "Enter two numbers separated by space: "; 14 | cin >> x >> y; 15 | } -------------------------------------------------------------------------------- /labs/functions/thelastproblem/src/helper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | using namespace std; 4 | 5 | // Function prototypes 6 | // Function finds the answer from given string and restuns the result as a string 7 | string twilight(const string &); 8 | // Function reads the data from standard input and returns the data 9 | string read_data(); 10 | -------------------------------------------------------------------------------- /notebooks/demos/file_io/formatted_output.txt: -------------------------------------------------------------------------------- 1 | ================================================= 2 | Item Price 3 | ================================================= 4 | Apple 5.99 5 | Carrots 2.55 6 | ************************************************* 7 | -------------------------------------------------------------------------------- /labs/loops/doggopher/src/doggopher.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Function implementation 3 | float distance(const float x1, const float y1, const float x2, const float y2) 4 | { 5 | float dist = 0; 6 | // FIXME4: Find the Eucledian distance between two points on 2-d coordiantes. 7 | // store the distance into the `dist` variable and return it 8 | return dist; 9 | } 10 | -------------------------------------------------------------------------------- /labs/functions/library/src/my_math.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // Mathematical utility functions 3 | float square_root(float x); 4 | float cube_root(float x); 5 | float power_of_ten(float x); 6 | float log_base_2(float x); 7 | float log_base_10(float x); 8 | float degree_to_radian(float degree); 9 | float sine_of_radian(float radian); 10 | float cosine_of_radian(float radian); 11 | -------------------------------------------------------------------------------- /notebooks/demos/unittest/assert/Makefile: -------------------------------------------------------------------------------- 1 | COMPILER = g++ 2 | 3 | COMPILER_FLAGS = -c -g -Wall -std=c++17 4 | 5 | PROGRAM_NAME = assert.exe 6 | 7 | CPP_FILES = assertdebug.cpp 8 | 9 | build: 10 | $(COMPILER) $(COMPILER_FLAGS) $(CPP_FILES) 11 | $(COMPILER) -o $(PROGRAM_NAME) *.o 12 | 13 | 14 | run: 15 | ./$(PROGRAM_NAME) 16 | 17 | clean: 18 | rm -f $(PROGRAM_NAME) *.o 19 | -------------------------------------------------------------------------------- /labs/arrays/modulo/src/modulo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | // Function prototypes for modulo lab 5 | using namespace std; 6 | 7 | void read_data(unsigned int *, size_t); 8 | unsigned int get_modulo_42(const unsigned int); 9 | void update_flags(const unsigned int *, bool *, size_t); 10 | size_t count_flags(const bool[], size_t); 11 | void init_flags(bool *, size_t); 12 | -------------------------------------------------------------------------------- /notebooks/demos/functions/func_prototype/Makefile: -------------------------------------------------------------------------------- 1 | COMPILER = g++ 2 | 3 | COMPILER_FLAGS = -c -g -Wall -std=c++17 4 | 5 | PROGRAM_NAME = func_prototype.exe 6 | 7 | CPP_FILES = func_prototype.cpp 8 | 9 | build: 10 | $(COMPILER) $(COMPILER_FLAGS) $(CPP_FILES) 11 | $(COMPILER) -o $(PROGRAM_NAME) *.o 12 | 13 | run: 14 | ./$(PROGRAM_NAME) 15 | 16 | clean: 17 | rm -f $(PROGRAM_NAME) *.o 18 | -------------------------------------------------------------------------------- /notebooks/demos/header_files/header/main.cpp: -------------------------------------------------------------------------------- 1 | // main program 2 | 3 | #include 4 | #include "utility.h" //user-defined header file 5 | using namespace std; 6 | 7 | int main(int argc, char* argv[]) { 8 | int num1, num2; 9 | long ans; 10 | getData(num1, num2); 11 | ans = add(num1, num2); 12 | cout << "sum = "; 13 | print(ans); 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /notebooks/demos/intro/Makefile: -------------------------------------------------------------------------------- 1 | # a simple Makefile with 3 rules 2 | 3 | # rule for compiling program 4 | # make or make compile triggers the following rule 5 | compile: 6 | g++ helloworld.cpp 7 | 8 | # rule for running programming 9 | # make run triggers the following rule 10 | run: 11 | ./a.out 12 | 13 | # rule for clean up 14 | # make clean triggers the following rule 15 | clean: 16 | rm -f a.out 17 | -------------------------------------------------------------------------------- /notebooks/demos/makefiles/demo1/Makefile: -------------------------------------------------------------------------------- 1 | # a simple Makefile with 3 rules 2 | 3 | # rule for compiling program 4 | # make or make compile triggers the following rule 5 | compile: 6 | g++ hello.cpp 7 | 8 | # rule for running programming 9 | # make run triggers the following rule 10 | run: 11 | ./a.out 12 | 13 | # rule for clean up 14 | # make clean triggers the following rule 15 | clean: 16 | rm -f a.out 17 | -------------------------------------------------------------------------------- /labs/maps/baconeggsandspam/src/bacon.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | using map_str_set = map>; 11 | 12 | // function prototypes 13 | vector split_string(const string &line); 14 | map_str_set read_items(int n); 15 | void print_items(const map_str_set &items); 16 | void solve(); 17 | -------------------------------------------------------------------------------- /notebooks/codespaces+zany-pancake-57rgjjwrxgfr5r:.inetloc: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | URL 6 | vscode-remote://codespaces%2Bzany-pancake-57rgjjwrxgfr5r/workspaces/CPP-Fundamentals/notebooks/RegularExpressions.ipynb 7 | 8 | 9 | -------------------------------------------------------------------------------- /notebooks/demos/unittest/doctest/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CXXFLAGS = -std=c++17 -I tests 3 | SRC = $(wildcard src/*.cpp) 4 | TESTS = $(wildcard tests/*.cpp) 5 | 6 | run_tests: 7 | $(CXX) $(CXXFLAGS) $(TESTS) $(SRC) -o doctest_runner.exe 8 | ./doctest_runner.exe 9 | @echo "All tests executed successfully!" 10 | 11 | clean: 12 | find . -type f -name "doctest_runner.exe" -delete 13 | find . -type f -name "*.o" -delete -------------------------------------------------------------------------------- /labs/maps/sevenwonders/src/sevenwonders.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | using pos_int = unsigned int; // create type alias 6 | 7 | // function prototypes 8 | std::unordered_map count_cards(const std::string &); 9 | pos_int count_points(const std::unordered_map &); 10 | pos_int count_bonus(const std::unordered_map &); 11 | void solve(); -------------------------------------------------------------------------------- /labs/namespaces/grafaholur/src/dig.cpp: -------------------------------------------------------------------------------- 1 | #include "dig.h" 2 | 3 | double dig::calculate_rate_per_worker(int n_workers, int h_hours, int x_cubic_meters) 4 | { 5 | return static_cast(x_cubic_meters) / (n_workers * h_hours); 6 | } 7 | 8 | double dig::calculate_time_needed(int m_workers, double rate_per_worker, int y_cubic_meters) 9 | { 10 | return static_cast(y_cubic_meters) / (m_workers * rate_per_worker); 11 | } -------------------------------------------------------------------------------- /notebooks/demos/makefiles/demo2/Makefile: -------------------------------------------------------------------------------- 1 | # a simple Makefile with 3 rules 2 | 3 | # rule for compiling program 4 | # make or make compile triggers the following rule 5 | compile: 6 | g++ -g -Wall -std=c++17 -o hello.exe hello.cpp 7 | 8 | # rule for running programming 9 | # make run triggers the following rule 10 | run: 11 | ./hello.exe 12 | 13 | # rule for clean up 14 | # make clean triggers the following rule 15 | clean: 16 | rm -f hello.exe 17 | -------------------------------------------------------------------------------- /labs/conditionals/twostones/src/twostones.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | using namespace std; 5 | 6 | // Function prototypes 7 | // given a positive integer, the function finds and returns 'even' or 'odd' 8 | string odd_or_even(const int unsigned); 9 | // function to test odd_or_even function 10 | void test_odd_or_even(); 11 | // given a positive integer, function returns the answer as expected by Kattis 12 | string answer(const int unsigned); -------------------------------------------------------------------------------- /labs/pointers/timeloop/src/timeloop.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | using namespace std; 4 | 5 | // declare alias pos_short of type "unsigned int" 6 | using pos_short = unsigned short; 7 | 8 | // Function taken an integer n and returns 9 | // spell: n Abracadabra 10 | string cast_spell(const pos_short); 11 | 12 | // function to print the final answer 13 | void print_answer(const pos_short *); 14 | 15 | // function to read N 16 | pos_short read_number(); 17 | -------------------------------------------------------------------------------- /notebooks/demos/classes/points/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CXXFLAGS = -std=c++17 -Wall -Wextra -pedantic 3 | TARGET = point.exe 4 | SRCS = $(wildcard src/*.cpp) 5 | 6 | all: $(TARGET) 7 | $(TARGET): $(SRCS) 8 | $(CXX) $(CXXFLAGS) -o $(TARGET) $(SRCS) 9 | 10 | run: $(TARGET) 11 | ./$(TARGET) 12 | 13 | clean: 14 | rm -f *.exe 15 | 16 | unittest: $(TARGET) 17 | $(CXX) $(CXXFLAGS) -o test_point.exe tests/test_point.cpp src/point.cpp -I src 18 | ./test_point.exe 19 | 20 | -------------------------------------------------------------------------------- /notebooks/demos/stdio/carrots/carrots.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Kattis problem - https://open.kattis.com/problems/carrots 3 | Solving for Carrots 4 | 5 | Algorithm steps: 6 | - read only the first line (two numbers) 7 | - output the second number 8 | */ 9 | 10 | #include 11 | #include // printf 12 | 13 | using namespace std; 14 | 15 | int main() { 16 | int N, P; 17 | cin >> N >> P; 18 | //cout << P << endl; 19 | printf("%d\n", P); 20 | return 0; 21 | } -------------------------------------------------------------------------------- /labs/math/dfyrirdreki/src/roots.cpp: -------------------------------------------------------------------------------- 1 | #include "roots.h" 2 | 3 | long long find_discriminant(int a, int b, int c) 4 | { 5 | long long discriminant = 0; // placeholder return 6 | // FIXME2: implement the function to calculate and return the discriminant 7 | return discriminant; 8 | } 9 | 10 | int find_roots(long long discriminant) 11 | { 12 | if (discriminant < 0) 13 | return 0; 14 | // FIXME3: complete the rest of the logic to determine number of real roots 15 | } -------------------------------------------------------------------------------- /labs/stdio/ascii/util.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "util.h" 3 | using namespace std; 4 | 5 | // given width of the column and the string, function returns centered string within the column 6 | string center_text(int width, const string &str) 7 | { 8 | int len = str.length(); 9 | if (width < len) 10 | return str; 11 | int diff = width - len; 12 | int pad1 = diff / 2; 13 | int pad2 = diff - pad1; 14 | return string(pad1, ' ') + str + string(pad2, ' '); 15 | } -------------------------------------------------------------------------------- /labs/unittest/mclimbroad/src/mclimbroad.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "util.h" 3 | 4 | using namespace std; 5 | 6 | int convert_miles_to_feet(const int miles) 7 | { 8 | // FIXME2: Convert miles to feet and return the value 9 | return miles; 10 | } 11 | 12 | int calculate_answer(const int total_feet, const int numb_students) 13 | { 14 | // FIXME3: Calculate and return the answer 15 | // Number of times you'll be squirted with a water gun 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /notebooks/demos/classes/points/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "point.hpp" 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | Point p1(3.0, 4.0); 9 | Point p2(1.0, 2.0); 10 | Point p3 = p1 + p2; 11 | 12 | cout << p3 << endl; 13 | Point p4(3.0, 4.0); 14 | if (p1 == p4) 15 | { 16 | cout << "p1 is equal to p4" << endl; 17 | } 18 | else 19 | { 20 | cout << "p1 is not equal to p4" << endl; 21 | } 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /notebooks/demos/classes/points/src/point.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | class Point 8 | { 9 | private: 10 | double *x; 11 | double *y; 12 | 13 | public: 14 | Point(double xCoord, double yCoord); 15 | double distance_from_origin() const; 16 | Point operator+(const Point &p) const; 17 | bool operator==(const Point &p) const; 18 | friend ostream &operator<<(ostream &os, const Point &p); 19 | ~Point(); 20 | }; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | .DS_Store 35 | .ipynb_checkpoints/ 36 | .vscode/ 37 | venv/ 38 | __pycache__/ 39 | *.pyc 40 | *.pyo 41 | -------------------------------------------------------------------------------- /labs/loops/doggopher/tests/test_doggopher.cpp: -------------------------------------------------------------------------------- 1 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 2 | #include "../../../doctest/doctest.h" // FIXME: adjust the path as needed 3 | #include "../src/doggopher.h" 4 | 5 | TEST_CASE("Testing distance function") 6 | { 7 | SUBCASE("Sub Case 1") 8 | { 9 | CHECK(distance(0, 0, 0, 0) == 0); 10 | } 11 | SUBCASE("Sub Case 2") 12 | { 13 | CHECK(distance(0, 0, 3, 4) == 5); 14 | } 15 | // FIXME35: Write 2 more test sub cases for distance function with at least 2 subcases 16 | } -------------------------------------------------------------------------------- /notebooks/demos/makefiles/demo4/Makefile: -------------------------------------------------------------------------------- 1 | # a simple Makefile with 3 rules 2 | 3 | # rule for compiling program 4 | # make or make build triggers the following rule 5 | build: 6 | # compiles .cpp to object file .o 7 | g++ -c -g -Wall -std=c++17 hello.cpp 8 | # builds executable from object files 9 | g++ -o hello.exe hello.o 10 | 11 | # rule for running programming 12 | # make run triggers the following rule 13 | run: 14 | ./hello.exe 15 | 16 | # rule for clean up 17 | # make clean triggers the following rule 18 | clean: 19 | rm -f hello.exe hello.o 20 | -------------------------------------------------------------------------------- /labs/math/addtwonumbers/tests/test_addtwo.cpp: -------------------------------------------------------------------------------- 1 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 2 | #include "../../../doctest/doctest.h" // FIXME: adjust the path as needed 3 | #include "../src/addtwo.h" 4 | 5 | TEST_CASE("Testing add_two_numbers function") 6 | { 7 | SUBCASE("Basic additions of smalle positive numbers") 8 | { 9 | CHECK(add_two_numbers(2, 3) == 5); 10 | } 11 | SUBCASE("Adding small negative and positive numbers") 12 | { 13 | CHECK(add_two_numbers(-1, 1) == 0); 14 | } 15 | // FIXME5: Add 3 more test cases to cover edge cases 16 | } -------------------------------------------------------------------------------- /notebooks/demos/makefiles/demo3/Makefile: -------------------------------------------------------------------------------- 1 | # a simple Makefile with 4 rules 2 | 3 | # rule for compiling program 4 | # make or make compile triggers the rule 5 | compile: 6 | # compiles .cpp to object file .o 7 | g++ -c -g -Wall -std=c++17 hello.cpp 8 | 9 | # rule for building executable program 10 | # make or make build triggers the rule 11 | build: 12 | g++ -o hello.exe hello.o 13 | 14 | # rule for running programming 15 | # make run triggers the rule 16 | run: 17 | ./hello.exe 18 | 19 | # rule for clean up 20 | # make clean triggers the rule 21 | clean: 22 | rm -f hello.exe hello.o 23 | -------------------------------------------------------------------------------- /exercises/intro/helloworld/main.cpp: -------------------------------------------------------------------------------- 1 | /*================================================= 2 | Hello World program 3 | By: Ram Basnet 4 | Date: June 24, 2020 5 | Copyright: MIT License 6 | 7 | The program prints "Hello World!" on the console 8 | ===================================================*/ 9 | 10 | // include required libraries/header files 11 | #include 12 | 13 | // one main function is always required in a C++ program 14 | int main() // main entry to the program 15 | { 16 | // output/print Hello World! 17 | std::cout << "Hello World!" << std::endl; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /notebooks/demos/intro/helloworld.cpp: -------------------------------------------------------------------------------- 1 | /*================================================= 2 | Hello World program 3 | By: Ram Basnet 4 | Date: June 24, 2020 5 | Copyright: MIT License 6 | 7 | The program prints "Hello World!" on the console 8 | ===================================================*/ 9 | 10 | // include required libraries/header files 11 | #include 12 | 13 | // one main function is always required in a C++ program 14 | int main() // main entry to the program 15 | { 16 | // output/print Hello World! 17 | std::cout << "Hello World!" << std::endl; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /notebooks/demos/makefiles/demo1/hello.cpp: -------------------------------------------------------------------------------- 1 | /*================================================= 2 | Hello World program 3 | Author: Ram Basnet 4 | Date: June 24, 2020 5 | Copyright: MIT License 6 | 7 | The program prints "Hello World!" on the console. 8 | ===================================================*/ 9 | 10 | // include required libraries/header files 11 | #include 12 | 13 | // one main function is always required in a C++ program 14 | int main() // main entry to the program 15 | { 16 | // output/print Hello World! 17 | std::cout << "Hello World!" << std::endl; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /notebooks/demos/makefiles/demo2/hello.cpp: -------------------------------------------------------------------------------- 1 | /*================================================= 2 | Hello World program 3 | Author: Ram Basnet 4 | Date: June 24, 2020 5 | Copyright: MIT License 6 | 7 | The program prints "Hello World!" on the console. 8 | ===================================================*/ 9 | 10 | // include required libraries/header files 11 | #include 12 | 13 | // one main function is always required in a C++ program 14 | int main() // main entry to the program 15 | { 16 | // output/print Hello World! 17 | std::cout << "Hello World!" << std::endl; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /notebooks/demos/makefiles/demo3/hello.cpp: -------------------------------------------------------------------------------- 1 | /*================================================= 2 | Hello World program 3 | Author: Ram Basnet 4 | Date: June 24, 2020 5 | Copyright: MIT License 6 | 7 | The program prints "Hello World!" on the console. 8 | ===================================================*/ 9 | 10 | // include required libraries/header files 11 | #include 12 | 13 | // one main function is always required in a C++ program 14 | int main() // main entry to the program 15 | { 16 | // output/print Hello World! 17 | std::cout << "Hello World!" << std::endl; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /notebooks/demos/makefiles/demo4/hello.cpp: -------------------------------------------------------------------------------- 1 | /*================================================= 2 | Hello World program 3 | By: Ram Basnet 4 | Date: June 24, 2020 5 | Copyright: MIT License 6 | 7 | The program prints "Hello World!" on the console. 8 | ===================================================*/ 9 | 10 | // include required libraries/header files 11 | #include 12 | 13 | // one main function is always required in a C++ program 14 | int main() // main entry to the program 15 | { 16 | // output/print Hello World! 17 | std::cout << "Hello World!" << std::endl; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /notebooks/demos/makefiles/demo5/hello.cpp: -------------------------------------------------------------------------------- 1 | /*================================================= 2 | Hello World program 3 | Author: Ram Basnet 4 | Date: June 24, 2020 5 | Copyright: MIT License 6 | 7 | The program prints "Hello World!" on the console. 8 | ===================================================*/ 9 | 10 | // include required libraries/header files 11 | #include 12 | 13 | // one main function is always required in a C++ program 14 | int main() // main entry to the program 15 | { 16 | // output/print Hello World! 17 | std::cout << "Hello World!" << std::endl; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /notebooks/demos/vectors/triangle/output.txt: -------------------------------------------------------------------------------- 1 | ================================================================ 2 | Triangles Report 3 | ================================================================ 4 | ID side 1 side 2 side 3 area perimeter 5 | **************************************************************** 6 | 1 7.00 9.00 11.00 31.42 27.00 7 | 2 3.00 4.00 5.00 6.00 12.00 8 | 3 4.00 5.00 6.00 9.92 15.00 9 | **************************************************************** 10 | -------------------------------------------------------------------------------- /labs/fileio/src/fileio.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | const float EPSILON = 1e-4; // accuracy upto 4 decimal points 7 | 8 | // function prototypes 9 | void read_data(vector &, const string); 10 | int find_max(const vector &); 11 | int find_min(const vector &); 12 | float find_mean(const vector &); // average 13 | int find_range(const vector &); 14 | float find_median(vector); 15 | // bonus implement findMode function 16 | int find_mode(const vector &); 17 | 18 | void write_data(const vector &numbers); 19 | void test(); -------------------------------------------------------------------------------- /notebooks/demos/vectors/triangle/triangles_report.txt: -------------------------------------------------------------------------------- 1 | ================================================================ 2 | Triangles Report 3 | ================================================================ 4 | ID side 1 side 2 side 3 area perimeter 5 | **************************************************************** 6 | 1 7.00 9.00 11.00 31.42 27.00 7 | 2 3.00 4.00 5.00 6.00 12.00 8 | 3 4.00 5.00 6.00 9.92 15.00 9 | **************************************************************** 10 | -------------------------------------------------------------------------------- /labs/pointers/timeloop/src/timeloop.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "timeloop.h" 4 | 5 | using namespace std; 6 | 7 | pos_short read_number() 8 | { 9 | // FIXME3: Declare a dynamic variable to read and store N and return it 10 | pos_short *N; 11 | return *N; 12 | } 13 | 14 | string cast_spell(pos_short n) 15 | { 16 | // FIXME4: return the single spell string as per the format "n Abracadabra" 17 | return ""; 18 | } 19 | 20 | void print_answer(const pos_short *N) 21 | { 22 | for (pos_short i = 1; i <= *N; i++) 23 | { 24 | cout << cast_spell(i) << endl; 25 | } 26 | } -------------------------------------------------------------------------------- /labs/arrays/numbers/src/utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | using big_int = long long int; 4 | 5 | // function that reads numbers 6 | void read_data(int *, int); 7 | // function that finds max & min numbers from given array of numbers 8 | void find_max_min(int *, int, int &, int &); 9 | // function that finds the sum of the numbers in a given array 10 | big_int find_sum(int *, int); 11 | // function that sorts the numbes into ascending order 12 | void bubble_sort(int *, int); 13 | // function that prints each element in the array 14 | void print_array(int *, int); 15 | // menu function to display menu and get user choice 16 | int menu(); 17 | -------------------------------------------------------------------------------- /exercises/variables/exercise1/main.cpp: -------------------------------------------------------------------------------- 1 | // solution to Exercise 1 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | long st_id; // student id 7 | string st_first_name; // first name 8 | string st_last_name; 9 | string st_address; // complete address 10 | string emg_contact_name; // emergency contact's full name 11 | float GPA; 12 | // courses enrollment info? 13 | 14 | st_id = 700123456; 15 | st_first_name = "Jane"; 16 | st_last_name = "Smith"; 17 | st_address = "123 Awesome Street"; 18 | emg_contact_name = "Joe Smith"; 19 | GPA = 4.0; 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /notebooks/demos/variables/exercise1.cpp: -------------------------------------------------------------------------------- 1 | // solution to Exercise 1 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | long st_id; // student id 7 | string st_first_name; // first name 8 | string st_last_name; 9 | string st_address; // complete address 10 | string emg_contact_name; // emergency contact's full name 11 | float GPA; 12 | // courses enrollment info? 13 | 14 | st_id = 700123456; 15 | st_first_name = "Jane"; 16 | st_last_name = "Smith"; 17 | st_address = "123 Awesome Street"; 18 | emg_contact_name = "Joe Smith"; 19 | GPA = 4.0; 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /notebooks/demos/unittest/doctest/src/fruitful.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Fruitful functions for demonstration of doctest 4 | 5 | // Function that returns the sum of two integers 6 | int add(int a, int b); 7 | // Function that returns the maximum of two integers 8 | int max(int a, int b); 9 | // Function that returns the minimum of two integers 10 | int min(int a, int b); 11 | // Function that returns the factorial of a non-negative integer 12 | int factorial(int n); 13 | // Function that returns the nth Fibonacci number 14 | int fibonacci_recursive(int n); 15 | // Function that returns the nth Fibonacci number using iteration 16 | int fibonacci_iterative(int n); 17 | -------------------------------------------------------------------------------- /labs/functions/thelastproblem/tests/test_helper.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../src/helper.h" 3 | #include 4 | 5 | using namespace std; 6 | 7 | void test_twilight_1() 8 | { 9 | string input = "Alice"; 10 | string expected = "Thank you, Alice, and farewell!"; 11 | string result = twilight(input); 12 | assert(result == expected); 13 | } 14 | 15 | void test_twilight_2() 16 | { 17 | string input = "Bob"; 18 | string expected = "Thank you, Bob, and farewell!"; 19 | string result = twilight(input); 20 | assert(result == expected); 21 | } 22 | 23 | int main() 24 | { 25 | test_twilight_1(); 26 | test_twilight_2(); 27 | return 0; 28 | } -------------------------------------------------------------------------------- /labs/loops/shapes/tests/test_shapes.cpp: -------------------------------------------------------------------------------- 1 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 2 | #include "../../../doctest/doctest.h" // FIXME: adjust the path as needed 3 | #include "../src/shapes.h" 4 | 5 | TEST_CASE("Testing get_triangle function") 6 | { 7 | SUBCASE("Height 3") 8 | { 9 | std::stringstream triangle_3 = get_triangle(3); 10 | std::string expected_3 = "* \n* * \n* * * \n"; 11 | CHECK(triangle_3.str() == expected_3); 12 | } 13 | 14 | SUBCASE("Height 5") 15 | { 16 | std::stringstream triangle_5 = get_triangle(5); 17 | std::string expected_5 = "* \n* * \n* * * \n* * * * \n* * * * * \n"; 18 | CHECK(triangle_5.str() == expected_5); 19 | } 20 | } -------------------------------------------------------------------------------- /labs/loops/nostragglers/src/nostragglers.cpp: -------------------------------------------------------------------------------- 1 | // Implementation of utility functions for No Stragglers problem 2 | #include "utils.h" 3 | 4 | int total_stragglers(int students, int visitors, int faculty) 5 | { 6 | // FIXME4: Return the total number of stragglers 7 | return 0; 8 | } 9 | 10 | void update_count(char type, char in_out, int count, int &students, int &visitors, int &faculty) 11 | { 12 | switch (type) 13 | { 14 | case 'S': 15 | if (in_out == 'I') 16 | students += count; 17 | else 18 | students -= count; 19 | break; 20 | // FIXME5: Implement logic for 'V' (visitors) 21 | // FIXME6: Implement logic for 'F' (faculty) 22 | } 23 | } -------------------------------------------------------------------------------- /labs/arrays/modulo/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CXXFLAGS = -c -g -Wall -std=c++17 3 | 4 | PROGRAM = modulo.exe 5 | 6 | # list .cpp files separated by space 7 | SRC = $(wildcard src/*.cpp) 8 | TEST_FILES = $(wildcard tests/*.cpp) 9 | 10 | all: build doctest run clean 11 | 12 | build: 13 | $(CXX) $(CXXFLAGS) $(SRC) 14 | $(CXX) -o $(PROGRAM) *.o 15 | 16 | run: 17 | ./$(PROGRAM) 18 | 19 | # make clean rule 20 | # delete object and binary files 21 | clean: 22 | find . -name "*.o" -delete 23 | find . -name "*.dSYM" -type d -exec rm -rf {} + 2>/dev/null || true 24 | find . -name "*.exe" -delete 25 | find . -name "*.out" -delete 26 | find . -name "*.pch" -delete 27 | 28 | 29 | doctest: 30 | $(CXX) -std=c++17 -I tests $(TEST_FILES) src/modulo.cpp -o doctest_runner.exe 31 | ./doctest_runner.exe 32 | -------------------------------------------------------------------------------- /labs/loops/shapes/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CXXFLAGS = -c -g -Wall -std=c++17 3 | 4 | PROGRAM = shapes.exe 5 | 6 | # list .cpp files separated by space 7 | SRC = $(wildcard src/*.cpp) 8 | TEST_FILES = $(wildcard tests/*.cpp) 9 | 10 | all: build doctest run clean 11 | 12 | build: 13 | $(CXX) $(CXXFLAGS) $(SRC) 14 | $(CXX) -o $(PROGRAM) *.o 15 | 16 | run: build 17 | ./$(PROGRAM) 18 | 19 | # make clean rule 20 | # delete object and binary files 21 | clean: 22 | find . -name "*.o" -delete 23 | find . -name "*.dSYM" -type d -exec rm -rf {} + 2>/dev/null || true 24 | find . -name "*.exe" -delete 25 | find . -name "*.out" -delete 26 | find . -name "*.pch" -delete 27 | 28 | doctest: 29 | $(CXX) -std=c++17 -I tests $(TEST_FILES) src/shapes.cpp -o doctest_runner.exe 30 | ./doctest_runner.exe 31 | -------------------------------------------------------------------------------- /labs/arrays/numbers/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CXXFLAGS = -c -g -Wall -std=c++17 3 | 4 | PROGRAM = numbers.exe 5 | 6 | # list .cpp files separated by space 7 | SRC = $(wildcard src/*.cpp) 8 | TEST_FILES = $(wildcard tests/*.cpp) 9 | 10 | all: build doctest run clean 11 | 12 | build: 13 | $(CXX) $(CXXFLAGS) $(SRC) 14 | $(CXX) -o $(PROGRAM) *.o 15 | 16 | run: build 17 | ./$(PROGRAM) 18 | 19 | # make clean rule 20 | # delete object and binary files 21 | clean: 22 | find . -name "*.o" -delete 23 | find . -name "*.dSYM" -type d -exec rm -rf {} + 2>/dev/null || true 24 | find . -name "*.exe" -delete 25 | find . -name "*.out" -delete 26 | find . -name "*.pch" -delete 27 | 28 | 29 | doctest: 30 | $(CXX) -std=c++17 -I tests $(TEST_FILES) src/utils.cpp -o doctest_runner.exe 31 | ./doctest_runner.exe 32 | -------------------------------------------------------------------------------- /labs/pointers/pointers/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CXXFLAGS = -c -g -Wall -std=c++17 3 | 4 | PROGRAM = namespace.exe 5 | 6 | # list .cpp files separated by space 7 | SRC = $(wildcard src/*.cpp) 8 | TEST_FILES = $(wildcard tests/*.cpp) 9 | 10 | all: build doctest run clean 11 | 12 | build: 13 | $(CXX) $(CXXFLAGS) $(SRC) 14 | $(CXX) -o $(PROGRAM) *.o 15 | 16 | run: build 17 | ./$(PROGRAM) 18 | 19 | # make clean rule 20 | # delete object and binary files 21 | clean: 22 | find . -name "*.o" -delete 23 | find . -name "*.dSYM" -type d -exec rm -rf {} + 2>/dev/null || true 24 | find . -name "*.exe" -delete 25 | find . -name "*.out" -delete 26 | find . -name "*.pch" -delete 27 | 28 | doctest: 29 | $(CXX) -std=c++17 -I tests $(TEST_FILES) src/utils.cpp -o doctest_runner.exe 30 | ./doctest_runner.exe 31 | -------------------------------------------------------------------------------- /labs/pointers/timeloop/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CXXFLAGS = -c -g -Wall -std=c++17 3 | 4 | PROGRAM = timeloop.exe 5 | 6 | # list .cpp files separated by space 7 | SRC = $(wildcard src/*.cpp) 8 | TEST_FILES = $(wildcard tests/*.cpp) 9 | 10 | all: build doctest run clean 11 | 12 | build: 13 | $(CXX) $(CXXFLAGS) $(SRC) 14 | $(CXX) -o $(PROGRAM) *.o 15 | 16 | run: build 17 | ./$(PROGRAM) 18 | 19 | # make clean rule 20 | # delete object and binary files 21 | clean: 22 | find . -name "*.o" -delete 23 | find . -name "*.dSYM" -type d -exec rm -rf {} + 2>/dev/null || true 24 | find . -name "*.exe" -delete 25 | find . -name "*.out" -delete 26 | find . -name "*.pch" -delete 27 | 28 | doctest: 29 | $(CXX) -std=c++17 -I tests $(TEST_FILES) src/timeloop.cpp -o doctest_runner.exe 30 | ./doctest_runner.exe 31 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CXXFLAGS = -c -g -Wall -std=c++17 3 | 4 | PROGRAM = morsecode.exe 5 | 6 | # list .cpp files separated by space 7 | SRC = $(wildcard src/*.cpp) 8 | TEST_FILES = $(wildcard tests/*.cpp) 9 | 10 | all: build doctest run clean 11 | 12 | build: 13 | $(CXX) $(CXXFLAGS) $(SRC) 14 | $(CXX) -o $(PROGRAM) *.o 15 | 16 | run: build 17 | ./$(PROGRAM) 18 | 19 | # make clean rule 20 | # delete object and binary files 21 | clean: 22 | find . -name "*.o" -delete 23 | find . -name "*.dSYM" -type d -exec rm -rf {} + 2>/dev/null || true 24 | find . -name "*.exe" -delete 25 | find . -name "*.out" -delete 26 | find . -name "*.pch" -delete 27 | 28 | 29 | doctest: 30 | $(CXX) -std=c++17 -I tests $(TEST_FILES) src/morsecode.cpp -o doctest_runner.exe 31 | ./doctest_runner.exe 32 | -------------------------------------------------------------------------------- /labs/unittest/triarea/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CXXFLAGS = -c -g -Wall -std=c++17 3 | 4 | PROGRAM = triangle_area.exe 5 | 6 | # list .cpp files separated by space 7 | SRC = $(wildcard src/*.cpp) 8 | TEST_FILES = $(wildcard tests/*.cpp) 9 | all: build run 10 | 11 | build: 12 | $(CXX) $(CXXFLAGS) $(SRC) 13 | $(CXX) -o $(PROGRAM) *.o 14 | 15 | run: 16 | ./$(PROGRAM) 17 | 18 | # make clean rule 19 | # delete object and binary files 20 | clean: 21 | find . -name "*.o" -delete 22 | find . -name "*.dSYM" -type d -exec rm -rf {} + 2>/dev/null || true 23 | find . -name "*.exe" -delete 24 | find . -name "*.out" -delete 25 | 26 | assert_test: build 27 | ./$(PROGRAM) test 28 | @echo "Assert tests passed!" 29 | 30 | doctest: 31 | $(CXX) -std=c++17 -I tests $(TEST_FILES) src/triarea.cpp -o doctest_runner.exe 32 | ./doctest_runner.exe 33 | -------------------------------------------------------------------------------- /labs/fileio/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CXXFLAGS = -c -g -Wall -std=c++17 3 | 4 | PROGRAM = fileio.exe 5 | 6 | # list .cpp files separated by space 7 | SRC = $(wildcard src/*.cpp) 8 | TEST_FILES = $(wildcard tests/*.cpp) 9 | 10 | all: build doctest run clean 11 | 12 | build: 13 | $(CXX) $(CXXFLAGS) $(SRC) 14 | $(CXX) -o $(PROGRAM) *.o 15 | 16 | run: build 17 | ./$(PROGRAM) 18 | 19 | # make clean rule 20 | # delete object and binary files 21 | clean: 22 | find . -name "*.o" -delete 23 | find . -name "*.dSYM" -type d -exec rm -rf {} + 2>/dev/null || true 24 | find . -name "*.exe" -delete 25 | find . -name "*.out" -delete 26 | find . -name "*.pch" -delete 27 | 28 | assert: build 29 | ./$(PROGRAM) test 30 | 31 | doctest: 32 | $(CXX) -std=c++17 -I tests $(TEST_FILES) src/fileio.cpp -o doctest_runner.exe 33 | ./doctest_runner.exe 34 | -------------------------------------------------------------------------------- /labs/conditionals/menu/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CXXFLAGS = -c -g -Wall -std=c++17 3 | 4 | PROGRAM = menu.exe 5 | 6 | # list .cpp files separated by space 7 | SRC = $(wildcard src/*.cpp) 8 | TEST_FILES = $(wildcard tests/*.cpp) 9 | 10 | all: build doctest run clean 11 | 12 | build: 13 | $(CXX) $(CXXFLAGS) $(SRC) 14 | $(CXX) -o $(PROGRAM) *.o 15 | 16 | run: build 17 | ./$(PROGRAM) 18 | 19 | # make clean rule 20 | # delete object and binary files 21 | clean: 22 | find . -name "*.o" -delete 23 | find . -name "*.dSYM" -type d -exec rm -rf {} + 2>/dev/null || true 24 | find . -name "*.exe" -delete 25 | find . -name "*.out" -delete 26 | find . -name "*.pch" -delete 27 | 28 | assert: build 29 | ./$(PROGRAM) test 30 | 31 | doctest: 32 | $(CXX) -std=c++17 -I tests $(TEST_FILES) src/utils.cpp -o doctest_runner.exe 33 | ./doctest_runner.exe 34 | -------------------------------------------------------------------------------- /labs/conditionals/twostones/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CXXFLAGS = -c -g -Wall -std=c++17 3 | 4 | PROGRAM = twostones.exe 5 | 6 | # list .cpp files separated by space 7 | SRC = $(wildcard src/*.cpp) 8 | TEST_FILES = $(wildcard tests/*.cpp) 9 | 10 | all: build doctest run clean 11 | 12 | build: 13 | $(CXX) $(CXXFLAGS) $(SRC) 14 | $(CXX) -o $(PROGRAM) *.o 15 | 16 | run: build 17 | ./$(PROGRAM) 18 | 19 | # make clean rule 20 | # delete object and binary files 21 | clean: 22 | find . -name "*.o" -delete 23 | find . -name "*.dSYM" -type d -exec rm -rf {} + 2>/dev/null || true 24 | find . -name "*.exe" -delete 25 | find . -name "*.out" -delete 26 | find . -name "*.pch" -delete 27 | 28 | assert: build 29 | ./$(PROGRAM) test 30 | 31 | doctest: 32 | $(CXX) -std=c++17 -I tests $(TEST_FILES) src/twostones.cpp -o doctest_runner.exe 33 | ./doctest_runner.exe 34 | -------------------------------------------------------------------------------- /labs/unittest/points/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # c++ compiler flags 4 | # -g : adds debugging information to the executable file 5 | # -Wall : turns on most, but not all, compiler warnings 6 | # -std=C++17 : uses c++17 standard 7 | # put all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = #FIXME 12 | 13 | # list .cpp files separated by space 14 | CPPFILES = #FIXME 15 | 16 | # make build rule/default rule that'll be run when we run "make" 17 | # first compile each file to object file 18 | # then make a single binary program 19 | all: 20 | $(CXX) $(CXXFLAGS) $(CPPFILES) 21 | $(CXX) -o $(PROGRAM) *.o 22 | 23 | run: 24 | ./$(PROGRAM) 25 | 26 | # make clean rule 27 | # delete object and binary files 28 | clean: 29 | rm -f $(PROGRAM) *.o 30 | -------------------------------------------------------------------------------- /labs/maps/baconeggsandspam/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CXXFLAGS = -c -g -Wall -std=c++17 3 | 4 | PROGRAM = bacon.exe 5 | 6 | # list .cpp files separated by space 7 | SRC = $(wildcard src/*.cpp) 8 | TEST_FILES = $(wildcard tests/*.cpp) 9 | all: build run 10 | 11 | build: 12 | $(CXX) $(CXXFLAGS) $(SRC) 13 | $(CXX) -o $(PROGRAM) *.o 14 | 15 | run: build 16 | ./$(PROGRAM) 17 | 18 | # make clean rule 19 | # delete object and binary files 20 | clean: 21 | find . -name "*.o" -delete 22 | find . -name "*.dSYM" -type d -exec rm -rf {} + 2>/dev/null || true 23 | find . -name "*.exe" -delete 24 | find . -name "*.out" -delete 25 | find . -name "*.pch" -delete 26 | 27 | assert_test: build 28 | ./$(PROGRAM) test 29 | @echo "Assert tests passed!" 30 | 31 | doctest: 32 | $(CXX) -std=c++17 -I tests $(TEST_FILES) src/bacon.cpp -o doctest_runner.exe 33 | ./doctest_runner.exe 34 | -------------------------------------------------------------------------------- /labs/maps/baconeggsandspam/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Map Lab 3 | Kattis problem - https://open.kattis.com/problems/baconeggsandspam 4 | 5 | Updated by: [Your Name Here] 6 | Date: [Today's Date Here] 7 | 8 | Solution to Bacon, Eggs and Spam Problem 9 | Algorithm steps: 10 | 1. Read number of lines to be processed; if 0, end reading 11 | 2. For each line, split the line into words 12 | 3. For each menu item after the first word (which is the customer name), 13 | add the name to the ordered set of names for that item in a map 14 | - note: use ordered map and ordered set to maintain alphabetical order 15 | 4. After reading all lines, print each item and the associated names in alphabetical order 16 | 17 | */ 18 | #include "bacon.h" 19 | 20 | int main(int argc, char *argv[]) 21 | { 22 | // FIXME4 - call the right functions to solve the problem 23 | return 0; 24 | } -------------------------------------------------------------------------------- /labs/math/addtwonumbers/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CXXFLAGS = -c -g -Wall -std=c++17 3 | 4 | PROGRAM = addtwo.exe 5 | 6 | # list .cpp files separated by space 7 | SRC = $(wildcard src/*.cpp) 8 | TEST_FILES = $(wildcard tests/*.cpp) 9 | all: build run 10 | 11 | build: 12 | $(CXX) $(CXXFLAGS) $(SRC) 13 | $(CXX) -o $(PROGRAM) *.o 14 | 15 | run: build 16 | ./$(PROGRAM) 17 | 18 | # make clean rule 19 | # delete object and binary files 20 | clean: 21 | find . -name "*.o" -delete 22 | find . -name "*.dSYM" -type d -exec rm -rf {} + 2>/dev/null || true 23 | find . -name "*.exe" -delete 24 | find . -name "*.out" -delete 25 | find . -name "*.pch" -delete 26 | 27 | assert_test: build 28 | ./$(PROGRAM) test 29 | @echo "Assert tests passed!" 30 | 31 | doctest: 32 | $(CXX) -std=c++17 -I tests $(TEST_FILES) src/addtwo.cpp -o doctest_runner.exe 33 | ./doctest_runner.exe 34 | -------------------------------------------------------------------------------- /labs/math/dfyrirdreki/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CXXFLAGS = -c -g -Wall -std=c++17 3 | 4 | PROGRAM = addtwo.exe 5 | 6 | # list .cpp files separated by space 7 | SRC = $(wildcard src/*.cpp) 8 | TEST_FILES = $(wildcard tests/*.cpp) 9 | all: build run 10 | 11 | build: 12 | $(CXX) $(CXXFLAGS) $(SRC) 13 | $(CXX) -o $(PROGRAM) *.o 14 | 15 | run: build 16 | ./$(PROGRAM) 17 | 18 | # make clean rule 19 | # delete object and binary files 20 | clean: 21 | find . -name "*.o" -delete 22 | find . -name "*.dSYM" -type d -exec rm -rf {} + 2>/dev/null || true 23 | find . -name "*.exe" -delete 24 | find . -name "*.out" -delete 25 | find . -name "*.pch" -delete 26 | 27 | assert_test: build 28 | ./$(PROGRAM) test 29 | @echo "Assert tests passed!" 30 | 31 | doctest: 32 | $(CXX) -std=c++17 -I tests $(TEST_FILES) src/roots.cpp -o doctest_runner.exe 33 | ./doctest_runner.exe 34 | -------------------------------------------------------------------------------- /labs/unittest/mclimbroad/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CXXFLAGS = -c -g -Wall -std=c++17 3 | 4 | PROGRAM = mclimbroad.exe 5 | 6 | # list .cpp files separated by space 7 | SRC = $(wildcard src/*.cpp) 8 | TEST_FILES = $(wildcard tests/*.cpp) 9 | all: build run 10 | 11 | build: 12 | $(CXX) $(CXXFLAGS) $(SRC) 13 | $(CXX) -o $(PROGRAM) *.o 14 | 15 | run: 16 | ./$(PROGRAM) 17 | 18 | # make clean rule 19 | # delete object and binary files 20 | clean: 21 | find . -name "*.o" -delete 22 | find . -name "*.dSYM" -type d -exec rm -rf {} + 2>/dev/null || true 23 | find . -name "*.exe" -delete 24 | find . -name "*.out" -delete 25 | find . -name "*.pch" -delete 26 | 27 | assert_test: build 28 | ./$(PROGRAM) test 29 | @echo "Assert tests passed!" 30 | 31 | doctest: 32 | $(CXX) -std=c++17 -I tests $(TEST_FILES) src/mclimbroad.cpp -o doctest_runner.exe 33 | ./doctest_runner.exe 34 | -------------------------------------------------------------------------------- /notebooks/demos/functions/func_prototype/func_prototype.cpp: -------------------------------------------------------------------------------- 1 | // A C++ program that demonstrates the function prototypes 2 | 3 | #include 4 | using namespace std; 5 | 6 | // function prototypes 7 | // TODO: uncomment these out for the program to compile 8 | //float average(int, int); 9 | //int addInts(int, int); 10 | 11 | int main() { 12 | int n1 = 10; 13 | int n2 = 20; 14 | cout << "average of " << n1 << " and " << n2 << " = " << average(n1, n2); 15 | 16 | return 0; 17 | } 18 | 19 | // function computes and returns average of two integers 20 | float average(int a, int b) { 21 | // average can call addInts, 22 | // eventhough it has not beed defined yet 23 | long sum = addInts(a, b); 24 | return sum/2.0; 25 | } 26 | 27 | // function computes and returns sum of two integers 28 | int addInts(int a, int b) { 29 | return a+b; 30 | } -------------------------------------------------------------------------------- /labs/loops/nostragglers/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CXXFLAGS = -c -g -Wall -std=c++17 3 | 4 | PROGRAM = mclimbroad.exe 5 | 6 | # list .cpp files separated by space 7 | SRC = $(wildcard src/*.cpp) 8 | TEST_FILES = $(wildcard tests/*.cpp) 9 | all: build run 10 | 11 | build: 12 | $(CXX) $(CXXFLAGS) $(SRC) 13 | $(CXX) -o $(PROGRAM) *.o 14 | 15 | run: build 16 | ./$(PROGRAM) 17 | 18 | # make clean rule 19 | # delete object and binary files 20 | clean: 21 | find . -name "*.o" -delete 22 | find . -name "*.dSYM" -type d -exec rm -rf {} + 2>/dev/null || true 23 | find . -name "*.exe" -delete 24 | find . -name "*.out" -delete 25 | find . -name "*.pch" -delete 26 | 27 | assert_test: build 28 | ./$(PROGRAM) test 29 | @echo "Assert tests passed!" 30 | 31 | doctest: 32 | $(CXX) -std=c++17 -I tests $(TEST_FILES) src/nostragglers.cpp -o doctest_runner.exe 33 | ./doctest_runner.exe 34 | -------------------------------------------------------------------------------- /labs/maps/sevenwonders/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CXXFLAGS = -c -g -Wall -std=c++17 3 | 4 | PROGRAM = sevenwonders.exe 5 | 6 | # list .cpp files separated by space 7 | SRC = $(wildcard src/*.cpp) 8 | TEST_FILES = $(wildcard tests/*.cpp) 9 | all: build run 10 | 11 | build: 12 | $(CXX) $(CXXFLAGS) $(SRC) 13 | $(CXX) -o $(PROGRAM) *.o 14 | 15 | run: build 16 | ./$(PROGRAM) 17 | 18 | # make clean rule 19 | # delete object and binary files 20 | clean: 21 | find . -name "*.o" -delete 22 | find . -name "*.dSYM" -type d -exec rm -rf {} + 2>/dev/null || true 23 | find . -name "*.exe" -delete 24 | find . -name "*.out" -delete 25 | find . -name "*.pch" -delete 26 | 27 | assert_test: build 28 | ./$(PROGRAM) test 29 | @echo "Assert tests passed!" 30 | 31 | doctest: 32 | $(CXX) -std=c++17 -I tests $(TEST_FILES) src/sevenwonders.cpp -o doctest_runner.exe 33 | ./doctest_runner.exe 34 | -------------------------------------------------------------------------------- /labs/math/circle/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # g++ compiler flags 4 | # -g: adds debugging information to the executable file 5 | # -Wall: turns on most, but not all, compiler warnings 6 | # -std=c++17: uses c++17 standard 7 | # put all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = #FIXME 12 | 13 | # list .cpp files separated by space 14 | CPPFILES = #FIXME 15 | 16 | # make all rule/default rule that'll be run when we run "make" 17 | # first compile each file to object file 18 | # then make a single binary/executable program 19 | all: 20 | $(CXX) $(CXXFLAGS) $(CPPFILES) 21 | $(CXX) -o $(PROGRAM) *.o 22 | 23 | # make clean rule 24 | # delete object and binary files 25 | clean: 26 | rm -f $(PROGRAM) *.o 27 | 28 | # FIXME 29 | # add a rule to run the program 30 | -------------------------------------------------------------------------------- /labs/namespaces/grafaholur/tests/test_dig.cpp: -------------------------------------------------------------------------------- 1 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 2 | #include "../../../doctest/doctest.h" // FIXME: adjust the path as needed 3 | #include "../src/dig.h" 4 | 5 | TEST_CASE("Testing calculate_rate_per_worker function") 6 | { 7 | SUBCASE("Basic case") 8 | { 9 | int n_workers = 3; 10 | int h_hours = 4; 11 | int x_cubic_meters = 24; 12 | CHECK(dig::calculate_rate_per_worker(n_workers, h_hours, x_cubic_meters) == doctest::Approx(2.0).epsilon(dig::EPSILON)); 13 | } 14 | SUBCASE("Single worker") 15 | { 16 | int n_workers = 1; 17 | int h_hours = 3; 18 | int x_cubic_meters = 8; 19 | CHECK(dig::calculate_rate_per_worker(n_workers, h_hours, x_cubic_meters) == doctest::Approx(2.6).epsilon(dig::EPSILON)); 20 | } 21 | // FIXME4: Add 2 more test cases to cover edge cases 22 | } -------------------------------------------------------------------------------- /labs/stdio/ascii1/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # g++ compiler flags 4 | # -g: adds debugging information to the executable file 5 | # -Wall: turns on most, but not all, compiler warnings 6 | # -std=c++17: uses c++17 standard 7 | # put all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = #FIXME 12 | 13 | # list .cpp files separated by space 14 | CPPFILES = #FIXME 15 | 16 | # make all rule/default rule that'll be run when we run "make" 17 | # first compile each file to object file 18 | # then make a single binary/executable program 19 | all: 20 | $(CXX) $(CXXFLAGS) $(CPPFILES) 21 | $(CXX) -o $(PROGRAM) *.o 22 | 23 | # make clean rule 24 | # delete object and binary files 25 | clean: 26 | rm -f $(PROGRAM) *.o 27 | 28 | # FIXME 29 | # add a rule to run the program 30 | -------------------------------------------------------------------------------- /labs/variables/ascii/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # g++ compiler flags 4 | # -g: adds debugging information to the executable file 5 | # -Wall: turns on most, but not all, compiler warnings 6 | # -std=c++17: uses c++17 standard 7 | # put all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = #FIXME 12 | 13 | # list .cpp files separated by space 14 | CPPFILES = #FIXME 15 | 16 | # make all rule/default rule that'll be run when we run "make" 17 | # first compile each file to object file 18 | # then make a single binary/executable program 19 | all: 20 | $(CXX) $(CXXFLAGS) $(CPPFILES) 21 | $(CXX) -o $(PROGRAM) *.o 22 | 23 | # make clean rule 24 | # delete object and binary files 25 | clean: 26 | rm -f $(PROGRAM) *.o 27 | 28 | # FIXME 29 | # add a rule to run the program 30 | -------------------------------------------------------------------------------- /notebooks/demos/unittest/assert1/unittesting.cpp: -------------------------------------------------------------------------------- 1 | // unittesting fruitful functions 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | // function adds two numbers and returns the sum 8 | int add_func(int num1, int num2) 9 | { 10 | return num1 + num2; 11 | } 12 | 13 | int main() 14 | { 15 | int answer; 16 | int num1, num2; 17 | num1 = 100; 18 | num2 = 1199; 19 | answer = add_func(10, 5); 20 | cout << "answer = " << answer << endl; 21 | assert(answer == 15); 22 | cerr << "first assertion passed\n"; 23 | // directly calling and testing function 24 | assert(add_func(3, 7) == 10); 25 | cerr << "2nd assertion passed\n"; 26 | // write 2 more test cases... 27 | assert(add_func(-10, -5) == -15); 28 | assert(add_func(-5, 5) == 0); 29 | assert(add_func(num1, num2) == 1299); 30 | cerr << "all test cases passed!\n"; 31 | return 0; 32 | } -------------------------------------------------------------------------------- /labs/functions/library/tests/test_my_math.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../src/my_math.h" 5 | using namespace std; 6 | 7 | const float EPSILON = 1e-6; // accuracy upto 6 decimal points 8 | 9 | void test_square_root() 10 | { 11 | float num = 16.0; 12 | float expected = 4.0; 13 | float result = square_root(num); 14 | assert(fabs(result - expected) <= EPSILON); 15 | } 16 | 17 | void test_log_base_2() 18 | { 19 | float num = 1024; 20 | float expected = 10; 21 | float result = log_base_2(num); 22 | assert(fabs(result - expected) <= EPSILON); 23 | } 24 | 25 | int main() 26 | { 27 | cerr << "My Math Library Test Runner" << endl; 28 | test_square_root(); 29 | test_log_base_2(); 30 | // FIXME1: call the rest of the test functions 31 | cerr << "All test cases passed!" << endl; 32 | return 0; 33 | } -------------------------------------------------------------------------------- /labs/namespaces/grafaholur/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CXXFLAGS = -c -g -Wall -std=c++17 3 | 4 | PROGRAM = namespace.exe 5 | 6 | # list .cpp files separated by space 7 | SRC = $(wildcard src/*.cpp) 8 | TEST_FILES = $(wildcard tests/*.cpp) 9 | 10 | all: build doctest run clean 11 | 12 | build: 13 | $(CXX) $(CXXFLAGS) $(SRC) 14 | $(CXX) -o $(PROGRAM) *.o 15 | 16 | run: build 17 | ./$(PROGRAM) 18 | 19 | # make clean rule 20 | # delete object and binary files 21 | clean: 22 | find . -name "*.o" -delete 23 | find . -name "*.dSYM" -type d -exec rm -rf {} + 2>/dev/null || true 24 | find . -name "*.exe" -delete 25 | find . -name "*.out" -delete 26 | find . -name "*.pch" -delete 27 | 28 | assert_test: build 29 | ./$(PROGRAM) test 30 | @echo "Assert tests passed!" 31 | 32 | doctest: 33 | $(CXX) -std=c++17 -I tests $(TEST_FILES) src/dig.cpp -o doctest_runner.exe 34 | ./doctest_runner.exe 35 | -------------------------------------------------------------------------------- /labs/namespaces/namespace/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CXXFLAGS = -c -g -Wall -std=c++17 3 | 4 | PROGRAM = namespace.exe 5 | 6 | # list .cpp files separated by space 7 | SRC = $(wildcard src/*.cpp) 8 | TEST_FILES = $(wildcard tests/*.cpp) 9 | 10 | all: build doctest run clean 11 | 12 | build: 13 | $(CXX) $(CXXFLAGS) $(SRC) 14 | $(CXX) -o $(PROGRAM) *.o 15 | 16 | run: build 17 | ./$(PROGRAM) 18 | 19 | # make clean rule 20 | # delete object and binary files 21 | clean: 22 | find . -name "*.o" -delete 23 | find . -name "*.dSYM" -type d -exec rm -rf {} + 2>/dev/null || true 24 | find . -name "*.exe" -delete 25 | find . -name "*.out" -delete 26 | find . -name "*.pch" -delete 27 | 28 | assert_test: build 29 | ./$(PROGRAM) test 30 | @echo "Assert tests passed!" 31 | 32 | doctest: 33 | $(CXX) -std=c++17 -I tests $(TEST_FILES) src/utils.cpp -o doctest_runner.exe 34 | ./doctest_runner.exe 35 | -------------------------------------------------------------------------------- /labs/strings/palindrome/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # g++ compiler flags 4 | # -g: adds debugging information to the executable file 5 | # -Wall: turns on most, but not all, compiler warnings 6 | # -std=c++17: uses c++17 standard 7 | # put all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = #FIXME 12 | 13 | # list .cpp files separated by space 14 | CPPFILES = #FIXME 15 | 16 | # make all rule/default rule that'll be run when we run "make" 17 | # first compile each file to object file 18 | # then make a single binary/executable program 19 | all: 20 | $(CXX) $(CXXFLAGS) $(CPPFILES) 21 | $(CXX) -o $(PROGRAM) *.o 22 | 23 | # make clean rule 24 | # delete object and binary files 25 | clean: 26 | rm -f $(PROGRAM) *.o 27 | 28 | # FIXME 29 | # add a rule to run the program 30 | -------------------------------------------------------------------------------- /labs/unittest/triarea/tests/test_triarea.cpp: -------------------------------------------------------------------------------- 1 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 2 | #include "../../../doctest/doctest.h" // FIXME: adjust the path as needed 3 | #include "../src/triarea.h" 4 | 5 | TEST_CASE("Testing area_of_triangle function") 6 | { 7 | SUBCASE("Test Case 1") 8 | { 9 | unsigned height = 10; 10 | unsigned base = 5; 11 | float expected = 25.0; 12 | float result = area_of_triangle(height, base); 13 | CHECK(result == doctest::Approx(expected).epsilon(MAX_ERROR)); 14 | } 15 | SUBCASE("Test Case 2") 16 | { 17 | unsigned height = 6; 18 | unsigned base = 4; 19 | float expected = 12.0; 20 | float result = area_of_triangle(height, base); 21 | CHECK(result == doctest::Approx(expected).epsilon(MAX_ERROR)); 22 | } 23 | } 24 | 25 | // FIXME3: Write 2nd test case with atleate 2 subcases -------------------------------------------------------------------------------- /notebooks/demos/library/printf/printf_demo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Program to demonstrate printf function 3 | */ 4 | 5 | #include 6 | 7 | using namespace std; 8 | 9 | int main() { 10 | // format printf( ) demo 11 | printf("Printing integer numbers: %d %u %i\n", -100, 85, -999); 12 | printf("Printing characters:\tc %c\n", 65); 13 | printf("Printing c-string: %s\n", "Hello World"); 14 | printf("Printing floating points: %.2f\n", 1.99999); // round it to 2 decimal points 15 | 16 | printf("\n\n"); 17 | printf("Printing Hexadecimal: %x %X %#x %#X\n", 10, 10, 10, 10); 18 | printf("Printing Octal: %o %#o\n", 10, 10); 19 | printf("Printing Scientific: %e %E\n", 1.5, 1.5); 20 | 21 | printf("\n\n"); 22 | printf("Column Width & Right Justification: '%10s'\n", "Hi"); 23 | printf("Column Width & Left Justification: '%-10s'\n", "Hi"); 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /notebooks/demos/header_files/header/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # c++ compiler flags 4 | # -g : adds debugging information to the executable file 5 | # -Wall : turns on most, but not all, compiler warnings 6 | # -std=C++17 : uses c++17 standard 7 | # put all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = demo.exe 12 | 13 | # list .cpp files separated by space 14 | CPPFILES = main.cpp utility.cpp 15 | 16 | # make build rule/default rule that'll be run when we run "make" 17 | # first compile each file to object file 18 | # then make a single binary program 19 | build: 20 | $(CXX) $(CXXFLAGS) $(CPPFILES) 21 | $(CXX) -o $(PROGRAM) *.o 22 | 23 | run: 24 | ./$(PROGRAM) 25 | 26 | # make clean rule 27 | # delete object and binary files 28 | clean: 29 | rm -f $(PROGRAM) *.o 30 | -------------------------------------------------------------------------------- /exercises/stdio/BMI/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | 4 | # c++ compiler flags 5 | # -c : just do preprocess; compile and assemble into object files 6 | # -g : adds debugging information to the executable file 7 | # -Wall : turns on most, but not all, compiler warnings 8 | # -std=c++17 : uses c++17 standard 9 | # put all the required flags separated by space 10 | CXXFLAGS = -c -g -Wall -std=c++17 11 | 12 | # the build target executable file; .exe is not required 13 | PROGRAM = BMI.exe 14 | 15 | # list all .cpp files separated by space 16 | CPPFILES = main.cpp 17 | 18 | # make all rule/default rule that'll be run when we run "make" 19 | # first compile each file to object file 20 | # then make a single binary program 21 | all: 22 | $(CXX) $(CXXFLAGS) $(CPPFILES) 23 | $(CXX) -o $(PROGRAM) *.o 24 | 25 | # make clean rule 26 | # delete object and binary files 27 | clean: 28 | rm -f $(PROGRAM) *.o -------------------------------------------------------------------------------- /labs/fileio/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | CS1 - File IO Lab 3 | 4 | Updated by: [Your Name] 5 | Date: [Current Date] 6 | 7 | The program reads numbers from a file and finds statistical values from those numbers. 8 | Lab demonstrates the file io and vector application. 9 | Statistical value's definitions for mean, median, mode, etc. can be found here: 10 | https://www.purplemath.com/modules/meanmode.htm 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include "fileio.h" 17 | 18 | using namespace std; 19 | 20 | int main(int argc, char *argv[]) 21 | { 22 | vector numbers; 23 | string input_file; 24 | cout << "Enter input file name: "; 25 | getline(cin, input_file); 26 | read_data(numbers, input_file); 27 | write_data(numbers); 28 | cout << "All done. Enter to exit..."; 29 | cin.get(); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /notebooks/demos/arrays/buffer_overflow1/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # c++ compiler flags 4 | # -g : adds debugging information to the executable file 5 | # -Wall : turns on most, but not all, compiler warnings 6 | # -std=C++17 : uses c++17 standard 7 | # put all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = overflow.exe 12 | 13 | # list .cpp files separated by space 14 | CPPFILES = buffer_overflow1.cpp 15 | 16 | # make build rule/default rule that'll be run when we run "make" 17 | # first compile each file to object file 18 | # then make a single binary program 19 | build: 20 | $(CXX) $(CXXFLAGS) $(CPPFILES) 21 | $(CXX) -o $(PROGRAM) *.o 22 | 23 | run: 24 | ./$(PROGRAM) 25 | 26 | # make clean rule 27 | # delete object and binary files 28 | clean: 29 | rm -f $(PROGRAM) *.o 30 | -------------------------------------------------------------------------------- /exercises/intro/helloworld/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | 4 | # c++ compiler flags 5 | # -c : just do preprocess; compile and assemble into object files 6 | # -g : adds debugging information to the executable file 7 | # -Wall : turns on most, but not all, compiler warnings 8 | # -std=c++17 : uses c++17 standard 9 | # put all the required flags separated by space 10 | CXXFLAGS = -c -g -Wall -std=c++17 11 | 12 | # the build target executable file; .exe is not required 13 | PROGRAM = hangman.exe 14 | 15 | # list all .cpp files separated by space 16 | CPPFILES = main.cpp 17 | 18 | # make all rule/default rule that'll be run when we run "make" 19 | # first compile each file to object file 20 | # then make a single binary program 21 | all: 22 | $(CXX) $(CXXFLAGS) $(CPPFILES) 23 | $(CXX) -o $(PROGRAM) *.o 24 | 25 | # make clean rule 26 | # delete object and binary files 27 | clean: 28 | rm -f $(PROGRAM) *.o -------------------------------------------------------------------------------- /labs/maps/sevenwonders/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Map Lab 3 | Kattis - Seven Wonders 4 | 5 | Updated By: [Your Name Here] 6 | Date: [Today's Date Here] 7 | 8 | The solution to the Seven Wonders Problem: https://open.kattis.com/problems/sevenwonders 9 | Algorithm steps: 10 | 1. Read cards into a string variable 11 | 2. use unordered_map to keep track of count of each card played 12 | - update map: for each card, update its count 13 | 3. find regular points following the instruction 14 | - points = sum of (each card_count)^2 15 | 4. add bonus points if any 16 | - find # of sets of three cards and multiply it by 7 17 | */ 18 | 19 | #include 20 | #include "sevenwonders.h" 21 | using namespace std; 22 | 23 | int main() 24 | { 25 | ios_base::sync_with_stdio(false); 26 | cin.tie(NULL); 27 | 28 | // FIXME0: Call the correct function to solve the problem 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /labs/math/addtwonumbers/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Lab: Basic Math 3 | 4 | Updated By: [Your Name] 5 | Date: [Today's Date] 6 | CSCI 111 - Foundations of Computer Science 7 | Instructor: [Instructor's Name] 8 | 9 | Read and Solve Add Two Numbers: https://open.kattis.com/problems/addtwonumbers 10 | 11 | Algorithm steps: 12 | 1. Read two numbers 13 | 2. Add them up and print the result using function 14 | */ 15 | 16 | #include 17 | #include "addtwo.h" 18 | 19 | using namespace std; 20 | 21 | int main() 22 | { 23 | ios_base::sync_with_stdio(false); 24 | cin.tie(NULL); 25 | 26 | // Your solution here 27 | // declare variables to store input data and answer 28 | int a, b, ans; 29 | cin >> a; 30 | // FIXME1: Read the 2nd number 31 | // FIXME2: add two numbers using function and store the result into ans variable 32 | // FIXME3: print the answer 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /exercises/library/rectangle/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | 4 | # c++ compiler flags 5 | # -c : just do preprocess; compile and assemble into object files 6 | # -g : adds debugging information to the executable file 7 | # -Wall : turns on most, but not all, compiler warnings 8 | # -std=c++17 : uses c++17 standard 9 | # put all the required flags separated by space 10 | CXXFLAGS = -c -g -Wall -std=c++17 11 | 12 | # the build target executable file; .exe is not required 13 | PROGRAM = rectangle.exe 14 | 15 | # list all .cpp files separated by space 16 | CPPFILES = main.cpp 17 | 18 | # make all rule/default rule that'll be run when we run "make" 19 | # first compile each file to object file 20 | # then make a single binary program 21 | all: 22 | $(CXX) $(CXXFLAGS) $(CPPFILES) 23 | $(CXX) -o $(PROGRAM) *.o 24 | 25 | # make clean rule 26 | # delete object and binary files 27 | clean: 28 | rm -f $(PROGRAM) *.o -------------------------------------------------------------------------------- /notebooks/demos/loops/rectangle/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | 4 | # c++ compiler flags 5 | # -c : just do preprocess; compile and assemble into object files 6 | # -g: adds debugging information to the executable file 7 | # - Wall turns on most, but not all, compiler warnings 8 | # -std=c++17 uses c++17 standard 9 | # put all the required flags separated by space 10 | CXXFLAGS = -c -g -Wall -std=c++17 11 | 12 | # the build target executable file; .exe is not required 13 | PROGRAM = rectangle.exe 14 | 15 | # list all .cpp files separated by space 16 | CPPFILES = main.cpp 17 | 18 | # make all rule/default rule that'll be run when we run "make" 19 | # first compile each file to object file 20 | # then make a single binary program 21 | all: 22 | $(CXX) $(CXXFLAGS) $(CPPFILES) 23 | $(CXX) -o $(PROGRAM) *.o 24 | 25 | # make clean rule 26 | # delete object and binary files 27 | clean: 28 | rm -f $(PROGRAM) *.o -------------------------------------------------------------------------------- /notebooks/demos/pointers/rectangle/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | 4 | # c++ compiler flags 5 | # -c : just do preprocess; compile and assemble into object files 6 | # -g: adds debugging information to the executable file 7 | # - Wall turns on most, but not all, compiler warnings 8 | # -std=c++17 uses c++17 standard 9 | # put all the required flags separated by space 10 | CXXFLAGS = -c -g -Wall -std=c++17 11 | 12 | # the build target executable file; .exe is not required 13 | PROGRAM = rectangle.exe 14 | 15 | # list all .cpp files separated by space 16 | CPPFILES = main.cpp 17 | 18 | # make all rule/default rule that'll be run when we run "make" 19 | # first compile each file to object file 20 | # then make a single binary program 21 | all: 22 | $(CXX) $(CXXFLAGS) $(CPPFILES) 23 | $(CXX) -o $(PROGRAM) *.o 24 | 25 | # make clean rule 26 | # delete object and binary files 27 | clean: 28 | rm -f $(PROGRAM) *.o -------------------------------------------------------------------------------- /labs/unittest/triarea/src/triarea.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "triarea.h" 4 | 5 | using namespace std; 6 | 7 | // Function implementation 8 | float area_of_triangle(const unsigned height, const unsigned base) 9 | { 10 | float area = 0; 11 | // FIXME2: Find the area of traingle using the formular given in algorithm step: 2.a 12 | // store the area into area variable 13 | return area; 14 | } 15 | 16 | // function to test area function 17 | void test_area_with_assert() 18 | { 19 | unsigned height, base; 20 | float answer, expected; 21 | height = 10; 22 | base = 5; 23 | answer = area_of_triangle(height, base); 24 | expected = 25.0; 25 | assert(abs(answer - expected) < MAX_ERROR); 26 | // FIXME3: Write 2nd test case 27 | // FIXME4: Write 3rd test case 28 | // FIXME5: Write 4th test case 29 | cerr << "All test cases passed!\n"; 30 | } 31 | -------------------------------------------------------------------------------- /notebooks/demos/conditionals/rectangle/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | 4 | # c++ compiler flags 5 | # -c : just do preprocess; compile and assemble into object files 6 | # -g: adds debugging information to the executable file 7 | # - Wall turns on most, but not all, compiler warnings 8 | # -std=c++17 uses c++17 standard 9 | # put all the required flags separated by space 10 | CXXFLAGS = -c -g -Wall -std=c++17 11 | 12 | # the build target executable file; .exe is not required 13 | PROGRAM = rectangle.exe 14 | 15 | # list all .cpp files separated by space 16 | CPPFILES = main.cpp 17 | 18 | # make all rule/default rule that'll be run when we run "make" 19 | # first compile each file to object file 20 | # then make a single binary program 21 | all: 22 | $(CXX) $(CXXFLAGS) $(CPPFILES) 23 | $(CXX) -o $(PROGRAM) *.o 24 | 25 | # make clean rule 26 | # delete object and binary files 27 | clean: 28 | rm -f $(PROGRAM) *.o -------------------------------------------------------------------------------- /notebooks/demos/loops/countdown/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | 4 | # c++ compiler flags 5 | # -c : just do preprocess; compile and assemble into object files 6 | # -g: adds debugging information to the executable file 7 | # -Wall turns on most, but not all, compiler warnings 8 | # -std=c++17 uses c++17 standard 9 | # put all the required flags separated by space 10 | CXXFLAGS = -c -g -Wall -std=c++17 11 | 12 | # the build target executable file; .exe is not required 13 | PROGRAM = countdown.exe 14 | 15 | # list all .cpp files separated by space 16 | CPPFILES = countdown.cpp 17 | 18 | # make all rule/default rule that'll be run when we run "make" 19 | # first compile each file to object file 20 | # then make a single binary program 21 | all: 22 | $(CXX) $(CXXFLAGS) $(CPPFILES) 23 | $(CXX) -o $(PROGRAM) *.o 24 | 25 | # make clean rule 26 | # delete object and binary files 27 | clean: 28 | rm -f $(PROGRAM) *.o -------------------------------------------------------------------------------- /notebooks/demos/header_files/triangle/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # c++ compiler flags 4 | # -g : adds debugging information to the executable file 5 | # -Wall : turns on most, but not all, compiler warnings 6 | # -std=C++17 : uses c++17 standard 7 | # put all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = triangle.exe 12 | 13 | # list .cpp files separated by space 14 | CPPFILES = main.cpp utility.cpp triangle.cpp test.cpp 15 | 16 | # make build rule/default rule that'll be run when we run "make" 17 | # first compile each file to object file 18 | # then make a single binary program 19 | build: 20 | $(CXX) $(CXXFLAGS) $(CPPFILES) 21 | $(CXX) -o $(PROGRAM) *.o 22 | 23 | run: 24 | ./$(PROGRAM) 25 | 26 | # make clean rule 27 | # delete object and binary files 28 | clean: 29 | rm -f $(PROGRAM) *.o 30 | -------------------------------------------------------------------------------- /notebooks/demos/file_io/triangle/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # c++ compiler flags 4 | # -g : adds debugging information to the executable file 5 | # -Wall : turns on most, but not all, compiler warnings 6 | # -std=C++17 : uses c++17 standard 7 | # put all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = triangle.exe 12 | 13 | # list .cpp files separated by space 14 | CPPFILES = triangle.cpp 15 | 16 | # make build rule/default rule that'll be run when we run "make" 17 | # first compile each file to object file 18 | # then make a single binary program 19 | build: 20 | $(CXX) $(CXXFLAGS) $(CPPFILES) 21 | $(CXX) -o $(PROGRAM) *.o 22 | 23 | test: 24 | ./$(PROGRAM) test 25 | 26 | run: 27 | ./$(PROGRAM) 28 | 29 | # make clean rule 30 | # delete object and binary files 31 | clean: 32 | rm -f $(PROGRAM) *.o 33 | -------------------------------------------------------------------------------- /notebooks/demos/structs/triangle/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # c++ compiler flags 4 | # -g : adds debugging information to the executable file 5 | # -Wall : turns on most, but not all, compiler warnings 6 | # -std=C++17 : uses c++17 standard 7 | # put all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = triangle.exe 12 | 13 | # list .cpp files separated by space 14 | CPPFILES = triangle.cpp 15 | 16 | # make build rule/default rule that'll be run when we run "make" 17 | # first compile each file to object file 18 | # then make a single binary program 19 | build: 20 | $(CXX) $(CXXFLAGS) $(CPPFILES) 21 | $(CXX) -o $(PROGRAM) *.o 22 | 23 | test: 24 | ./$(PROGRAM) test 25 | 26 | run: 27 | ./$(PROGRAM) 28 | 29 | # make clean rule 30 | # delete object and binary files 31 | clean: 32 | rm -f $(PROGRAM) *.o 33 | -------------------------------------------------------------------------------- /notebooks/demos/vectors/triangle/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # c++ compiler flags 4 | # -g : adds debugging information to the executable file 5 | # -Wall : turns on most, but not all, compiler warnings 6 | # -std=C++17 : uses c++17 standard 7 | # put all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = triangle.exe 12 | 13 | # list .cpp files separated by space 14 | CPPFILES = triangle.cpp 15 | 16 | # make build rule/default rule that'll be run when we run "make" 17 | # first compile each file to object file 18 | # then make a single binary program 19 | build: 20 | $(CXX) $(CXXFLAGS) $(CPPFILES) 21 | $(CXX) -o $(PROGRAM) *.o 22 | 23 | test: 24 | ./$(PROGRAM) test 25 | 26 | run: 27 | ./$(PROGRAM) 28 | 29 | # make clean rule 30 | # delete object and binary files 31 | clean: 32 | rm -f $(PROGRAM) *.o 33 | 34 | -------------------------------------------------------------------------------- /notebooks/demos/maps/letter_frequency/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # c++ compiler flags 4 | # -g : adds debugging information to the executable file 5 | # -Wall : turns on most, but not all, compiler warnings 6 | # -std=C++17 : uses c++17 standard 7 | # put all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = let_frequency.exe 12 | 13 | # list .cpp files separated by space 14 | CPPFILES = main.cpp 15 | 16 | # make build rule/default rule that'll be run when we run "make" 17 | # first compile each file to object file 18 | # then make a single binary program 19 | build: 20 | $(CXX) $(CXXFLAGS) $(CPPFILES) 21 | $(CXX) -o $(PROGRAM) *.o 22 | 23 | run: 24 | ./$(PROGRAM) 25 | 26 | test: 27 | ./$(PROGRAM) test 28 | 29 | # make clean rule 30 | # delete object and binary files 31 | clean: 32 | rm -f $(PROGRAM) *.o 33 | 34 | -------------------------------------------------------------------------------- /notebooks/demos/vectors/splitString/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # c++ compiler flags 4 | # -g : adds debugging information to the executable file 5 | # -Wall : turns on most, but not all, compiler warnings 6 | # -std=C++17 : uses c++17 standard 7 | # put all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = splitString.exe 12 | 13 | # list .cpp files separated by space 14 | CPPFILES = splitString.cpp 15 | 16 | # make build rule/default rule that'll be run when we run "make" 17 | # first compile each file to object file 18 | # then make a single binary program 19 | build: 20 | $(CXX) $(CXXFLAGS) $(CPPFILES) 21 | $(CXX) -o $(PROGRAM) *.o 22 | 23 | test: 24 | ./$(PROGRAM) test 25 | 26 | run: 27 | ./$(PROGRAM) 28 | 29 | # make clean rule 30 | # delete object and binary files 31 | clean: 32 | rm -f $(PROGRAM) *.o 33 | -------------------------------------------------------------------------------- /notebooks/demos/unittest/assert/assertdebug.cpp: -------------------------------------------------------------------------------- 1 | // a program to demonstrate assert statement 2 | // demonstrates debugging and unittesting concept 3 | // TODO: compile and run the program redirecting the output to a text file 4 | // a.out > output.txt 5 | 6 | #include 7 | // uncomment to disable assert() 8 | // #define NDEBUG 9 | #include 10 | using namespace std; 11 | 12 | int main() 13 | { 14 | assert(2 + 2 == 4); 15 | // output to stdout stream; 16 | // can redirect the result to a output.txt file 17 | cout << "2+2 equals to 4 is true!\n"; 18 | // output to stderr stream; still see the output on console 19 | // can't redirect the cerr output 20 | cerr << "Execution continues past the first assert\n"; 21 | assert(2 + 3 == 4); 22 | cerr << "Execution continues past the second assert\n"; 23 | assert(3 % 2 == 1); 24 | cerr << "Yet another assert message\n"; 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /labs/stdio/ascii/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # g++ compiler flags 4 | # -c: compile only, do not link 5 | # -g: adds debugging information to the executable file 6 | # -Wall: turns on most, but not all, compiler warnings 7 | # -std=c++17: uses c++17 standard 8 | # put all the required flags separated by space 9 | CXXFLAGS = -c -g -Wall -std=c++17 10 | 11 | # the build target executable file; .exe is not required 12 | PROGRAM = stdio.exe #FIXME 13 | 14 | # list .cpp files separated by space 15 | CPPFILES = main.cpp util.cpp #FIXME 16 | 17 | # make all rule/default rule that'll be run when we run "make" 18 | # first compile each file to object file 19 | # then make a single binary/executable program 20 | all: 21 | $(CXX) $(CXXFLAGS) $(CPPFILES) 22 | $(CXX) -o $(PROGRAM) *.o 23 | 24 | # make clean rule 25 | # delete object and binary files 26 | clean: 27 | rm -f $(PROGRAM) *.o 28 | 29 | # FIXME 30 | # add a rule to run the program 31 | -------------------------------------------------------------------------------- /labs/conditionals/twostones/src/twostones.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | string odd_or_even(const int unsigned number) 7 | { 8 | // FIXME4: if the number divided by 2 has 0 remainder, return 'even' 9 | // otherwise, return 'odd' 10 | return "odd"; 11 | } 12 | 13 | string answer(const int unsigned stone) 14 | { 15 | string evenorodd = odd_or_even(stone); 16 | if (evenorodd == "odd") 17 | return "Alice"; 18 | else 19 | return "Bob"; 20 | } 21 | 22 | void test_odd_or_even() 23 | { 24 | int unsigned number; 25 | number = 99999; 26 | assert(odd_or_even(number) == "odd"); 27 | // FIXME5: Write 2nd test case 28 | // FIXME6: Write 3rd test case 29 | cerr << "All test cases passed for odd_or_even() !\n"; 30 | } 31 | 32 | // FIXME7: Write a function to test answer function using assert function 33 | // Write at least 3 test cases 34 | -------------------------------------------------------------------------------- /labs/math/dfyrirdreki/tests/test_roots.cpp: -------------------------------------------------------------------------------- 1 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 2 | #include "../../../doctest/doctest.h" // FIXME: adjust the path as needed 3 | #include "../src/roots.h" 4 | 5 | TEST_CASE("Testing find_discriminant function") 6 | { 7 | SUBCASE("Discriminant is positive") 8 | { 9 | CHECK(find_discriminant(1, 5, 6) == 1); // 5^2 - 4*1*6 = 25 - 24 = 1 10 | } 11 | SUBCASE("Discriminant is zero") 12 | { 13 | CHECK(find_discriminant(1, 2, 1) == 0); // 2^2 - 4*1*1 = 4 - 4 = 0 14 | } 15 | // FIXME4: Add 6 more test cases to cover edge cases 16 | } 17 | 18 | TEST_CASE("Testing find_roots function") 19 | { 20 | SUBCASE("No real roots when discriminant is negative") 21 | { 22 | CHECK(find_roots(-1) == 0); 23 | } 24 | SUBCASE("One real root when discriminant is zero") 25 | { 26 | CHECK(find_roots(0) == 1); 27 | } 28 | // FIXME5: Add 3 more test cases to cover edge cases 29 | } -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | container: 3 | build: 4 | context: ./ # Use the current directory as the build context 5 | dockerfile: Dockerfile 6 | image: ${IMAGE_NAME} 7 | hostname: ${CONTAINER_NAME} 8 | container_name: ${CONTAINER_NAME} 9 | environment: 10 | - REPO_NAME=${REPO_NAME} 11 | working_dir: /home/user/${REPO_NAME} 12 | volumes: 13 | - ./:/home/user/${REPO_NAME} 14 | - ${HOME}/.gitconfig:/home/user/.gitconfig 15 | - ${HOME}/.ssh:/home/user/.ssh 16 | - ${HOME}/.zsh_history:/home/user/.zsh_history 17 | - ${HOME}/.kattisrc:/home/user/.kattisrc 18 | cap_add: 19 | - ALL 20 | privileged: true # Grant full privileges to the container 21 | ports: 22 | - 8888:8888 23 | command: 24 | [ 25 | "bash", 26 | "-c", 27 | "sudo chown user --recursive /home/user && tail -f /dev/null", 28 | ] 29 | 30 | networks: 31 | default: 32 | driver: bridge 33 | -------------------------------------------------------------------------------- /labs/vectors/numSystem/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # g++ compiler flags 4 | # -g: adds debugging information to the executable file 5 | # -Wall: turns on most, but not all, compiler warnings 6 | # -std=c++17: uses c++17 standard 7 | # add all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = numberSystem.exe #FIXME1 12 | 13 | # list .cpp files separated by space 14 | CPPFILES = numberSystem.cpp #FIXME2 15 | 16 | # make all rule/default rule that'll be run when we run "make" 17 | # first compile each file to object file 18 | # then make a single binary/executable program 19 | build: 20 | $(CXX) $(CXXFLAGS) $(CPPFILES) 21 | $(CXX) -o $(PROGRAM) *.o 22 | 23 | # make clean rule 24 | # delete object and binary files 25 | clean: 26 | rm -f $(PROGRAM) *.o 27 | 28 | # FIXME 29 | # add a rule to run the program 30 | 31 | all: build run clean 32 | @echo "All done..." 33 | -------------------------------------------------------------------------------- /notebooks/demos/classes/points/tests/test_point.cpp: -------------------------------------------------------------------------------- 1 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 2 | #include "../../../../doctest/doctest.hpp" 3 | #include "../src/point.hpp" 4 | 5 | TEST_CASE("Testing Point class functionality") 6 | { 7 | Point p1(3.0, 4.0); 8 | Point p2(1.0, 2.0); 9 | 10 | SUBCASE("Test distance from origin") 11 | { 12 | CHECK(p1.distance_from_origin() == doctest::Approx(5.0)); 13 | CHECK(p2.distance_from_origin() == doctest::Approx(sqrt(5.0))); 14 | } 15 | 16 | SUBCASE("Test point addition") 17 | { 18 | Point p3 = p1 + p2; 19 | CHECK(p3 == Point(4.0, 6.0)); 20 | } 21 | 22 | SUBCASE("Test point equality") 23 | { 24 | Point p4(3.0, 4.0); 25 | CHECK(p1 == p4); 26 | CHECK_FALSE(p1 == p2); 27 | } 28 | 29 | SUBCASE("Test output stream operator") 30 | { 31 | std::ostringstream os; 32 | os << p1; 33 | CHECK(os.str() == "(3, 4)"); 34 | } 35 | } -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/src/morsecode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | // Algorithm step 1 8 | const unordered_map morse_code = { 9 | {'A', ".-"}, 10 | {'B', "-..."}, 11 | {'C', "-.-."}, 12 | {'D', "-.."}, 13 | {'E', "."}, 14 | {'F', "..-."}, 15 | {'G', "--."}, 16 | {'H', "...."}, 17 | {'I', ".."}, 18 | {'J', ".---"}, 19 | {'K', "-.-"}, 20 | {'L', ".-.."}, 21 | {'M', "--"}, 22 | {'N', "-."}, 23 | {'O', "---"}, 24 | {'P', ".--."}, 25 | {'Q', "--.-"}, 26 | {'R', ".-."}, 27 | {'S', "..."}, 28 | {'T', "-"}, 29 | {'U', "..-"}, 30 | {'V', "...-"}, 31 | {'W', ".--"}, 32 | {'X', "-..-"}, 33 | {'Y', "-.--"}, 34 | {'Z', "--.."}, 35 | // FIXME0 - add number mappings 36 | }; 37 | 38 | // function prototypes 39 | string convert_to_morse(const string &); 40 | bool is_palindrome(const string &); 41 | void solve(); -------------------------------------------------------------------------------- /notebooks/demos/arrays/overflow_fixed/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # c++ compiler flags 4 | # -g : adds debugging information to the executable file 5 | # -Wall : turns on most, but not all, compiler warnings 6 | # -std=C++17 : uses c++17 standard 7 | # -fno-stack-protector : compilers provide way to detect stack-overflow; so disable it if required! 8 | # put all the required flags separated by space 9 | CXXFLAGS = -c -g -Wall -std=c++17 10 | 11 | # the build target executable file; .exe is not required 12 | PROGRAM = authenticator.exe 13 | 14 | # list .cpp files separated by space 15 | CPPFILES = overflow_fixed.cpp 16 | 17 | # make build rule/default rule that'll be run when we run "make" 18 | # first compile each file to object file 19 | # then make a single binary program 20 | build: 21 | $(CXX) $(CXXFLAGS) $(CPPFILES) 22 | $(CXX) -o $(PROGRAM) *.o 23 | 24 | run: 25 | $(PROGRAM) 26 | 27 | # make clean rule 28 | # delete object and binary files 29 | clean: 30 | rm -f $(PROGRAM) *.o 31 | -------------------------------------------------------------------------------- /notebooks/demos/stdio/demo1/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # c++ compiler flags 4 | # -g : adds debugging information to the executable file 5 | # -Wall : turns on most, but not all, compiler warnings 6 | # -std=C++17 : uses c++17 standard 7 | # put all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = stdio.exe 12 | 13 | # list all .cpp file(s) separated by space 14 | CPPFILES = main.cpp 15 | 16 | # make all rule or the default rule that'll be run when we run "make" 17 | # first compile each file to object file 18 | # then make a single binary program 19 | all: 20 | $(CXX) $(CXXFLAGS) $(CPPFILES) # compile each file to object file 21 | $(CXX) -o $(PROGRAM) *.o # build the binary program using object file(s) 22 | # ./$(PROGRAM) # run the program if successfully built 23 | 24 | # make clean rule 25 | # delete object and binary files 26 | clean: 27 | rm -f $(PROGRAM) *.o 28 | 29 | run: 30 | ./$(PROGRAM) -------------------------------------------------------------------------------- /exercises/variables/exercise1/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # c++ compiler flags 4 | # -g : adds debugging information to the executable file 5 | # -Wall : turns on most, but not all, compiler warnings 6 | # -std=C++17 : uses c++17 standard 7 | # put all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = exercise1.exe 12 | 13 | # list all .cpp file(s) separated by space 14 | CPPFILES = main.cpp 15 | 16 | # make all rule or the default rule that'll be run when we run "make" 17 | # first compile each file to object file 18 | # then make a single binary program 19 | all: 20 | $(CXX) $(CXXFLAGS) $(CPPFILES) # compile each file to object file 21 | $(CXX) -o $(PROGRAM) *.o # build the binary program using object file(s) 22 | # ./$(PROGRAM) # uncomment it if you want to run the program if successfully built 23 | 24 | # make clean rule 25 | # delete object and binary files 26 | clean: 27 | rm -f $(PROGRAM) *.o 28 | -------------------------------------------------------------------------------- /notebooks/demos/stdio/decToBin/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # c++ compiler flags 4 | # -g : adds debugging information to the executable file 5 | # -Wall : turns on most, but not all, compiler warnings 6 | # -std=C++17 : uses c++17 standard 7 | # put all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = decToBin.exe 12 | 13 | # list all .cpp file(s) separated by space 14 | CPPFILES = main.cpp 15 | 16 | # make all rule or the default rule that'll be run when we run "make" 17 | # first compile each file to object file 18 | # then make a single binary program 19 | all: 20 | $(CXX) $(CXXFLAGS) $(CPPFILES) # compile each file to object file 21 | $(CXX) -o $(PROGRAM) *.o # build the binary program using object file(s) 22 | # ./$(PROGRAM) # uncomment it if you want to run the program if successfully built 23 | 24 | # make clean rule 25 | # delete object and binary files 26 | clean: 27 | rm -f $(PROGRAM) *.o 28 | -------------------------------------------------------------------------------- /notebooks/demos/arrays/buffer_overflow2/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # c++ compiler flags 4 | # -g : adds debugging information to the executable file 5 | # -Wall : turns on most, but not all, compiler warnings 6 | # -std=C++17 : uses c++17 standard 7 | # -fno-stack-protector : compilers provide way to detect stack-overflow; so must be disabled! 8 | # put all the required flags separated by space 9 | CXXFLAGS = -c -g -Wall -std=c++17 -fno-stack-protector 10 | 11 | # the build target executable file; .exe is not required 12 | PROGRAM = authenticator.exe 13 | 14 | # list .cpp files separated by space 15 | CPPFILES = buffer_overflow2.cpp 16 | 17 | # make build rule/default rule that'll be run when we run "make" 18 | # first compile each file to object file 19 | # then make a single binary program 20 | build: 21 | $(CXX) $(CXXFLAGS) $(CPPFILES) 22 | $(CXX) -o $(PROGRAM) *.o 23 | 24 | run: 25 | ./$(PROGRAM) 26 | 27 | # make clean rule 28 | # delete object and binary files 29 | clean: 30 | rm -f $(PROGRAM) *.o 31 | -------------------------------------------------------------------------------- /notebooks/demos/stdio/rectangle/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # c++ compiler flags 4 | # -g : adds debugging information to the executable file 5 | # -Wall : turns on most, but not all, compiler warnings 6 | # -std=C++17 : uses c++17 standard 7 | # put all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = rectangle.exe 12 | 13 | # list all .cpp file(s) separated by space 14 | CPPFILES = main.cpp 15 | 16 | # make all rule or the default rule that'll be run when we run "make" 17 | # first compile each file to object file 18 | # then make a single binary program 19 | all: 20 | $(CXX) $(CXXFLAGS) $(CPPFILES) # compile each file to object file 21 | $(CXX) -o $(PROGRAM) *.o # build the binary program using object file(s) 22 | # ./$(PROGRAM) # uncomment it if you want to run the program if successfully built 23 | 24 | # make clean rule 25 | # delete object and binary files 26 | clean: 27 | rm -f $(PROGRAM) *.o 28 | -------------------------------------------------------------------------------- /notebooks/demos/library/printf/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # c++ compiler flags 4 | # -g : adds debugging information to the executable file 5 | # -Wall : turns on most, but not all, compiler warnings 6 | # -std=C++17 : uses c++17 standard 7 | # put all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = printf_demo.exe 12 | 13 | # list all .cpp file(s) separated by space 14 | CPPFILES = printf_demo.cpp 15 | 16 | # make all rule or the default rule that'll be run when we run "make" 17 | # first compile each file to object file 18 | # then make a single binary program 19 | all: 20 | $(CXX) $(CXXFLAGS) $(CPPFILES) # compile each file to object file 21 | $(CXX) -o $(PROGRAM) *.o # build the binary program using object file(s) 22 | # ./$(PROGRAM) # uncomment it if you want to run the program if successfully built 23 | 24 | # make clean rule 25 | # delete object and binary files 26 | clean: 27 | rm -f $(PROGRAM) *.o 28 | -------------------------------------------------------------------------------- /labs/pointers/pointers/src/utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // macro function 4 | #ifdef _WIN32 5 | #define clear() system("cls") 6 | #else 7 | #define clear() system("clear") 8 | #endif 9 | 10 | // user-defined enumerated type: OPERATION 11 | enum OPERATION 12 | { 13 | ADD, 14 | MULTIPLY, 15 | SUBTRACT, 16 | LARGER, 17 | QUIT 18 | }; 19 | 20 | // C++ way of defining type alias 21 | using big_int = long long int; 22 | 23 | // C way of defining type alias 24 | typedef long long int large_int; 25 | // both large_int and big_int are alias to "long long int" type 26 | 27 | // declare my_space namespace 28 | namespace my_space 29 | { 30 | // function prototypes defined within the namespace 31 | big_int find_sum(const big_int *, const big_int *); 32 | big_int find_larger(const big_int *, const big_int *); 33 | large_int find_product(const large_int &, const large_int &); 34 | large_int find_difference(const large_int &, const large_int &); 35 | } 36 | 37 | void show_menu(void); 38 | OPERATION get_operation(char); 39 | -------------------------------------------------------------------------------- /labs/functions/library/src/my_math.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "my_math.h" 3 | using namespace std; 4 | 5 | float square_root(float x) 6 | { 7 | return sqrt(x); 8 | } 9 | 10 | float cube_root(float x) 11 | { 12 | return cbrt(x); 13 | } 14 | 15 | float power_of_ten(float x) 16 | { 17 | return pow(10, x); 18 | } 19 | 20 | float log_base_2(float x) 21 | { 22 | return log2(x); 23 | } 24 | 25 | float log_base_10(float x) 26 | { 27 | // FIXME1 - implement function using standard library to find and return log base 10 of x 28 | return 0.0; 29 | } 30 | 31 | float degree_to_radian(float degree) 32 | { 33 | return degree * (M_PI / 180.0); 34 | } 35 | 36 | float sine_of_radian(float radian) 37 | { 38 | // FIXME2 - implement function using standard library to find and return sine of the given radian value 39 | return 0.0; 40 | } 41 | 42 | float cosine_of_radian(float radian) 43 | { 44 | // FIXME3 - implement function using standard library to find and return cosine of the given radian value 45 | return 0.0; 46 | } 47 | -------------------------------------------------------------------------------- /notebooks/demos/arrays/buffer_overflow2/buffer_overflow2.cpp: -------------------------------------------------------------------------------- 1 | // buffer overflow example 2 2 | // TODO: Compile and run the program using given Makefile 3 | // enter whatever username and about 20 As or more for passoword 4 | // goal is to display the social security without using the hidden password 5 | 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | int main() 12 | { 13 | bool valid = false; 14 | char username[10]; 15 | char password[10]; 16 | 17 | cout << "Enter username: "; 18 | cin >> username; 19 | cout << "Enter password: "; 20 | cin >> password; 21 | //strcpy(passBuffer, password); 22 | 23 | if (string(username) == "backdoor" and strcmp(password, "123456") == 0) 24 | valid = true; 25 | 26 | //cout << valid << endl; 27 | if(valid) { 28 | cout << "You have now access to top secret part of the program!" << endl; 29 | cout << "Your SSN is 123-45-5678\n"; 30 | } 31 | else 32 | cout << "Invalid username or password!" << endl; 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /notebooks/demos/functions/helloworld/helloworld.cpp: -------------------------------------------------------------------------------- 1 | /*================================================= 2 | Hello World program 3 | By: Ram Basnet 4 | Date: June 24, 2020 5 | Copyright: MIT License 6 | 7 | The program prints "Hello World!" on the console 8 | - provides automated testing 9 | ===================================================*/ 10 | 11 | // include required libraries/header files 12 | #include 13 | #include 14 | #include // assert() 15 | 16 | using namespace std; 17 | 18 | // function prototypes 19 | string hello(); 20 | void test_hello(); 21 | 22 | int main() // main entry to the program 23 | { 24 | // run test cases 25 | test_hello(); 26 | // output/print Hello World! 27 | cout << hello() << endl; 28 | return 0; 29 | } 30 | 31 | // function returns Hello World! 32 | string hello() { 33 | return "Hello World!"; 34 | } 35 | 36 | // function that tests hello function 37 | void test_hello() { 38 | assert(hello() == "Hello World!"); 39 | cerr << "all test cases passed!\n"; 40 | } -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Map Lab 3 | Kattis - Morse Code Palindromes 4 | 5 | Updated By: [Your Name Here] 6 | Date: [Today's Date Here] 7 | 8 | Solution to Morse Code Palindromes Problem: https://open.kattis.com/problems/morsecodepalindromes 9 | Algorithm steps: 10 | 1. Creae a map of char to morse code 11 | 2. Read in a string 12 | 3. Convert the string to morse code 13 | i. for each char in string, find its morse code in map 14 | ii. append morse code to a string if char key is found 15 | 4. Check if morse code is a palindrome 16 | i. compare first and last char 17 | ii. if they are the same, compare second and second last char 18 | iii. if they are the same, compare third and third last char 19 | iv. repeat until all chars are compared until mid index or a mismatch is found 20 | 5. Print 1 if morse code is a palindrome, 0 otherwise 21 | */ 22 | 23 | #include 24 | #include "morsecode.h" 25 | 26 | int main(int argc, char *argv[]) 27 | { 28 | ios_base::sync_with_stdio(false); 29 | cin.tie(NULL); 30 | 31 | solve(); 32 | return 0; 33 | } -------------------------------------------------------------------------------- /notebooks/demos/arrays/buffer_overflow1/buffer_overflow1.cpp: -------------------------------------------------------------------------------- 1 | // Buffer overflow Example 1 2 | // a simple program to demonstrate buffer overflow vulnerability by corrupting data in memory 3 | // Run the program with various length of passwords (any characters!) and notice the output of SSN 4 | // TODO: 5 | // 1. compile and run the program with 7 characters 6 | // 2. run the program with 8 characters 7 | // 3. run the program with more than 8 characters 8 | // You'll see the SSN being overwritten and corrupted with part of your password 9 | 10 | #include 11 | #include 12 | 13 | using namespace std; 14 | 15 | int main() { 16 | char social_security[] = "123-45-6789"; 17 | char password[8]; // supposed to store only 8 characters or bytes including the null byte 18 | cout << "Enter your password: "; 19 | cin >> password; 20 | // cin doesn't check the boundry or size of password 21 | // and keeps coping the char until \n 22 | cout << "you entered: " << password << endl; 23 | cout << "your SSN is " << social_security << endl; 24 | return 0; 25 | } -------------------------------------------------------------------------------- /notebooks/demos/header_files/triangle/utility.cpp: -------------------------------------------------------------------------------- 1 | #include //system() 2 | #include 3 | #include 4 | #include 5 | 6 | #include "utility.h" 7 | 8 | using namespace std; 9 | 10 | // clear function that is system independent 11 | // NOTE: system call is not a best practice 12 | void clear() { 13 | #ifdef _WIN32 // if running on Windows system 14 | system("cls"); // not a good security best-practice! 15 | #else 16 | system("clear"); // not recommended 17 | #endif 18 | } 19 | 20 | // wrapper function to test if two floating numbers are equal upto precision decimal points 21 | void assertAlmostEqual(float value1, float value2, int precision) { 22 | ostringstream oss; 23 | // create output string stream with precision for floating-point values 24 | oss << fixed << setprecision(precision) << value1 << " " << value2; 25 | // create input string stream from output string stream 26 | istringstream iss(oss.str()); 27 | float v1, v2; 28 | // extract the values as float 29 | iss >> v1 >> v2; 30 | assert(v1 == v2); 31 | } -------------------------------------------------------------------------------- /labs/functions/thelastproblem/src/thelastproblem.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Kattis - The Last Problem 3 | User-defined functions and Library Functions Lab 4 | Updated By: FIXME 5 | CSCI 111 6 | Date: FIXME 7 | 8 | Read and solve The Last Problem: https://open.kattis.com/problems/thelastproblem 9 | 10 | Algorithm: 11 | 1. Read the input string 12 | 3. Create the output as asked and print it 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "helper.h" 20 | 21 | using namespace std; 22 | 23 | int main() 24 | { 25 | string input = "input"; 26 | // step1. read data 27 | input = read_data(); 28 | // FIXME1: Call twilight function passing input as an argument 29 | // store the returned result into answer variable 30 | string answer = twilight(input); 31 | // print answer 32 | printf("%s\n", answer.c_str()); 33 | return 0; 34 | } 35 | 36 | // Function implementation 37 | string read_data() 38 | { 39 | string input; 40 | // FIXME2: using getline read and store the data into input variable 41 | // FIXME3 return input data 42 | return "FIXME"; 43 | } 44 | -------------------------------------------------------------------------------- /labs/unittest/mclimbroad/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Kattis M-Climb Road Problem 3 | Function and Unit Testing with Doctest 4 | Updated By: FIXME 5 | CSCI 111 6 | Date: FIXME 7 | 8 | Read and solve M-Climb Road problem from Kattis: https://open.kattis.com/problems/mclimbroad 9 | Algorithm: 10 | 1. Read the number of miles to be climbed and number of students 11 | 2. Convert miles to feet using the conversion factor (1 mile = 5280 feet) 12 | 3. Calculate the number of times each student will be squirted with a water gun 13 | by dividing total feet by number of students 14 | 4. Print the result 15 | 5. Write test functions to test the conversion and calculation functions 16 | */ 17 | 18 | #include 19 | #include "util.h" 20 | 21 | using namespace std; 22 | 23 | int main() 24 | { 25 | ios_base::sync_with_stdio(false); 26 | cin.tie(NULL); 27 | 28 | int road_len = 0, stu_gun = 0; 29 | // FIXME1: Read input values into road_len and stu_gun 30 | road_len = convert_miles_to_feet(road_len); 31 | cout << calculate_answer(road_len, stu_gun) << endl; 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /labs/conditionals/twostones/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "twostones.h" 4 | 5 | using namespace std; 6 | 7 | /* 8 | Kattis - Take Two Stones 9 | Conditional Logic Lab 10 | Updated By: [Your Name] 11 | CSCI 111 12 | Date: [Today's Date] 13 | 14 | Read and solve the Kattis problem: https://open.kattis.com/problems/twostones 15 | 16 | Algorithm Steps: 17 | 1. Read the number of stones 18 | 2. Check if the number of stones is odd or even 19 | 3.a. If the number is odd, Alice wins. 20 | 3.b. Otherwise, Bob wins. 21 | */ 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | ios_base::sync_with_stdio(false); 26 | cin.tie(NULL); 27 | 28 | // Your solution here 29 | if (argc == 2 and string(argv[1]) == string("test")) 30 | { 31 | // FIXME1: call testOddOrEven function that unit tests oddOrEven function 32 | // FIXME2: call the test function that unit tests answer function 33 | } 34 | else 35 | { 36 | unsigned int stones = 0; 37 | // FIXME3: readin the stones 38 | cout << answer(stones) << endl; 39 | } 40 | 41 | return 0; 42 | } -------------------------------------------------------------------------------- /notebooks/demos/classes/points/src/point.cpp: -------------------------------------------------------------------------------- 1 | // Define a Point class with methods to calculate distance from origin 2 | #include 3 | #include 4 | #include "point.hpp" 5 | using namespace std; 6 | 7 | // Constructor 8 | Point::Point(double xCoord, double yCoord) 9 | { 10 | this->x = new double(xCoord); 11 | this->y = new double(yCoord); 12 | } 13 | 14 | // Method to calculate distance from origin 15 | double Point::distance_from_origin() const 16 | { 17 | return sqrt((*x) * (*x) + (*y) * (*y)); 18 | } 19 | // overload + operator to add two points 20 | Point Point::operator+(const Point &p) const 21 | { 22 | return Point((*this->x + *p.x), (*this->y + *p.y)); 23 | } 24 | // overload == operator to compare two points 25 | bool Point::operator==(const Point &p) const 26 | { 27 | return (*this->x == *p.x) && (*this->y == *p.y); 28 | } 29 | 30 | // Destructor 31 | Point::~Point() 32 | { 33 | delete x; 34 | delete y; 35 | } 36 | 37 | // overload << operator to print point 38 | std::ostream &operator<<(std::ostream &os, const Point &p) 39 | { 40 | return os << "(" << *(p.x) << ", " << *(p.y) << ")"; 41 | } -------------------------------------------------------------------------------- /notebooks/demos/stdio/demo1/main.cpp: -------------------------------------------------------------------------------- 1 | // demonstrates standard input and output 2 | // specifically >> and getline 3 | // compile and run the program as it is 4 | // TODO: fix it by uncommenting cin >> ws; line, so the getline works propertly! 5 | 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | int main() { 12 | float n1, n2; 13 | char ch; 14 | string name; 15 | cout << "Enter two numbers separated by comma: "; 16 | // parse the input stream 17 | // >> reads and discards leading whitespace until printable character is found 18 | cin >> n1 >> ch >> n2; // leaves behind \n 19 | cout << n1 << " + " << n2 << " = " << n1+n2 << endl; 20 | cout << "Hi, what's your name?: "; 21 | // cin >> ws; // discard any whitespace character and stop at the character 22 | // ws makes the input wait until non-whitespace character is found 23 | // need to use it carefully! 24 | getline(cin, name); 25 | cout << "Nice meeting you, " << name << endl; 26 | cout << "Good bye!\n"; 27 | cout << "Press enter to quit the program..."; 28 | cin.get(); 29 | return 0; 30 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Ram Basnet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /exercises/loops/BMI/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile Template 2 | # variable for compiler name 3 | COMPILER = g++ 4 | 5 | # c++ compiler flags 6 | # -c : just do preprocess; compile and assemble into object files 7 | # -g: adds debugging information to the executable file 8 | # -Wall turns on most, but not all, compiler warnings 9 | # -std=c++17 uses c++17 standard 10 | # put all the required flags separated by space 11 | COMPILER_FLAGS = -c -g -Wall -std=c++17 12 | 13 | # the build target executable program name of your choice 14 | PROGRAM_NAME = BMI.exe # FIXME 15 | 16 | # list all .cpp files separated by space; files must exist! 17 | CPP_FILES = BMI_v4.cpp # FIXME 18 | 19 | # make build rule/default rule that'll be run when we run "make" or make build 20 | # first compile each file to object file 21 | # then make a single binary program 22 | build: 23 | $(COMPILER) $(COMPILER_FLAGS) $(CPP_FILES) 24 | $(COMPILER) -o $(PROGRAM_NAME) *.o 25 | 26 | # rule to run the program 27 | # make run to execute this rule 28 | run: 29 | ./$(PROGRAM_NAME) 30 | 31 | # make clean rule 32 | # delete object and binary files 33 | clean: 34 | rm -f $(PROGRAM_NAME) *.o 35 | -------------------------------------------------------------------------------- /notebooks/demos/makefiles/Makefile_template: -------------------------------------------------------------------------------- 1 | # Makefile Template 2 | # variable for compiler name 3 | COMPILER = g++ 4 | 5 | # c++ compiler flags 6 | # -c : just do preprocess; compile and assemble into object files 7 | # -g : adds debugging information to the executable file 8 | # -Wall : turns on most, but not all, compiler warnings 9 | # -std=c++17 : uses c++17 standard 10 | # add all the required flags separated by space 11 | COMPILER_FLAGS = -c -g -Wall -std=c++17 12 | 13 | # the build target executable program name of your choice 14 | PROGRAM_NAME = # FIXME 15 | 16 | # list all .cpp files separated by space; files must exist! 17 | CPP_FILES = # FIXME 18 | 19 | # make build rule/default rule that'll run when we run "make" or make build 20 | # first compile each file to object file 21 | # then make a single binary program 22 | build: 23 | $(COMPILER) $(COMPILER_FLAGS) $(CPP_FILES) 24 | $(COMPILER) -o $(PROGRAM_NAME) *.o 25 | 26 | # rule to run the program 27 | # make run to execute this rule 28 | run: 29 | ./$(PROGRAM_NAME) 30 | 31 | # make clean rule 32 | # delete object and binary files 33 | clean: 34 | rm -f $(PROGRAM_NAME) *.o 35 | 36 | -------------------------------------------------------------------------------- /exercises/conditionals/BMI/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile Template 2 | # variable for compiler name 3 | COMPILER = g++ 4 | 5 | # c++ compiler flags 6 | # -c : just do preprocess; compile and assemble into object files 7 | # -g : adds debugging information to the executable file 8 | # -Wall " turns on most, but not all, compiler warnings 9 | # -std=c++17 " uses c++17 standard 10 | # put all the required flags separated by space 11 | COMPILER_FLAGS = -c -g -Wall -std=c++17 12 | 13 | # the build target executable program name of your choice 14 | PROGRAM_NAME = BMI.exe # FIXME 15 | 16 | # list all .cpp files separated by space; files must exist! 17 | CPP_FILES = BMI_v3.cpp # FIXME 18 | 19 | # make build rule/default rule that'll be run when we run "make" or make build 20 | # first compile each file to object file 21 | # then make a single binary program 22 | build: 23 | $(COMPILER) $(COMPILER_FLAGS) $(CPP_FILES) 24 | $(COMPILER) -o $(PROGRAM_NAME) *.o 25 | 26 | # rule to run the program 27 | # make run to execute this rule 28 | run: 29 | ./$(PROGRAM_NAME) 30 | 31 | # make clean rule 32 | # delete object and binary files 33 | clean: 34 | rm -f $(PROGRAM_NAME) *.o 35 | -------------------------------------------------------------------------------- /exercises/functions/BMI/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile Template 2 | # variable for compiler name 3 | COMPILER = g++ 4 | 5 | # c++ compiler flags 6 | # -c : just do preprocess; compile and assemble into object files 7 | # -g : adds debugging information to the executable file 8 | # -Wall : turns on most, but not all, compiler warnings 9 | # -std=c++17 : uses c++17 standard 10 | # put all the required flags separated by space 11 | COMPILER_FLAGS = -c -g -Wall -std=c++17 12 | 13 | # the build target executable program name of your choice 14 | PROGRAM_NAME = BMI.exe # FIXME 15 | 16 | # list all .cpp files separated by space; files must exist! 17 | CPP_FILES = BMI_v2.cpp # FIXME 18 | 19 | # make build rule/default rule that'll be run when we run "make" or make build 20 | # first compile each file to object file 21 | # then make a single binary program 22 | build: 23 | $(COMPILER) $(COMPILER_FLAGS) $(CPP_FILES) 24 | $(COMPILER) -o $(PROGRAM_NAME) *.o 25 | 26 | # rule to run the program 27 | # make run to execute this rule 28 | run: 29 | ./$(PROGRAM_NAME) 30 | 31 | # make clean rule 32 | # delete object and binary files 33 | clean: 34 | rm -f $(PROGRAM_NAME) *.o 35 | -------------------------------------------------------------------------------- /notebooks/demos/conditionals/menu/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile Template 2 | # variable for compiler name 3 | COMPILER = g++ 4 | 5 | # c++ compiler flags 6 | # -c : just do preprocess; compile and assemble into object files 7 | # -g: adds debugging information to the executable file 8 | # -Wall turns on most, but not all, compiler warnings 9 | # -std=c++17 uses c++17 standard 10 | # put all the required flags separated by space 11 | COMPILER_FLAGS = -c -g -Wall -std=c++17 12 | 13 | # the build target executable program name of your choice 14 | PROGRAM_NAME = menu.exe # FIXME 15 | 16 | # list all .cpp files separated by space; files must exist! 17 | CPP_FILES = menu.cpp # FIXME 18 | 19 | # make build rule/default rule that'll be run when we run "make" or make build 20 | # first compile each file to object file 21 | # then make a single binary program 22 | build: 23 | $(COMPILER) $(COMPILER_FLAGS) $(CPP_FILES) 24 | $(COMPILER) -o $(PROGRAM_NAME) *.o 25 | 26 | # rule to run the program 27 | # make run to execute this rule 28 | run: 29 | ./$(PROGRAM_NAME) 30 | 31 | # make clean rule 32 | # delete object and binary files 33 | clean: 34 | rm -f $(PROGRAM_NAME) *.o 35 | -------------------------------------------------------------------------------- /exercises/header_files/exercise1/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile Template 2 | # variable for compiler name 3 | COMPILER = g++ 4 | 5 | # c++ compiler flags 6 | # -c : just do preprocess; compile and assemble into object files 7 | # -g: adds debugging information to the executable file 8 | # -Wall turns on most, but not all, compiler warnings 9 | # -std=c++17 uses c++17 standard 10 | # put all the required flags separated by space 11 | COMPILER_FLAGS = -c -g -Wall -std=c++17 12 | 13 | # the build target executable program name of your choice 14 | PROGRAM_NAME = exercise1.exe # FIXME 15 | 16 | # list all .cpp files separated by space; files must exist! 17 | CPP_FILES = exercise1.cpp # FIXME 18 | 19 | # make build rule/default rule that'll be run when we run "make" or make build 20 | # first compile each file to object file 21 | # then make a single binary program 22 | build: 23 | $(COMPILER) $(COMPILER_FLAGS) $(CPP_FILES) 24 | $(COMPILER) -o $(PROGRAM_NAME) *.o 25 | 26 | # rule to run the program 27 | # make run to execute this rule 28 | run: 29 | ./$(PROGRAM_NAME) 30 | 31 | # make clean rule 32 | # delete object and binary files 33 | clean: 34 | rm -f $(PROGRAM_NAME) *.o 35 | -------------------------------------------------------------------------------- /exercises/conditionals/vote1/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile Template 2 | # variable for compiler name 3 | COMPILER = g++ 4 | 5 | # c++ compiler flags 6 | # -c : just do preprocess; compile and assemble into object files 7 | # -g : adds debugging information to the executable file 8 | # -Wall : turns on most, but not all, compiler warnings 9 | # -std=c++17 : uses c++17 standard 10 | # put all the required flags separated by space 11 | COMPILER_FLAGS = -c -g -Wall -std=c++17 12 | 13 | # the build target executable program name of your choice 14 | PROGRAM_NAME = vote.exe # FIXME 15 | 16 | # list all .cpp files separated by space; files must exist! 17 | CPP_FILES = voting_eligibility.cpp # FIXME 18 | 19 | # make build rule/default rule that'll be run when we run "make" or make build 20 | # first compile each file to object file 21 | # then make a single binary program 22 | build: 23 | $(COMPILER) $(COMPILER_FLAGS) $(CPP_FILES) 24 | $(COMPILER) -o $(PROGRAM_NAME) *.o 25 | 26 | # rule to run the program 27 | # make run to execute this rule 28 | run: 29 | ./$(PROGRAM_NAME) 30 | 31 | # make clean rule 32 | # delete object and binary files 33 | clean: 34 | rm -f $(PROGRAM_NAME) *.o 35 | -------------------------------------------------------------------------------- /notebooks/demos/conditionals/main_arg1/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile Template 2 | # variable for compiler name 3 | COMPILER = g++ 4 | 5 | # c++ compiler flags 6 | # -c : just do preprocess; compile and assemble into object files 7 | # -g : adds debugging information to the executable file 8 | # -Wall : turns on most, but not all, compiler warnings 9 | # -std=c++17 : uses c++17 standard 10 | # put all the required flags separated by space 11 | COMPILER_FLAGS = -c -g -Wall -std=c++17 12 | 13 | # the build target executable program name of your choice 14 | PROGRAM_NAME = prog.exe # FIXME 15 | 16 | # list all .cpp files separated by space; files must exist! 17 | CPP_FILES = main_arg1.cpp # FIXME 18 | 19 | # make build rule/default rule that'll be run when we run "make" or make build 20 | # first compile each file to object file 21 | # then make a single binary program 22 | build: 23 | $(COMPILER) $(COMPILER_FLAGS) $(CPP_FILES) 24 | $(COMPILER) -o $(PROGRAM_NAME) *.o 25 | 26 | # rule to run the program 27 | # make run to execute this rule 28 | run: 29 | ./$(PROGRAM_NAME) 30 | 31 | # make clean rule 32 | # delete object and binary files 33 | clean: 34 | rm -f $(PROGRAM_NAME) *.o 35 | -------------------------------------------------------------------------------- /exercises/conditionals/vote2/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile Template 2 | # variable for compiler name 3 | COMPILER = g++ 4 | 5 | # c++ compiler flags 6 | # -c : just do preprocess; compile and assemble into object files 7 | # -g : adds debugging information to the executable file 8 | # -Wall : turns on most, but not all, compiler warnings 9 | # -std=c++17 : uses c++17 standard 10 | # put all the required flags separated by space 11 | COMPILER_FLAGS = -c -g -Wall -std=c++17 12 | 13 | # the build target executable program name of your choice 14 | PROGRAM_NAME = voting.exe # FIXME 15 | 16 | # list all .cpp files separated by space; files must exist! 17 | CPP_FILES = voting_eligibility_v2.cpp # FIXME 18 | 19 | # make build rule/default rule that'll be run when we run "make" or make build 20 | # first compile each file to object file 21 | # then make a single binary program 22 | build: 23 | $(COMPILER) $(COMPILER_FLAGS) $(CPP_FILES) 24 | $(COMPILER) -o $(PROGRAM_NAME) *.o 25 | 26 | # rule to run the program 27 | # make run to execute this rule 28 | run: 29 | ./$(PROGRAM_NAME) 30 | 31 | # make clean rule 32 | # delete object and binary files 33 | clean: 34 | rm -f $(PROGRAM_NAME) *.o 35 | -------------------------------------------------------------------------------- /notebooks/demos/loops/input_validate/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile Template 2 | # variable for compiler name 3 | COMPILER = g++ 4 | 5 | # c++ compiler flags 6 | # -c : just do preprocess; compile and assemble into object files 7 | # -g: adds debugging information to the executable file 8 | # -Wall turns on most, but not all, compiler warnings 9 | # -std=c++17 uses c++17 standard 10 | # put all the required flags separated by space 11 | COMPILER_FLAGS = -c -g -Wall -std=c++17 12 | 13 | # the build target executable program name of your choice 14 | PROGRAM_NAME = validation.exe # FIXME 15 | 16 | # list all .cpp files separated by space; files must exist! 17 | CPP_FILES = input_validation.cpp # FIXME 18 | 19 | # make build rule/default rule that'll be run when we run "make" or make build 20 | # first compile each file to object file 21 | # then make a single binary program 22 | build: 23 | $(COMPILER) $(COMPILER_FLAGS) $(CPP_FILES) 24 | $(COMPILER) -o $(PROGRAM_NAME) *.o 25 | 26 | # rule to run the program 27 | # make run to execute this rule 28 | run: 29 | ./$(PROGRAM_NAME) 30 | 31 | # make clean rule 32 | # delete object and binary files 33 | clean: 34 | rm -f $(PROGRAM_NAME) *.o 35 | -------------------------------------------------------------------------------- /labs/vectors/foxsays/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # g++ compiler flags 4 | # -g: adds debugging information to the executable file 5 | # -Wall: turns on most, but not all, compiler warnings 6 | # -std=c++17: uses c++17 standard 7 | # put all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=gnu++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = foxsays.exe #FIXME 12 | 13 | # list .cpp files separated by space 14 | CPPFILES = main.cpp #FIXME 15 | 16 | # make all rule/default rule that'll be run when we run "make" 17 | # first compile each file to object file 18 | # then make a single binary/executable program 19 | build: 20 | $(CXX) $(CXXFLAGS) $(CPPFILES) 21 | $(CXX) -o $(PROGRAM) *.o 22 | 23 | # make clean rule 24 | # delete object and binary files 25 | clean: 26 | @rm -f $(PROGRAM) *.o 27 | 28 | # FIXME3 - add rule to run unittest functions 29 | 30 | # FIXME4 - add 4 more commands to test the 4 input files 31 | kattis: 32 | cat 1.in | ./$(PROGRAM) | diff - 1.ans 33 | @#FIXME - Add commands to test 4 more input files 34 | @echo "All kattis test cases passed!" 35 | 36 | all: build test clean 37 | @echo "All done!" -------------------------------------------------------------------------------- /notebooks/demos/makefiles/demo5/Makefile: -------------------------------------------------------------------------------- 1 | # Fairly complex Makefile demo 2 | 3 | COMPILER = clang++ 4 | COMPILER_FLAGS = -c -g -Wall -std=c++17 5 | 6 | # list .cpp files separated by space 7 | CPP_FILES = hello.cpp 8 | 9 | # executable program name 10 | PROGRAM_NAME = hello.exe 11 | 12 | # rule using other rules 13 | # other rules must be written after the rule name on the same line separated by a space 14 | all: build run clean 15 | @echo "All Done!" 16 | 17 | 18 | # rule for compiling and building program 19 | # make or make all or make build triggers the following rule 20 | # @ suppreses/hides the command itself from printing 21 | build: 22 | @# compile .cpp to object file .o 23 | @echo "compiling..." 24 | $(COMPILER) $(COMPILER_FLAGS) $(CPP_FILES) 25 | @# build executable from object files 26 | @echo "building..." 27 | $(COMPILER) -o $(PROGRAM_NAME) *.o 28 | 29 | # rule for running binary program 30 | # make run triggers the following rule 31 | run: 32 | @echo "running program..." 33 | ./$(PROGRAM_NAME) 34 | 35 | # rule for clean up 36 | # make clean triggers the following rule 37 | clean: 38 | @echo "cleaning up..." 39 | @rm -f $(PROGRAM_NAME) *.o *.out 2> /dev/null 40 | -------------------------------------------------------------------------------- /notebooks/demos/header_files/triangle/triangle.h: -------------------------------------------------------------------------------- 1 | // Triangle struct and function prototypes 2 | 3 | #pragma once // include guard; tells the compiler to only include this file once 4 | 5 | #include 6 | using namespace std; 7 | 8 | // use struct to represent Triangle 9 | struct Triangle { 10 | int ID; 11 | float side1, side2, side3; 12 | }; 13 | 14 | // function prototypes 15 | bool validTriangle(float s1, float s2, float s3); 16 | void test_validTriangle(); 17 | Triangle getTriangle(); 18 | float trianglePerimeter(const Triangle & t); 19 | void test_trianglePerimeter(); 20 | float triangleArea(const Triangle & t); 21 | void assertAlmostEqual(float value1, float value2, int precision); 22 | void test_triangleArea(); 23 | void computeAreaAndPerimeter(const Triangle & t); 24 | void program(); 25 | void menu(); 26 | void readTriangles(vector &, const string &); 27 | void writeTriangles(const vector &, const string &); 28 | 29 | int searchTriangle(const vector &, int); 30 | bool smaller(const Triangle & t1, const Triangle & t2); 31 | bool larger(const Triangle & t1, const Triangle & t2); 32 | void printTriangles(const vector & tris); 33 | 34 | -------------------------------------------------------------------------------- /notebooks/demos/stdio/rectangle/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Composition Example 3 | Author: Ram Basnet 4 | CS1 at Colorado Mesa University 5 | Copyright: MIT - Feel free to use the code. 6 | 7 | The program finds area and perimeter of a rectangle. 8 | 9 | Algorithm steps: 10 | 11 | 1. get values for length and width of a rectangle 12 | 2. calculate area and perimeter using the following equations 13 | - area = length x width 14 | - perimeter = 2 x (length + width) 15 | 3. display the results 16 | 17 | */ 18 | 19 | #include 20 | 21 | using namespace std; 22 | 23 | int main() { 24 | // 1. variables to store length and width 25 | float rect_length, rect_width; 26 | // 1. prompt user to enter length and width of a rectangle 27 | cout << "Enter length and width of a rectangle separated by space: "; 28 | // 1. read length and width values from keyboard 29 | cin >> rect_length >> rect_width; 30 | // 2 and 3 calculate and display area and perimeter 31 | // 2 and 3: calculate and display the area and perimeter 32 | cout << "area of the rectangle: " << rect_length * rect_width << endl; 33 | cout << "perimeter of the rectangle: " << 2*(rect_length+rect_width) << endl; 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /labs/pointers/timeloop/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Pointers Lab 3 | 4 | Updated By: [Your Name] 5 | CSCI 111 6 | Date: [Today's Date] 7 | Instructor: [Instructor's Name] 8 | 9 | Read and solve the Kattis problem Stuck in a Timeloop: https://open.kattis.com/problems/timeloop 10 | 11 | Algorithm Steps: 12 | 1. Using a function, read and return N 13 | 2. Declare a dynamic variable to store, N returned by function in 1. 14 | 3. Define a function to get the necessary spell given N 15 | 4. Define a function to print answer 16 | - the function will use a loop to call cast_spell function to print spell N times: 17 | 1 Abracadabra 18 | 2 Abracadabra 19 | ... 20 | N Abracadabra 21 | */ 22 | 23 | #include 24 | #include 25 | #include "timeloop.h" 26 | 27 | using namespace std; 28 | 29 | int main() 30 | { 31 | ios_base::sync_with_stdio(false); 32 | cin.tie(NULL); 33 | 34 | // Your solution here 35 | // declare a dynamic variable to store N 36 | pos_short *N = new pos_short; 37 | 38 | // FIXME1: Call read_number function and assign the returned value to N; 39 | // FIXME2: Call print_answer function passing proper argument 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /notebooks/demos/stdio/carrots/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # g++ compiler flags 4 | # -g: adds debugging information to the executable file 5 | # -Wall: turns on most, but not all, compiler warnings 6 | # -std=c++17: uses c++17 standard 7 | # put all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = carrots.exe 12 | 13 | # list .cpp files separated by space 14 | CPPFILES = carrots.cpp 15 | 16 | # make all rule/default rule that'll be run when we run "make" 17 | # first compile each file to object file 18 | # then make a single binary/executable program 19 | all: 20 | $(CXX) $(CXXFLAGS) $(CPPFILES) 21 | $(CXX) -o $(PROGRAM) *.o 22 | 23 | # make clean rule 24 | # delete object and binary files 25 | clean: 26 | rm -f $(PROGRAM) *.o *.out 27 | @# blah 28 | 29 | # FIXME 30 | run: 31 | ./$(PROGRAM) 32 | 33 | # FIXME - add 4 more commands to test the 4 input files 34 | test: 35 | cat 1.in | ./$(PROGRAM) | diff - 1.ans 36 | cat 2.in | ./$(PROGRAM) | diff - 2.ans 37 | cat 3.in | ./$(PROGRAM) | diff - 3.ans 38 | @#FIXME - Add commands to test 4 more input files 39 | @echo "All test cases passed!" 40 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/tests/test_morsecode.cpp: -------------------------------------------------------------------------------- 1 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 2 | #include "../../../doctest/doctest.h" 3 | #include "../src/morsecode.h" 4 | 5 | TEST_CASE("Testing convert_to_morse function") 6 | { 7 | SUBCASE("Simple phrase") 8 | { 9 | string phrase = "SOS"; 10 | string expected_morse = "...---..."; 11 | CHECK(convert_to_morse(phrase) == expected_morse); 12 | } 13 | 14 | SUBCASE("Phrase with spaces and punctuation") 15 | { 16 | string phrase = "HELLO, WORLD!"; 17 | string expected_morse = "......-...-..---.-----.-..-..-.."; 18 | CHECK(convert_to_morse(phrase) == expected_morse); 19 | } 20 | 21 | // FIXME1: Add 2 more sub cases to test convert_to_morse function 22 | } 23 | 24 | TEST_CASE("Testing is_palindrome function") 25 | { 26 | SUBCASE("Palindrome morse code") 27 | { 28 | string morse = "...---..."; 29 | CHECK(is_palindrome(morse) == true); 30 | } 31 | 32 | SUBCASE("Non-palindrome morse code") 33 | { 34 | string morse = "...-.-"; 35 | CHECK(is_palindrome(morse) == false); 36 | } 37 | 38 | // FIXME2: Add 2 more sub cases to test is_palindrome function 39 | } -------------------------------------------------------------------------------- /labs/math/dfyrirdreki/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Lab: Basic Math 3 | Updated By: [Your Name] 4 | Date: [Today's Date] 5 | CSCI 111 - Foundations of Computer Science 6 | Instructor: [Instructor's Name] 7 | 8 | Read and Solve: https://open.kattis.com/problems/dfyrirdreki 9 | 10 | Algorithm steps: 11 | See hints in the figure of problem statement. 12 | 1. Read 3 coefficients (a, b, c) of a quadratic equation 13 | 2. Calculate b^2 - 4ac as the discriminant 14 | 3. if the discriminant is negative, print 0 - no real roots 15 | 4. if the discriminant is zero, print 1 - one real root 16 | 5. if the discriminant is positive, print 2 - two real roots 17 | */ 18 | 19 | #include 20 | #include 21 | #include "roots.h" 22 | 23 | using namespace std; 24 | 25 | int main() 26 | { 27 | ios_base::sync_with_stdio(false); 28 | cin.tie(NULL); 29 | 30 | // Your solution here 31 | // declare variables to store input data and answer 32 | int a, b, c; 33 | long long discriminant; 34 | cin >> a >> b >> c; 35 | 36 | // calculate the discriminant 37 | discriminant = find_discriminant(a, b, c); 38 | // FIXME1: determine the number of real roots using function and print the result 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /notebooks/demos/loops/input_validate/input_validation.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | do-while demo 3 | Author: Ram Basnet 4 | Date: 7/11/2020 5 | License: MIT - Feel free to use anyhow 6 | 7 | This program validates user input using do-while loop 8 | - valdite if the user input is an integer between 1 and 20. 9 | */ 10 | 11 | #include 12 | 13 | using namespace std; 14 | 15 | int getNumber() { 16 | int input; // variable to store user input 17 | 18 | do { 19 | cout << "Enter a whole number between 1 and 20: "; 20 | cin >> input; 21 | if (cin.fail()) { // somehow cin failed 22 | cout << "Invalid input. Try again!\n"; 23 | cin.clear(); // clear the error flag 24 | cin.ignore(INT_MAX, '\n'); // ignore upto INT_MAX bytes in std input stream or '\n' 25 | } 26 | else if (input < 1 || input > 20) { 27 | cout << "input must be a whole number between 1 and 20\n"; 28 | } 29 | else break; 30 | } while (true); 31 | 32 | return input; 33 | } 34 | 35 | int main(int argc, char* argv[]) { 36 | // declare and intialize variables; 37 | int num = getNumber(); 38 | cout << "Great! you entered: " << num << endl; 39 | return 0; 40 | } -------------------------------------------------------------------------------- /notebooks/demos/conditionals/main_arg2/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile Template 2 | # variable for compiler name 3 | COMPILER = g++ 4 | 5 | # c++ compiler flags 6 | # -c : just do preprocess; compile and assemble into object files 7 | # -g: adds debugging information to the executable file 8 | # -Wall turns on most, but not all, compiler warnings 9 | # -std=c++17 uses c++17 standard 10 | # put all the required flags separated by space 11 | COMPILER_FLAGS = -c -g -Wall -std=c++17 12 | 13 | # the build target executable program name of your choice 14 | PROGRAM_NAME = prog.exe # FIXME 15 | 16 | # list all .cpp files separated by space; files must exist! 17 | CPP_FILES = main_arg2.cpp # FIXME 18 | 19 | # make build rule/default rule that'll be run when we run "make" or make build 20 | # first compile each file to object file 21 | # then make a single binary program 22 | build: 23 | $(COMPILER) $(COMPILER_FLAGS) $(CPP_FILES) 24 | $(COMPILER) -o $(PROGRAM_NAME) *.o 25 | 26 | # rule to run the program 27 | # make run to execute this rule 28 | run: 29 | ./$(PROGRAM_NAME) 30 | 31 | # make clean rule 32 | # delete object code and binary executables 33 | clean: 34 | rm -f $(PROGRAM_NAME) *.o 35 | 36 | unittest: 37 | ./$(PROGRAM_NAME) test 38 | @printf "All done!\n" 39 | -------------------------------------------------------------------------------- /labs/namespaces/namespace/src/utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // macro function 4 | #ifdef _WIN32 5 | #define clear() system("cls") 6 | #else 7 | #define clear() system("clear") 8 | #endif 9 | 10 | // user-defined enumerated type: OPERATION 11 | // FIXME2: add more operations as needed 12 | enum OPERATION 13 | { 14 | ADD, 15 | MULTIPLY, 16 | SUBTRACT, 17 | LARGER, 18 | QUIT 19 | }; 20 | 21 | // C++ way of defining type alias 22 | using big_int = long long int; 23 | using pos_int = unsigned int; 24 | 25 | // C way of defining type alias 26 | typedef long long int large_int; 27 | // both large_int and big_int are alias to "long long int" type 28 | 29 | // declare my_functions namespace and header file contents 30 | namespace my_functions 31 | { 32 | // function prototypes defined within the namespace 33 | big_int find_sum(const big_int, const big_int); 34 | big_int find_larger(const big_int, const big_int); 35 | large_int find_product(const large_int, const large_int); 36 | int find_difference(const large_int, const pos_int); 37 | const double PI = 3.141592653589793; 38 | const double EPSILON = 0.0000001; 39 | double find_area_of_circle(const double); 40 | } 41 | 42 | void show_menu(void); 43 | OPERATION get_operation(char); 44 | -------------------------------------------------------------------------------- /labs/namespaces/grafaholur/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Namespace Lab 3 | 4 | Updated By: [Your Name] 5 | Date: [Today's Date] 6 | CSCI 111 - Foundations of Computer Science 7 | Instructor: [Instructor's Name] 8 | 9 | Kattis Problem Diggy Hole - https://open.kattis.com/problems/grafaholur 10 | 11 | Algorithm steps: 12 | 1. Read first 3 lines representing: n workers, h hours, x cubic meters 13 | - n workers can dig x cubic meters in h hours 14 | 2. Read last 2 lines representing: m workers, y cubic meters 15 | 3. Determine how long it takes m workers to dig y cubic meters 16 | 4. Use fruitful functions and namespaces where appropriate 17 | */ 18 | 19 | #include 20 | #include "dig.h" 21 | 22 | using namespace std; 23 | 24 | int main() 25 | { 26 | ios_base::sync_with_stdio(false); 27 | cin.tie(NULL); 28 | 29 | // Your solution here 30 | int n, h, x, m, y; 31 | cin >> n >> h >> x >> m >> y; 32 | 33 | // Calculate the rate of work per worker 34 | double rate_per_worker = dig::calculate_rate_per_worker(n, h, x); 35 | 36 | // Calculate time for m workers to dig y cubic meters 37 | double time_needed = dig::calculate_time_needed(m, rate_per_worker, y); 38 | 39 | cout << time_needed << endl; 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /notebooks/demos/conditionals/main_arg1/main_arg1.cpp: -------------------------------------------------------------------------------- 1 | // program demonstrates passing arguments to main 2 | // TODO: compile the program 3 | // run the program with arguments 4 | // e.g. programName 5 | // e.g. programName hello "john smith" 10 6 | #include 7 | #include //strncmp 8 | #include 9 | 10 | using namespace std; 11 | 12 | void test() { 13 | cout << "running test function!\n"; 14 | } 15 | 16 | // main takes arguments 17 | int main(int argc, char* argv[]) { 18 | // 1 argument is always available 19 | cout << "total argument count = " << argc << endl; 20 | // there'll always be one argument; the name of the program 21 | cout << "value at argv[0] = " << argv[0] << endl; 22 | 23 | // can convert each argument captured in argv[] array to string type 24 | string arg0 = string(argv[0]); // program name 25 | 26 | if (argc >= 2) { 27 | cout << "value at argv[1] = " << argv[1] << endl; 28 | string arg1 = string(argv[1]); 29 | if (arg1 == "test") 30 | test(); 31 | } 32 | 33 | if (argc >= 3) 34 | cout << "value at argv[2] = " << argv[2] << endl; 35 | if (argc >= 4) 36 | cout << "value at argv[3] = " << argv[3] << endl; 37 | // so on.. 38 | return 0; 39 | } -------------------------------------------------------------------------------- /notebooks/demos/unittest/doctest/src/fruitful.cpp: -------------------------------------------------------------------------------- 1 | // Implementation of fruitful functions for demonstration of doctest 2 | #include 3 | using namespace std; 4 | 5 | // Function that returns the sum of two integers 6 | int add(int a, int b) 7 | { 8 | return a + b; 9 | } 10 | // Function that returns the maximum of two integers 11 | int max(int a, int b) 12 | { 13 | return (a > b) ? a : b; 14 | } 15 | // Function that returns the minimum of two integers 16 | int min(int a, int b) 17 | { 18 | return (a < b) ? a : b; 19 | } 20 | // Function that returns the factorial of a non-negative integer 21 | int factorial(int n) 22 | { 23 | if (n == 0) 24 | return 1; 25 | return n * factorial(n - 1); 26 | } 27 | // Function that returns the nth Fibonacci number 28 | int fibonacci_recursive(int n) 29 | { 30 | if (n <= 1) 31 | return n; 32 | return fibonacci_recursive(n - 1) + fibonacci_recursive(n - 2); 33 | } 34 | 35 | // Function that returns the nth Fibonacci number using iteration 36 | int fibonacci_iterative(int n) 37 | { 38 | if (n <= 1) 39 | return n; 40 | int a = 0, b = 1, fib; 41 | for (int i = 2; i <= n; ++i) 42 | { 43 | fib = a + b; 44 | a = b; 45 | b = fib; 46 | } 47 | return fib; 48 | } 49 | -------------------------------------------------------------------------------- /labs/conditionals/menu/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Conditional Lab 3 | 4 | Programmer: [Your Name] 5 | Date: [Today's Date] 6 | 7 | Program finds statistical values of two given numbers using user-defined functions. 8 | 9 | A menu-driven program that demonstrates user-defined functions, automated testing conditional statements and loop. 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "utils.h" 17 | 18 | using namespace std; 19 | 20 | int main(int argc, char *argv[]) 21 | { 22 | if (argc == 2 && string(argv[1]) == string("test")) 23 | { 24 | test(); 25 | exit(EXIT_SUCCESS); // exit the program 26 | } 27 | else 28 | { 29 | // this loop will keep the program running until user wants to quit 30 | while (true) 31 | { 32 | if (!program()) // call program 33 | break; // break loop if program returned false 34 | cin.ignore(100, '\n'); 35 | cout << "Enter to continue..."; 36 | cin.get(); 37 | clear_screen(); 38 | } 39 | } 40 | cin.ignore(100, '\n'); 41 | cout << "Good bye..." << endl; 42 | cout << "Enter to quit the program.\n"; 43 | cin.get(); 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /labs/functions/library/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # c++ compiler flags 4 | # -g : adds debugging information to the executable file 5 | # -Wall : turns on most, but not all, compiler warnings 6 | # -std=C++17 : uses c++17 standard 7 | # put all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = library.exe 12 | 13 | # list .cpp files separated by space 14 | CPPFILES = src/main.cpp src/my_math.cpp 15 | 16 | # make build rule/default rule that'll be run when we run "make" 17 | # first compile each file to object file 18 | # then make a single binary program 19 | 20 | all: build doctest clean 21 | 22 | build: 23 | $(CXX) $(CXXFLAGS) $(CPPFILES) 24 | $(CXX) -o $(PROGRAM) *.o 25 | 26 | run: build 27 | ./$(PROGRAM) 28 | 29 | doctest: 30 | $(CXX) tests/test_my_math.cpp src/my_math.cpp -o test_my_math.exe 31 | ./test_my_math.exe 32 | @echo "All tests executed successfully!" 33 | 34 | # make clean rule 35 | # delete object and binary files 36 | 37 | clean: 38 | find . -name "*.o" -delete 39 | find . -name "*.dSYM" -type d -exec rm -rf {} + 2>/dev/null || true 40 | find . -name "*.exe" -delete 41 | find . -name "*.out" -delete 42 | find . -name "*.pch" -delete 43 | 44 | -------------------------------------------------------------------------------- /notebooks/data/studentgradereport.txt: -------------------------------------------------------------------------------- 1 | ========================================================================================= 2 | First Name Last Name test1 test2 test3 Avgerage 3 | ========================================================================================= 4 | John Smith 100 95 85 93.3 5 | Jane Doe 85 89 99 91.0 6 | Jill Jones 56 89 99 81.3 7 | ***************************************************************************************** 8 | ========================================================================================= 9 | First Name Last Name test1 test2 test3 Avgerage 10 | ========================================================================================= 11 | John Smith 100 95 85 93.3 12 | Jane Doe 85 89 99 91.0 13 | Jill Jones 56 89 99 81.3 14 | ***************************************************************************************** 15 | -------------------------------------------------------------------------------- /labs/unittest/triarea/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Kattis - Triangle Area Problem 3 | Function and Unit Testing with Doctest 4 | Updated By: FIXME 5 | CSCI 111 6 | Date: FIXME 7 | 8 | Read and solve Triangle Area problem: https://open.kattis.com/problems/triarea 9 | 10 | Algorithm: 11 | 1. Read height and base of a right triangle 12 | 2. Define a function to find and return area given height and base of a right triangle 13 | a. Area is given by the equation: (Base * Height)/2 14 | 3. Call the function to find and print the result 15 | 4. Write a test function to test the area function implemented in step 2 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include "triarea.h" 22 | 23 | using namespace std; 24 | 25 | int main(int argc, char **argv) 26 | { 27 | if (argc > 1 && string(argv[1]) == "test") 28 | { 29 | test_area_with_assert(); 30 | return 0; 31 | } 32 | unsigned height, base; 33 | float answer; 34 | // read height and base into corresponding variables 35 | cin >> height >> base; 36 | // FIXME1: Call area function passing proper arguments 37 | // store the returned result into answer variable 38 | answer = 0.0f; 39 | // print answer 40 | printf("%.7f\n", answer); 41 | return 0; 42 | } -------------------------------------------------------------------------------- /notebooks/demos/file_io/studentgradereport.txt: -------------------------------------------------------------------------------- 1 | ========================================================================================= 2 | First Name Last Name test1 test2 test3 Avgerage 3 | ========================================================================================= 4 | John Smith 100 95 85 93.3 5 | Jane Doe 85 89 99 91.0 6 | Jill Jones 56 89 99 81.3 7 | ***************************************************************************************** 8 | ========================================================================================= 9 | First Name Last Name test1 test2 test3 Avgerage 10 | ========================================================================================= 11 | John Smith 100 95 85 93.3 12 | Jane Doe 85 89 99 91.0 13 | Jill Jones 56 89 99 81.3 14 | ***************************************************************************************** 15 | -------------------------------------------------------------------------------- /notebooks/demos/header_files/triangle/test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // include user-defined headers 5 | #include "triangle.h" 6 | #include "test.h" 7 | #include "utility.h" 8 | 9 | using namespace std; 10 | 11 | void test_validTriangle() { 12 | assert(validTriangle(2, 3, 4) == true); 13 | assert(validTriangle(1, 2, 3) == false); 14 | assert(validTriangle(4, 5, 10) == false); 15 | cerr << "all test cases passed for validTriangle()\n"; 16 | } 17 | 18 | // write 3 test cases for trianglePerimeter 19 | void test_trianglePerimeter() { 20 | assert(trianglePerimeter(Triangle({0, 2.0f, 3.0f, 4.0f})) == 9.0f); 21 | assert(trianglePerimeter(Triangle({0, 3.0f, 4.0f, 5.0f})) == 12.0f); 22 | assert(trianglePerimeter(Triangle({0, 2.5f, 3.5f, 4.5f})) == 10.5f); 23 | cerr << "all test cases passed for trianglePerimeter()\n"; 24 | } 25 | 26 | // write 3 test cases for triangleArea 27 | void test_triangleArea() { 28 | assert(triangleArea(Triangle({0, 3, 4, 5})) == 6.0); 29 | float area = triangleArea({0, 2, 4, 5}); // coersion of 3 values into Triangle type 30 | assertAlmostEqual(area, 3.799671038392666, 4); // accuracy upto 4 decimal points 31 | assertAlmostEqual(triangleArea({0, 3, 4, 6}), 5.3326822, 4); 32 | cerr << "all test cases passed for triangleArea()\n"; 33 | } -------------------------------------------------------------------------------- /labs/loops/doggopher/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # c++ compiler flags 4 | # -g : adds debugging information to the executable file 5 | # -Wall : turns on most, but not all, compiler warnings 6 | # -std=C++17 : uses c++17 standard 7 | # put all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = doggopher.exe 12 | 13 | # list .cpp files separated by space 14 | SOURCEFILES = $(wildcard src/*.cpp) 15 | TESTFILES = $(wildcard tests/*.cpp) 16 | 17 | 18 | # make build rule/default rule that'll be run when we run "make" 19 | # first compile each file to object file 20 | # then make a single binary program 21 | 22 | all: build doctest clean 23 | 24 | build: 25 | $(CXX) $(CXXFLAGS) $(SOURCEFILES) 26 | $(CXX) -o $(PROGRAM) *.o 27 | 28 | run: build 29 | ./$(PROGRAM) 30 | 31 | doctest: 32 | $(CXX) $(TESTFILES) src/doggopher.cpp -o test_doggopher.exe 33 | ./test_doggopher.exe 34 | @echo "All tests executed successfully!" 35 | 36 | # make clean rule 37 | # delete object and binary files 38 | 39 | clean: 40 | find . -name "*.o" -delete 41 | find . -name "*.dSYM" -type d -exec rm -rf {} + 2>/dev/null || true 42 | find . -name "*.exe" -delete 43 | find . -name "*.out" -delete 44 | find . -name "*.pch" -delete 45 | 46 | -------------------------------------------------------------------------------- /labs/strings/simonsays/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # c++ compiler flags 4 | # -g: adds debugging information to the executable file 5 | # - Wall turns on most, but not all, compiler warnings 6 | # -std=C++17 uses c++17 standard 7 | # add all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = simonsays.exe 12 | 13 | # list .cpp files separated by space 14 | CPPFILES = main.cpp 15 | 16 | # make build rule/default rule that'll be run when we run "make" or make build 17 | # first compile each file to object file 18 | # then make a single binary program 19 | build: 20 | @$(CXX) $(CXXFLAGS) $(CPPFILES) 21 | @$(CXX) -o $(PROGRAM) *.o 22 | 23 | run: 24 | @./$(PROGRAM) 25 | 26 | # make clean rule 27 | # delete object and binary files 28 | clean: 29 | @rm -f $(PROGRAM) *.o 30 | 31 | # run the test cases 32 | unittest: 33 | @./$(PROGRAM) test 34 | 35 | # test the kattis provided samples 36 | kattistest: 37 | cat ./sample_tests/1.in | ./$(PROGRAM) | diff - ./sample_tests/1.ans 38 | cat ./sample_tests/2.in | ./$(PROGRAM) | diff - ./sample_tests/2.ans 39 | cat ./sample_tests/3.in | ./$(PROGRAM) | diff - ./sample_tests/3.ans 40 | @echo "All Test Cases Passed!" 41 | 42 | all: build unittest clean 43 | @printf "All good!\n" -------------------------------------------------------------------------------- /labs/arrays/modulo/src/modulo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "modulo.h" 3 | using namespace std; 4 | 5 | using ui = unsigned int; 6 | 7 | // Function to get num modulo 42 8 | unsigned int get_modulo_42(ui num) 9 | { 10 | // FIXME4: return num modulo 42 11 | return 0; 12 | } 13 | 14 | // Function to read data into the array 15 | void read_data(ui *data, size_t arr_len) 16 | { 17 | for (int i = 0; i < arr_len; i++) 18 | cin >> data[i]; 19 | } 20 | 21 | // Function to update flags array based on numbers modulo 42 22 | void update_flags(const ui *numbers, bool *flags, size_t num_len) 23 | { 24 | ui mod; 25 | for (int i = 0; i < num_len; i++) 26 | { 27 | mod = get_modulo_42(numbers[i]); 28 | cerr << "mod = " << mod << endl; 29 | flags[mod] = true; 30 | } 31 | } 32 | 33 | // Function to initialize flags array to false 34 | void init_flags(bool *flags, size_t flags_len) 35 | { 36 | for (int i = 0; i < flags_len; i++) 37 | flags[i] = false; 38 | } 39 | 40 | // Function to count the number of true flags 41 | size_t count_flags(const bool flags[], size_t flags_len) 42 | { 43 | size_t count = 0; 44 | for (int i = 0; i < flags_len; i++) 45 | { 46 | // FIXME5: if the flags at index i is set to true, increment count by 1 47 | } 48 | return count; 49 | } 50 | -------------------------------------------------------------------------------- /labs/strings/hissingmicrophone/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # c++ compiler flags 4 | # -g: adds debugging information to the executable file 5 | # - Wall turns on most, but not all, compiler warnings 6 | # -std=C++17 uses c++17 standard 7 | # add all the required flags separated by space 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = hissing.exe 12 | 13 | # list .cpp files separated by space 14 | CPPFILES = main.cpp 15 | 16 | # make build rule/default rule that'll be run when we run "make" or make build 17 | # first compile each file to object file 18 | # then make a single binary program 19 | build: 20 | $(CXX) $(CXXFLAGS) $(CPPFILES) 21 | $(CXX) -o $(PROGRAM) *.o 22 | 23 | run: 24 | ./$(PROGRAM) 25 | 26 | # make clean rule 27 | # delete object and binary files 28 | clean: 29 | rm -f $(PROGRAM) *.o 30 | 31 | # run the test cases 32 | unittest: 33 | ./$(PROGRAM) test 34 | 35 | # test the kattis provided samples 36 | kattistest: 37 | cat ./sample_tests/1.in | ./$(PROGRAM) | diff - ./sample_tests/1.ans 38 | cat ./sample_tests/2.in | ./$(PROGRAM) | diff - ./sample_tests/2.ans 39 | cat ./sample_tests/3.in | ./$(PROGRAM) | diff - ./sample_tests/3.ans 40 | @echo "All test cases passed!" 41 | 42 | all: build unittest kattistest clean 43 | @printf "All good!\n" -------------------------------------------------------------------------------- /labs/strings/hissingmicrophone/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Kattis - Hissing Microphone Problem 3 | 4 | Updated By: FIXME1 5 | Date: FIXME2 6 | 7 | Problem Statement: https://open.kattis.com/problems/hissingmicrophone 8 | Algorithm steps: 9 | 1. Read a string 10 | 2. Search for "ss" substring in the string 11 | i. if found, print "hiss" 12 | ii. otherwise, print "no hiss" 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | using namespace std; 20 | 21 | // function prototypes 22 | string answer(const string &line); 23 | void testAnswer(); 24 | void solve(); 25 | 26 | int main(int argc, char* argv[]) { 27 | if (argc == 2 and string(argv[1]) == "test") 28 | testAnswer(); 29 | else 30 | solve(); 31 | } 32 | 33 | string answer(const string &line) { 34 | // FIXME3 - implement algorithm step 2; return "hiss" or "no hiss" 35 | return "hiss"; 36 | } 37 | 38 | // unit testing answer() 39 | void testAnswer() { 40 | // FIXME4 - write at least two test cases to test answer() 41 | cerr << "All test cases passed!\n"; 42 | } 43 | 44 | // solving the problem for kattis 45 | void solve() { 46 | string line; 47 | // Note: string consists of only lowercase letters (no spaces) upto 30 chars 48 | // FIXME5 - read string into line 49 | cout << answer(line) << endl; 50 | } 51 | -------------------------------------------------------------------------------- /labs/variables/ascii/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ASCII Lab 3 | ASCII Art - Using variables 4 | 5 | Updated By: #FIXME1 6 | Date: ... #FIXME2 7 | 8 | This program produces an ASCII art on the console. 9 | 10 | Algorithm steps: 11 | 1. Use variables to store data/values 12 | 2. Write a series of cout statements to print the values. 13 | */ 14 | 15 | #include //library for input and output 16 | #include 17 | 18 | using namespace std; //resolve cout, cin, and endl names 19 | 20 | //main entry point of the program 21 | int main() 22 | { 23 | // FIXME3: declare a variable to store name 24 | // FIXME4: assign "your full name" to the variable declared in FIXME3 25 | //FXIME5: greet the name using the variable as the following output 26 | //must output: Nice meeting you, ! 27 | 28 | string line1 = " |\\_/| ********************** (\\_/)\n"; 29 | cout << line1; 30 | 31 | //FIXME6: use variable to print the 2nd line 32 | //FIXME7: use variable to print the 3rd line 33 | //FIXME8: use variable to print the 4th line 34 | //FIXME9: use variable to print the 5th line 35 | 36 | cout << "\nGood bye... hit enter to exit the program: " << '\n'; 37 | // FIXME10: make the console wait for user input 38 | 39 | return 0; //exit program by returning 0 status to the system 40 | } -------------------------------------------------------------------------------- /labs/conditionals/twostones/tests/test_twostones.cpp: -------------------------------------------------------------------------------- 1 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 2 | #include "../../../doctest/doctest.h" // FIXME: adjust the path as needed 3 | #include "../src/twostones.h" 4 | 5 | TEST_CASE("Testing odd_or_even function") 6 | { 7 | SUBCASE("Sub Case 1: Odd number") 8 | { 9 | unsigned int number = 7; 10 | string expected = "odd"; 11 | string result = odd_or_even(number); 12 | CHECK(result == expected); 13 | } 14 | SUBCASE("Sub Case 2: Even number") 15 | { 16 | unsigned int number = 10; 17 | string expected = "even"; 18 | string result = odd_or_even(number); 19 | CHECK(result == expected); 20 | } 21 | // FIXME8: Write 3rd and 4th test cases for odd_or_even function 22 | } 23 | 24 | TEST_CASE("Testing answer function") 25 | { 26 | SUBCASE("Sub Case 1: Odd number of stones") 27 | { 28 | unsigned int stones = 5; 29 | string expected = "Alice"; 30 | string result = answer(stones); 31 | CHECK(result == expected); 32 | } 33 | SUBCASE("Sub Case 2: Even number of stones") 34 | { 35 | unsigned int stones = 8; 36 | string expected = "Bob"; 37 | string result = answer(stones); 38 | CHECK(result == expected); 39 | } 40 | // FIXME9: Write 3rd and 4th test cases for answer function 41 | } 42 | -------------------------------------------------------------------------------- /labs/arrays/modulo/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Kattis - Module 3 | Arrays Lab 4 | Updated By: FIXME 5 | CSCI 111 6 | Date: FIXME 7 | 8 | Read and solve the Kattis problem: https://open.kattis.com/problems/modulo 9 | 10 | Algorithm Steps: 11 | 1. Read 10 numbers into an array 12 | 2. Create boolean array of size 42 to store the modulo 42 values (0-41) 13 | - initialize the array with false values 14 | 3. For each of the 10 numbers: 15 | 3.a find the number modulo 42 as an index and set the flag of the array at that index to true 16 | 4. Go through the boolean array and count all true values 17 | 5. Print the count of the true values to find the unique modulo 42 values 18 | */ 19 | 20 | #include 21 | #include 22 | #include "modulo.h" 23 | 24 | using namespace std; 25 | using ui = unsigned int; 26 | 27 | int main(int argc, char *argv[]) 28 | { 29 | ios_base::sync_with_stdio(false); 30 | cin.tie(NULL); 31 | 32 | // create a dynamic unsigned int array of size 10 to store numbers 33 | ui *nums = new ui[10]; 34 | // read 10 numbers into nums array 35 | read_data(nums, 10); 36 | // create a dynamic boolean array of size 42 to store num % 42 flags 37 | bool *flags = new bool[42]; 38 | init_flags(flags, 42); 39 | update_flags(nums, flags, 10); 40 | // FIXME3 - call count_flags function passing proper 41 | // argument and print the result 42 | return 0; 43 | } -------------------------------------------------------------------------------- /notebooks/demos/unittest/assert2/unittesting2.cpp: -------------------------------------------------------------------------------- 1 | // unittesting fruitful functions, v.2 2 | // a better way using function to write all the test cases 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | // templated add function 9 | template 10 | T1 add(T2, T3); 11 | 12 | void test_add(); 13 | 14 | int main() { 15 | // do automatic testing of addfunc 16 | test_add(); 17 | // manual testing 18 | long answer; 19 | int n1, n2; 20 | cout << "Enter two integers separated by space: "; 21 | cin >> n1 >> n2; 22 | // calculate answer 23 | answer = add(n1, n2); 24 | cout << n1 << " + " << n2 << " = " << answer << endl; 25 | cout << "All done... Good bye!\n"; 26 | return 0; 27 | } 28 | 29 | // function adds two numbers and returns the sum 30 | template 31 | T1 add(T2 para1, T3 para2) { 32 | return para1 + para2; 33 | } 34 | 35 | void test_add() { 36 | // test add 37 | // Note: cannot call template function directly inside the assert 38 | long ans = add(10, 20); 39 | assert(ans == 30); 40 | ans = add(99, 1); 41 | assert(ans == 100); 42 | float ans2 = add(10, 20.5); 43 | assert(ans2 == 30.5); 44 | string ans3 = add("Hello", " World"); 45 | assert(ans3 == "Hello World"); 46 | cerr << "all test cases passed!\n"; 47 | } -------------------------------------------------------------------------------- /labs/conditionals/menu/src/utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define MAX_ERROR 0.01f 4 | 5 | // function prototypes 6 | 7 | // function clears the screen using system call 8 | void clear_screen(); 9 | 10 | // function prints menu options 11 | void print_menu(void); 12 | 13 | // function prompts user to enter two numbers 14 | // the numbers are stored in the parameters provided 15 | void get_two_numbers(double &, double &); 16 | 17 | // function takes two numbers; finds and returns the sum of the two 18 | double find_sum(const double &, const double &); 19 | 20 | // function takes two numbers; finds and returns the 2nd subtracted from the first 21 | double find_difference(const double &, const double &); 22 | 23 | // function takes two numbers; finds and returns the product of them 24 | double find_product(const double &, const double &); 25 | 26 | // function takes two numbers; finds; returns the quotient of first divided by the second 27 | double find_quotient(const double &, const double &); 28 | 29 | // function takes two numbers; finds and returns the average of the two 30 | void find_average(const double &, const double &, double &); 31 | 32 | // function takes two numbers; finds and returns the larger of the two 33 | double find_larger(const double &, const double &); 34 | 35 | // function takes two numbers; finds and returns the smaller of the two 36 | double find_smaller(const double &, const double &); 37 | 38 | void test(); 39 | 40 | bool program(); -------------------------------------------------------------------------------- /labs/functions/thelastproblem/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name variable 2 | CXX = g++ 3 | # c++ compiler flags 4 | # -g : adds debugging information to the executable file 5 | # -Wall : turns on most compiler warnings 6 | # -std=C++17 : uses c++17 standard 7 | # assign all the required flags separated by space to a variable 8 | CXXFLAGS = -c -g -Wall -std=c++17 9 | 10 | # the build target executable file; .exe is not required 11 | PROGRAM = thelastproblem.exe 12 | 13 | # list .cpp files separated by space 14 | 15 | SRC = $(wildcard src/*.cpp) 16 | TESTS = $(wildcard tests/*.cpp) 17 | 18 | # default rule that'll be run when we run "make" 19 | # first compile each file to object files 20 | # then link all objects files to a single binary program 21 | all: 22 | $(CXX) $(CXXFLAGS) $(SRC) 23 | $(CXX) -o $(PROGRAM) *.o 24 | 25 | 26 | run: 27 | ./$(PROGRAM) 28 | 29 | # make clean rule 30 | # delete object and binary files 31 | clean: 32 | find . -type f -name "*.out" -delete 33 | find . -type f -name "*.o" -delete 34 | find . -type f -name ".exe" -delete 35 | find . -type d -name "*.dSYM" -exec rm -r {} + 36 | 37 | test: 38 | cat data/1.in | ./$(PROGRAM) | diff - data/1.ans 39 | cat data/2.in | ./$(PROGRAM) | diff - data/2.ans 40 | @#FIXME - Add commands to test 3 more input files 41 | @echo "All test cases passed!" 42 | 43 | unit_test: 44 | $(CXX) tests/test_helper.cpp src/helper.cpp -o test_helper.exe 45 | ./test_helper.exe 46 | @echo "All tests passed!" 47 | --------------------------------------------------------------------------------