├── .gitignore ├── 00-TableOfContents.ipynb ├── Arrays.ipynb ├── Conditionals.ipynb ├── DataTypesAndBasicOperations.ipynb ├── DataTypesAndCasting.ipynb ├── DataTypesAndVariables.ipynb ├── DevEnvironmentSetup.ipynb ├── FileIO.ipynb ├── HeaderFiles.ipynb ├── Introduction.ipynb ├── JupyterNotebookSetup.ipynb ├── Kattis.ipynb ├── LICENSE ├── LibraryAndFunction.ipynb ├── Loops.ipynb ├── Makefile.ipynb ├── Maps.ipynb ├── Namespaces-Enumerations.ipynb ├── Pointers.ipynb ├── README.md ├── StdInputOutput.ipynb ├── Strings.ipynb ├── Structures.ipynb ├── Unions.ipynb ├── UserDefinedFunctionsTesting.ipynb ├── Vectors.ipynb ├── demos ├── arrays │ ├── buffer_overflow1 │ │ ├── Makefile │ │ └── buffer_overflow1.cpp │ ├── buffer_overflow2 │ │ ├── Makefile │ │ └── buffer_overflow2.cpp │ └── overflow_fixed │ │ ├── Makefile │ │ └── overflow_fixed.cpp ├── conditionals │ ├── main_arg1 │ │ ├── Makefile │ │ └── main_arg1.cpp │ ├── main_arg2 │ │ ├── Makefile │ │ └── main_arg2.cpp │ ├── menu │ │ ├── Makefile │ │ └── menu.cpp │ └── rectangle │ │ ├── Makefile │ │ └── main.cpp ├── file_io │ ├── formatted_output.txt │ ├── inputfile.txt │ ├── outputfile.txt │ ├── outputfile1.txt │ ├── studentgradereport.txt │ ├── studentgrades.txt │ └── triangle │ │ ├── Makefile │ │ ├── triangle.cpp │ │ ├── triangles_db.txt │ │ └── triangles_results.txt ├── functions │ ├── assert │ │ ├── Makefile │ │ └── assertdebug.cpp │ ├── func_prototype │ │ ├── Makefile │ │ └── func_prototype.cpp │ ├── helloworld │ │ └── helloworld.cpp │ ├── rectangle │ │ ├── Makefile │ │ └── main.cpp │ ├── unittest1 │ │ ├── Makefile │ │ └── unittesting.cpp │ ├── unittest2 │ │ ├── Makefile │ │ └── unittesting2.cpp │ └── unittest3 │ │ ├── Makefile │ │ └── unittesting3.cpp ├── header_files │ ├── header │ │ ├── Makefile │ │ ├── main.cpp │ │ ├── utility.cpp │ │ └── utility.h │ └── triangle │ │ ├── Makefile │ │ ├── main.cpp │ │ ├── test.cpp │ │ ├── test.h │ │ ├── triangle.cpp │ │ ├── triangle.h │ │ ├── triangles_db.txt │ │ ├── utility.cpp │ │ └── utility.h ├── intro │ ├── Makefile │ └── helloworld.cpp ├── library │ └── printf │ │ ├── Makefile │ │ └── printf_demo.cpp ├── loops │ ├── countdown │ │ ├── Makefile │ │ └── countdown.cpp │ ├── input_validate │ │ ├── Makefile │ │ └── input_validation.cpp │ └── rectangle │ │ ├── Makefile │ │ └── main.cpp ├── maps │ └── letter_frequency │ │ ├── Makefile │ │ └── main.cpp ├── pointers │ └── rectangle │ │ ├── Makefile │ │ └── main.cpp ├── stdio │ ├── carrots │ │ ├── 1.ans │ │ ├── 1.in │ │ ├── 2.ans │ │ ├── 2.in │ │ ├── 3.ans │ │ ├── 3.in │ │ ├── Makefile │ │ └── carrots.cpp │ ├── decToBin │ │ ├── Makefile │ │ └── main.cpp │ ├── demo1 │ │ ├── Makefile │ │ └── main.cpp │ └── rectangle │ │ ├── Makefile │ │ └── main.cpp ├── structs │ └── triangle │ │ ├── Makefile │ │ ├── triangle.cpp │ │ └── triangles_db.txt ├── variables │ └── exercise1.cpp └── vectors │ ├── splitString │ ├── Makefile │ └── splitString.cpp │ └── triangle │ ├── Makefile │ ├── output.txt │ ├── triangle.cpp │ ├── triangles_db.txt │ └── triangles_report.txt ├── environment.yml ├── exercises ├── Task - Unit 10.doc ├── conditionals │ ├── BMI │ │ ├── BMI_v3.cpp │ │ └── Makefile │ ├── vote1 │ │ ├── Makefile │ │ └── voting_eligibility.cpp │ └── vote2 │ │ ├── Makefile │ │ └── voting_eligibility_v2.cpp ├── functions │ └── BMI │ │ ├── BMI_v2.cpp │ │ └── Makefile ├── header_files │ └── exercise1 │ │ ├── Makefile │ │ └── exercise1.cpp ├── intro │ └── helloworld │ │ ├── Makefile │ │ └── main.cpp ├── library │ └── rectangle │ │ ├── Makefile │ │ └── main.cpp ├── loops │ └── BMI │ │ ├── BMI_v4.cpp │ │ └── Makefile ├── stdio │ ├── BMI │ │ ├── Makefile │ │ └── main.cpp │ └── hangman │ │ └── Hangman-README.pdf └── variables │ └── exercise1 │ ├── Makefile │ └── main.cpp ├── formatConverter.py ├── inputfile.txt ├── inputfile_copy.txt ├── labs ├── arrays │ ├── modulo │ │ ├── 1.ans │ │ ├── 1.in │ │ ├── 2.ans │ │ ├── 2.in │ │ ├── 3.ans │ │ ├── 3.in │ │ ├── Makefile │ │ └── main.cpp │ └── numbers │ │ ├── Makefile │ │ └── main.cpp ├── conditionals │ ├── menu │ │ ├── Makefile │ │ ├── README.docx │ │ └── main.cpp │ └── twostones │ │ ├── 1.ans │ │ ├── 1.in │ │ ├── 2.ans │ │ ├── 2.in │ │ ├── 3.ans │ │ ├── 3.in │ │ ├── Makefile │ │ └── main.cpp ├── fileio │ ├── Makefile │ ├── fileio.cpp │ ├── input.txt │ └── output.txt ├── functions │ ├── lastproblem │ │ ├── 1.ans │ │ ├── 1.in │ │ ├── 2.ans │ │ ├── 2.in │ │ ├── Makefile │ │ └── main.cpp │ └── library │ │ ├── Makefile │ │ └── main.cpp ├── intro │ ├── Makefile │ └── main.cpp ├── loops │ ├── doggopher │ │ ├── 1.ans │ │ ├── 1.in │ │ ├── 2.ans │ │ ├── 2.in │ │ ├── Makefile │ │ └── main.cpp │ └── shapes │ │ ├── Makefile │ │ └── main.cpp ├── maps │ ├── baconeggsandspam │ │ ├── 1.ans │ │ └── 1.in │ ├── morsecodepalindromes │ │ ├── Makefile │ │ ├── main.cpp │ │ └── sample_tests │ │ │ ├── 0.ans │ │ │ ├── 0.in │ │ │ ├── 1.ans │ │ │ ├── 1.in │ │ │ ├── 2.ans │ │ │ ├── 2.in │ │ │ ├── 3.ans │ │ │ ├── 3.in │ │ │ ├── 4.ans │ │ │ ├── 4.in │ │ │ ├── 5.ans │ │ │ ├── 5.in │ │ │ ├── 6.ans │ │ │ └── 6.in │ └── sevenwonders │ │ ├── Makefile │ │ ├── main.cpp │ │ └── sample_tests │ │ ├── 1.ans │ │ ├── 1.in │ │ ├── 2.ans │ │ ├── 2.in │ │ ├── 3.ans │ │ └── 3.in ├── math │ ├── addtwonumbers │ │ ├── 1.ans │ │ ├── 1.in │ │ ├── 2.ans │ │ ├── 2.in │ │ ├── Makefile │ │ └── main.cpp │ └── circle │ │ ├── Makefile │ │ └── main.cpp ├── pointers │ ├── pointersNamespace │ │ ├── Makefile │ │ └── main.cpp │ └── timeloop │ │ ├── 1.ans │ │ ├── 1.in │ │ ├── 2.ans │ │ ├── 2.in │ │ ├── Makefile │ │ └── main.cpp ├── stdio │ ├── ascii1 │ │ ├── Makefile │ │ └── main.cpp │ └── ascii2 │ │ ├── Makefile │ │ └── main.cpp ├── strings │ ├── hissingmicrophone │ │ ├── Makefile │ │ ├── main.cpp │ │ └── sample_tests │ │ │ ├── 1.ans │ │ │ ├── 1.in │ │ │ ├── 2.ans │ │ │ ├── 2.in │ │ │ ├── 3.ans │ │ │ └── 3.in │ ├── palindrome │ │ ├── Makefile │ │ └── palindrome.cpp │ └── simonsays │ │ ├── Makefile │ │ ├── main.cpp │ │ └── sample_tests │ │ ├── 1.ans │ │ ├── 1.in │ │ ├── 2.ans │ │ ├── 2.in │ │ ├── 3.ans │ │ └── 3.in ├── unittest │ ├── points │ │ ├── Makefile │ │ └── main.cpp │ └── triangleArea │ │ ├── 1.ans │ │ ├── 1.in │ │ ├── 2.ans │ │ ├── 2.in │ │ ├── Makefile │ │ └── main.cpp ├── variables │ └── ascii │ │ ├── Makefile │ │ └── main.cpp └── vectors │ ├── foxsays │ ├── 1.ans │ ├── 1.in │ ├── Makefile │ └── main.cpp │ └── numSystem │ ├── Makefile │ └── numberSystem.cpp ├── latex ├── 00-TableOfContents.tex ├── Arrays.tex ├── Conditionals.tex ├── DataVariablesAndOperations.tex ├── DevEnvironmentSetup.tex ├── FileIO.tex ├── HeaderFiles.tex ├── Introduction.tex ├── JupyterNotebookSetup.tex ├── Kattis.tex ├── LibraryAndFunction.tex ├── Loops.tex ├── Maps.tex ├── Namespaces-Enumerations.tex ├── Pointers.tex ├── StdInputOutput.tex ├── Strings.tex ├── Structures.tex ├── UserDefinedFunctions.tex ├── Vectors.tex └── resources │ ├── BuildingBlocks.png │ ├── CPPDevelopment.png │ ├── Cartesian-coordinates.png │ ├── Compiler.png │ ├── Do-While-Loop.png │ ├── For-Loop.png │ ├── Intrepreter.png │ ├── Map.png │ ├── VariablesAndMemory.png │ ├── While-Loop.png │ ├── array.png │ ├── chess-board.jpg │ ├── ifelsestatement.png │ ├── ifstatement.png │ ├── launchbinder.png │ ├── memory-layout.png │ ├── multi-wayselector.png │ ├── pointers-in-cpp.jpg │ ├── range-begin-end.png │ ├── range-begin-end.svg │ ├── range-rbegin-rend.png │ ├── range-rbegin-rend.svg │ ├── record.png │ ├── records.png │ ├── scopesandnameresolution.png │ ├── string_rep.png │ ├── switch.png │ └── tic-tac-toe.png ├── makefile_demos ├── Makefile_template ├── demo1 │ ├── Makefile │ └── hello.cpp ├── demo2 │ ├── Makefile │ └── hello.cpp ├── demo3 │ ├── Makefile │ └── hello.cpp ├── demo4 │ ├── Makefile │ └── hello.cpp └── demo5 │ ├── Makefile │ └── hello.cpp ├── notes ├── Part 1 Lessons 1 to 4.pdf ├── Part 2 Lessons 5 to 8.pdf ├── Part 3 Lessons 9 to 10.pdf ├── Part 4 Lessons 11 to 13.pdf └── Unit 10.pdf ├── outputfile.txt ├── outputfile1.txt ├── pdfs ├── 00-TableOfContents.pdf ├── Arrays.pdf ├── Conditionals.pdf ├── DataVariablesAndOperations.pdf ├── DevEnvironmentSetup.pdf ├── FileIO.html ├── FileIO.pdf ├── HeaderFiles.pdf ├── Introduction.pdf ├── JupyterNotebookSetup.pdf ├── Kattis.pdf ├── LibraryAndFunction.pdf ├── Loops.pdf ├── Maps.pdf ├── Namespaces-Enumerations.pdf ├── Pointers.pdf ├── StdInputOutput.pdf ├── Strings.pdf ├── Structures.pdf ├── Unions.pdf ├── UserDefinedFunctions.pdf └── Vectors.pdf ├── practicums ├── Data Types and fileIOAssignment.pdf ├── Dynamic Memory and Data Types Assignment.pdf ├── Practicum 10 Pointers hands study guide.pdf ├── Practicum 12 Exceptions Theory and examples │ ├── Exception_handling Ex1.cpp │ ├── Exception_handling Ex2.cpp │ ├── Exception_handling Ex3.cpp │ └── Exceptions.ppt ├── Practicum 13 Structs uses Linked Lists │ ├── Linked List & Classes intro.pdf │ ├── linkedlist.cpp │ ├── linkedlist.h │ └── string-examples │ │ ├── string1.cpp │ │ ├── string2.cpp │ │ ├── string3.cpp │ │ ├── string4.cpp │ │ └── string5.cpp ├── Practicum 2 Style Guide for CSCI111.pdf ├── Practicum 3 PSEUDO TO Cod.pdf ├── Practicum 4 ArithmaticAndPreceedence.pdf ├── Practicum 5 Selection.pdf ├── Practicum 6 Repetition.pdf ├── Practicum 6 challenge:assignment.pdf ├── Practicum 7 Function.pdf ├── Practicum 8 Data Types Array.pdf ├── Practicum 9 Enum TypeDef Structs.pdf └── period.tbl ├── record_copy.png ├── resources ├── BuildingBlocks.png ├── CPPDevelopment.png ├── Cartesian-coordinates.png ├── Compiler.png ├── Do-While-Loop.png ├── For-Loop.png ├── Intrepreter.png ├── Map.png ├── VariablesAndMemory.png ├── While-Loop.png ├── array.png ├── chess-board.jpg ├── ifelsestatement.png ├── ifstatement.png ├── launchbinder.png ├── memory-layout.png ├── multi-wayselector.png ├── pointers-in-cpp.jpg ├── range-begin-end.png ├── range-begin-end.svg ├── range-rbegin-rend.png ├── range-rbegin-rend.svg ├── record.png ├── records.png ├── scopesandnameresolution.png ├── string_rep.png ├── switch.png └── tic-tac-toe.png ├── slides ├── 1-2.ppt ├── 10.ppt ├── 3-4.ppt ├── 5-6.ppt ├── 7.ppt ├── 8 Repetition.ppt ├── 8 Selection.ppt ├── 9.ppt ├── Unit 1-2.pdf ├── Unit 3-4.pdf ├── Unit 5-6.pdf ├── Unit 7.pdf ├── Unit 8-0.pdf ├── Unit 8-1.pdf └── Unit 9.pdf ├── studentgradereport.txt └── studentgrades.txt /.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/ -------------------------------------------------------------------------------- /00-TableOfContents.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# C++ Fundamentals\n", 8 | "- partially based on [http://www.greenteapress.com/thinkcpp/thinkCScpp.pdf](http://www.greenteapress.com/thinkcpp/thinkCScpp.pdf)\n", 9 | "\n", 10 | "## Contents\n", 11 | "1. [**Introduction**](./Introduction.ipynb)\n", 12 | "2. [**Data, Types and Variables**](./DataTypesAndVariables.ipynb)\n", 13 | "3. [**Standard Input and Output**](./StdInputOutput.ipynb)\n", 14 | "4. [**Data Types and Basic Operations**](./DataTypesAndBasicOperations.ipynb)\n", 15 | "3. [**Data Types and Casting**](./DataTypesAndCasting.ipynb)\n", 16 | "4. [**Libraries and Functions**](./LibraryAndFunction.ipynb)\n", 17 | "5. [**User Defined Functions and Testing**](./UserDefinedFunctionsTesting.ipynb)\n", 18 | "6. [**Conditionals**](./Conditionals.ipynb)\n", 19 | "7. [**Loops**](./Loops.ipynb)\n", 20 | "8. [**Pointers**](./Pointers.ipynb)\n", 21 | "9. [**Namespaces and Enumerations**](./Namespaces-Enumerations.ipynb)\n", 22 | "10. [**Strings**](./Strings.ipynb)\n", 23 | "11. [**Arrays**](./Arrays.ipynb)\n", 24 | "12. [**Vectors**](./Vectors.ipynb)\n", 25 | "13. [**File Input and Output**](./FileIO.ipynb)\n", 26 | "14. [**Structures**](./Structures.ipynb)\n", 27 | "15. [**Unions**](./Unions.ipynb)\n", 28 | "15. [**Header Files**](./HeaderFiles.ipynb)\n", 29 | "16. [**Maps**](./Maps.ipynb)\n", 30 | "\n", 31 | "## Miscellaneous\n", 32 | "1. [**Dev Environment & Setup**](./DevEnvironmentSetup.ipynb)\n", 33 | "2. [**Makefile**](./Makefile.ipynb)\n", 34 | "3. [**Jupyter Notebook & Setup**](./JupyterNotebookSetup.ipynb)\n", 35 | "4. [**Kattis Online Judge & Problem Bank**](./Kattis.ipynb)" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": null, 41 | "metadata": {}, 42 | "outputs": [], 43 | "source": [] 44 | } 45 | ], 46 | "metadata": { 47 | "kernelspec": { 48 | "display_name": "C++14", 49 | "language": "C++14", 50 | "name": "xcpp14" 51 | }, 52 | "language_info": { 53 | "codemirror_mode": "text/x-c++src", 54 | "file_extension": ".cpp", 55 | "mimetype": "text/x-c++src", 56 | "name": "c++", 57 | "version": "14" 58 | } 59 | }, 60 | "nbformat": 4, 61 | "nbformat_minor": 4 62 | } 63 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /demos/arrays/overflow_fixed/overflow_fixed.cpp: -------------------------------------------------------------------------------- 1 | // Authenticator program with fixed buffer overflow vulnearbility 2 | // TODO: Compile and run the program using the given Makefile 3 | // try to get the program print the password without providing the correct username and password 4 | // goal is to display the social security without using the hidden password; but you shouldn't succeeed! 5 | 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | // function reads data one character at a time upto size-1 length 12 | // or '\n' which ever comes first 13 | void readData(char buffer[], unsigned int size) { 14 | char ch; 15 | int i = 0; 16 | bool newLineRead = false; 17 | while (i < size-1) { 18 | cin.get(ch); 19 | if (ch == '\n') { 20 | newLineRead = true; 21 | break; 22 | } 23 | buffer[i++] = ch; 24 | } 25 | buffer[i] = 0; // end the buffer with NULL character 26 | // read and discard the rest of the characters from std input stream upto '\n' 27 | if (not newLineRead) cin.ignore(INT_MAX, '\n'); 28 | } 29 | 30 | int main(int argc, char* argv[]) { 31 | bool valid = false; 32 | char username[10]; //c-string; buffer 33 | char password[10]; //c-string; buffer 34 | 35 | cout << "Enter username: "; 36 | readData(username, 10); // read data checking bounds/size 37 | cout << "Enter password: "; 38 | readData(password, 10); // read data checking bounds/size 39 | 40 | if (string(username) == "backdoor" && strcmp(password, "123456") == 0) 41 | valid = true; 42 | 43 | if (valid) { 44 | cout << "You have now access to the top secret part of the program!" << endl; 45 | cout << "Your social is 123-45-5678\n"; 46 | } 47 | else 48 | cout << "invalid username or password" << endl; 49 | 50 | return 0; 51 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /demos/conditionals/main_arg2/main_arg2.cpp: -------------------------------------------------------------------------------- 1 | // program demonstrates passing arguments to main 2 | // TODO: compile and run the program 3 | #include 4 | #include //strncmp 5 | #include 6 | #include //atof 7 | #include 8 | 9 | using namespace std; 10 | 11 | // templated function computes and returns sum of two numbers 12 | template 13 | T2 sum(T1 n1, T2 n2) { 14 | return n1+n2; 15 | } 16 | 17 | // function prototypes 18 | 19 | // templated function to find product of two numbers 20 | template 21 | T2 product(T1, T2); 22 | 23 | void test(); 24 | void help(string); 25 | 26 | // main takes arguments 27 | int main(int argc, char* argv[]) { 28 | cout << "program adds or multiplies two given numbers.\n"; 29 | string programName = string(argv[0]); 30 | if (argc == 4) { 31 | // program must run with 3 additional arguments, e.g. 32 | // program.exe sum 3 10.5 33 | float arg2, arg3; // block scope variables 34 | arg2 = atof(argv[2]); 35 | arg3 = atof(argv[3]); 36 | // or convert to string type and easily compare using == 37 | if (string(argv[1]) == "sum") 38 | cout << arg2 << " + " << arg3 << " = " << sum(arg2, arg3) << endl; 39 | else if(string(argv[1]) == "product") 40 | cout << arg2 << " * " << arg3 << " = " << product(arg2, arg3) << endl; 41 | else { 42 | cout << "Error: " << argv[1] << " is an invalid argument!\n"; 43 | help(programName); 44 | } 45 | } 46 | // comparing c_string using strncmp function 47 | else if(argc == 2 && strncmp(argv[1], "test", 4) == 0) 48 | test(); 49 | else 50 | help(programName); 51 | 52 | return 0; 53 | } 54 | 55 | // templated function computes and returns product of two numbers 56 | template 57 | T2 product(T1 n1, T2 n2) { 58 | return n1*n2; 59 | } 60 | 61 | void test() { 62 | cerr << "running test cases...\n"; 63 | // NOTe: template parameters don't work in assert() 64 | // type parameters are not required for fundamental types! 65 | assert(sum(10, 20) == 30); 66 | assert(sum(10.5f, 3.5f) == 14); 67 | assert(product(10, 20) == 200); 68 | assert(product(3.5f, 2.0f) == 7); 69 | cerr << "all test cases passed for sum() and product()\n"; 70 | } 71 | 72 | void help(string programName) { 73 | cout << "Usage examples...\n"; 74 | cout << programName << " sum 10 20.5\n"; 75 | cout << programName << " product 15 100\n"; 76 | cout << programName << " test\n"; 77 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /demos/conditionals/menu/menu.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Menu-driven program demo 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | template 15 | T add(T val1, T val2) { 16 | return val1 + val2; 17 | } 18 | 19 | template 20 | T subtract(T val1, T val2) { 21 | return val1 - val2; 22 | } 23 | 24 | template 25 | T larger(T val1, T val2) { 26 | return val1 >= val2?val1:val2; 27 | } 28 | 29 | template 30 | double average(T val1, T val2) { 31 | return add(val1, val2)/2.0; 32 | } 33 | 34 | int getMenuOption() { 35 | // A Smiple CLI-based calculator 36 | int option; 37 | cout << "Enter one of the following menu options: [1-6]\n" 38 | << "1 -> Add\n" 39 | << "2 -> Subtract\n" 40 | << "3 -> Larger\n" 41 | << "4 -> Average\n" 42 | << "5 -> Multiply\n" 43 | << "6 -> Quit\n"; 44 | cin >> option; 45 | return option; 46 | } 47 | 48 | void program() { 49 | float n1, n2; 50 | int option; 51 | option = getMenuOption(); 52 | if (option == 6) { 53 | cout << "Good bye...\n"; 54 | return; 55 | } 56 | cout << "Enter two numbers separated by space: "; 57 | cin >> n1 >> n2; 58 | switch(option) { 59 | case 1: 60 | cout << n1 << " + " << n2 << " = " << add(n1, n2) << endl; 61 | break; // terminate switch 62 | case 2: 63 | cout << n1 << " - " << n2 << " = " << subtract(n1, n2) << endl; 64 | break; 65 | case 3: 66 | cout << "larger between: " << n1 << " and " << n2 << " is " << larger(n1, n2) << endl; 67 | break; 68 | case 4: 69 | cout << "average of " << n1 << " and " << n2 << " = " << average(n1, n2) << endl; 70 | break; 71 | default: 72 | cout << n1 << " x " << n2 << " = " << n1*n2 << endl; 73 | break; 74 | } 75 | } 76 | 77 | int main() { 78 | program(); 79 | return 0; 80 | } -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /demos/file_io/formatted_output.txt: -------------------------------------------------------------------------------- 1 | ================================================= 2 | Item Price 3 | ================================================= 4 | Apple 5.99 5 | Carrots 2.55 6 | ************************************************* 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /demos/file_io/outputfile.txt: -------------------------------------------------------------------------------- 1 | Hello World! 2 | -------------------------------------------------------------------------------- /demos/file_io/outputfile1.txt: -------------------------------------------------------------------------------- 1 | 2 + 2 = 4 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /demos/functions/assert/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 = assert.exe # FIXME 15 | 16 | # list all .cpp files separated by space; files must exist! 17 | CPP_FILES = assertdebug.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 | -------------------------------------------------------------------------------- /demos/functions/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 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /demos/functions/func_prototype/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 = func_prototype.exe # FIXME 15 | 16 | # list all .cpp files separated by space; files must exist! 17 | CPP_FILES = func_prototype.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 | -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /demos/functions/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 -------------------------------------------------------------------------------- /demos/functions/unittest1/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 = unittest.exe 14 | 15 | # list all .cpp files separated by space 16 | CPPFILES = unittesting.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 -------------------------------------------------------------------------------- /demos/functions/unittest1/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 addfunc(int num1, int num2) { 9 | return num1 + num2; 10 | } 11 | 12 | int main() { 13 | int answer; 14 | int num1, num2; 15 | num1 = 100; 16 | num2 = 1199; 17 | answer = addfunc(10, 5); 18 | cout << "answer = " << answer << endl; 19 | assert(answer == 15); 20 | cerr << "first assertion passed\n"; 21 | // directly calling and testing function 22 | assert(addfunc(3, 7) == 10); 23 | cerr << "2nd assertion passed\n"; 24 | // write 2 more test cases... 25 | assert(addfunc(-10, -5) == -15); 26 | assert(addfunc(-5, 5) == 0); 27 | assert(addfunc(num1, num2) == 1299); 28 | cerr << "all test cases passed!\n"; 29 | return 0; 30 | } -------------------------------------------------------------------------------- /demos/functions/unittest2/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 = unittest.exe 14 | 15 | # list all .cpp files separated by space 16 | CPPFILES = unittesting2.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 29 | 30 | run: 31 | ./$(PROGRAM) -------------------------------------------------------------------------------- /demos/functions/unittest2/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 | } -------------------------------------------------------------------------------- /demos/functions/unittest3/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 = unittest.exe 14 | 15 | # list all .cpp files separated by space 16 | CPPFILES = unittesting3.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 29 | 30 | run: 31 | ./$(PROGRAM) -------------------------------------------------------------------------------- /demos/functions/unittest3/unittesting3.cpp: -------------------------------------------------------------------------------- 1 | // unittesting void functions and floating point results 2 | // void function that writes result to a reference parameter 3 | // NOTE - floating point computation may not be precisely accurate! 4 | // Run the program as it is (test fails!) 5 | // FIXME: change type of paramter in product function to double for double precision! 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | // function prototypes 13 | void product(float, float, float &); 14 | void test_product(void); 15 | 16 | const double tolerance = 1e-1; 17 | 18 | int main() { 19 | // call test function 20 | test_product(); 21 | // FIXME: make the program useable by any user... 22 | return 0; 23 | } 24 | 25 | // function multiplies given two numbers and finds the product 26 | // stores the result in product reference variable 27 | void product(float n1, float n2, float &result) { 28 | result = n1 * n2; 29 | // no return! 30 | } 31 | 32 | void test_product(void) { 33 | float answer; 34 | float num1, num2; 35 | num1 = 10.0; 36 | num2 = 20.0; 37 | product(10.0, 20.0, answer); 38 | assert(answer == 200); 39 | num1 = 100.1234; 40 | num2 = 1199.14556; 41 | double expected = 120062.530562; 42 | product(num1, num2, answer); 43 | // let's print the answer to see what it is 44 | // let's print some decimal values 45 | cerr << "answer = " << fixed << setprecision(6) << answer << endl; 46 | assert(fabs(answer-expected) <= tolerance); 47 | // the following assert will fail! 48 | // try: https://www.wolframalpha.com/input/?i=100.1234+*+1199.14556 49 | // try: https://www.google.com/search?q=100.1234*1199.14556&oq=100.1234*1199.14556 50 | // expected answer is provided by google and wolfram alpha 51 | assert(answer == expected); 52 | 53 | cerr << "all test cases passed!\n"; 54 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /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 &); -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /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(); -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /demos/loops/countdown/countdown.cpp: -------------------------------------------------------------------------------- 1 | // A Simple count down to Blast Off program 2 | // Demonstrates count down using both For and While loops 3 | 4 | #include 5 | #include //usleep 6 | #include 7 | 8 | using namespace std; 9 | 10 | // function to clear the screen 11 | void clear() { 12 | // Note: system call is not recommended security best practices in real-world! 13 | #ifdef _WIN32 // if 32 or 64 bit Windows 14 | system("cls"); 15 | #else // assuming mac or linux 16 | system("clear"); 17 | #endif 18 | } 19 | 20 | void pause(float seconds) { 21 | #ifdef _WIN32 // if 32 or 64 bit Windows 22 | Sleep(seconds*1000); // milliseconds 23 | #else // assuming mac or linux 24 | usleep(seconds*1000000); // microseconds 25 | #endif 26 | } 27 | 28 | void countDownForLoop(int N) { 29 | cout << "For Loop Countdown demo...\n"; 30 | cout << "Starting countdown from " << N << endl; 31 | pause(1); 32 | for(int i=N; i>=0; i--) { 33 | clear(); 34 | if (i == 0) { 35 | cout << "Blast Off!!!" << endl; 36 | pause(1); 37 | cout << "#$%@$#RAET$#%#$%EDFAsdf$^@^@#$^FD\n"; 38 | pause(0.5); 39 | cout << "^%$#$@#$^&$^%&$%^#%#$!@*&)!@!@#!DFGSFG%^$GAG\n"; 40 | pause(1); 41 | clear(); 42 | cout << "#$%@$#RAET$#%#$%EDFA$#%@#GAGQ!#%#FD\n"; 43 | pause(1); 44 | clear(); 45 | } 46 | else { 47 | cout << i << endl; 48 | pause(1); 49 | } 50 | } 51 | } 52 | 53 | void countDownWhileLoop(int N) { 54 | cout << "While Loop Countdown demo...\n"; 55 | cout << "Starting countdown from " << N << endl; 56 | pause(2); 57 | while(N >=0) { 58 | clear(); 59 | if (N == 0) { 60 | cout << "Blast Off!!!" << endl; 61 | pause(1.0); 62 | cout << "#$%@$#RAET$#%#$%EDFAsdf$^@^@#$^FD\n"; 63 | pause(0.5); 64 | cout << "^%$#$@#$^&$^%&$%^#%#$!@*&)!@!@#!DFGSFG%^$GAG\n"; 65 | pause(1); 66 | clear(); 67 | cout << "#$%@$#RAET$#%#$%EDFA$#%@#GAGQ!#%#FD\n"; 68 | pause(1); 69 | clear(); 70 | } 71 | else { 72 | cout << N << endl; 73 | pause(1); 74 | } 75 | N--; 76 | } 77 | } 78 | 79 | int main(int argc, char* argv[]) { 80 | if (argc == 2 && string(argv[1]) == "for") 81 | countDownForLoop(10); 82 | else 83 | countDownWhileLoop(10); 84 | return 0; 85 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /demos/maps/letter_frequency/main.cpp: -------------------------------------------------------------------------------- 1 | // Sample solution for Exercise 1 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | // linear search function that searches given key in given map 12 | // returns true if key is found; false otherwise 13 | bool searchMap(const map m, char key) { 14 | auto find = m.find(key); 15 | return (find != m.end()); 16 | } 17 | 18 | void test_searchMap() { 19 | assert(searchMap({{'a', 1}, {'b', 5}, {'!', 1}}, 'a') == true); 20 | assert(searchMap({{'q', 2}, {'Z', 1}}, 'm') == false); 21 | cerr << "all test cases passed for searchMap\n"; 22 | } 23 | 24 | // function finds and returns frequency of each character 25 | void letterFrequency(string text, map & freq) { 26 | for (char ch: text) { 27 | ch = char(tolower(ch)); // make case insensitive 28 | // find each c in freq map 29 | if (searchMap(freq, ch)) // found 30 | freq[ch] += 1; // update frequency by 1 31 | else 32 | freq[ch] = 1; // add new element 33 | } 34 | } 35 | 36 | void test_letterFrequency() { 37 | map ans; 38 | letterFrequency("Hi!", ans); 39 | map expected = {{'!', 1}, {'h', 1}, {'i', 1}}; 40 | assert(ans == expected); 41 | ans.clear(); 42 | letterFrequency("Yo yO", ans); 43 | map expected1 = {{' ', 1}, {'o', 2}, {'y', 2}}; 44 | assert(ans == expected1); 45 | ans.clear(); 46 | letterFrequency("Mississippi", ans); 47 | map expected2 = {{'i', 4}, {'m', 1}, {'p', 2}, {'s', 4}}; 48 | assert(ans == expected2); 49 | cerr << "all test cases passed for letterFrequency()\n"; 50 | } 51 | 52 | int main(int argc, char* argv[]) { 53 | if (argc == 2 and string(argv[1]) == "test" ) { 54 | // run all test cases 55 | test_letterFrequency(); 56 | test_searchMap(); 57 | cerr << "all test cases passed!\n"; 58 | } 59 | else { 60 | string input; 61 | cout << "Enter some text: "; 62 | getline(cin, input); 63 | map answer; 64 | letterFrequency(input, answer); 65 | for(auto pair : answer) { 66 | cout << pair.first << " -> " << pair.second << endl; 67 | } 68 | } 69 | 70 | return 0; 71 | } -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /demos/stdio/carrots/1.ans: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /demos/stdio/carrots/1.in: -------------------------------------------------------------------------------- 1 | 2 1 2 | carrots? 3 | bunnies 4 | -------------------------------------------------------------------------------- /demos/stdio/carrots/2.ans: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /demos/stdio/carrots/2.in: -------------------------------------------------------------------------------- 1 | 1 5 2 | sovl problmz 3 | -------------------------------------------------------------------------------- /demos/stdio/carrots/3.ans: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /demos/stdio/carrots/3.in: -------------------------------------------------------------------------------- 1 | 1000 10 2 | team1 3 | team2 4 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /demos/vectors/splitString/splitString.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | // Solution to Exercise 1 10 | void splitString(vector &words, string text) { 11 | string word; 12 | stringstream ss(text); 13 | while (ss >> word) { 14 | words.push_back(word); 15 | } 16 | } 17 | 18 | void test_splitString() { 19 | vector answer; 20 | splitString(answer, "word"); 21 | vector actual = {"word"}; 22 | assert(answer == actual); 23 | answer.clear(); 24 | splitString(answer, "two word"); 25 | vector actual1 = {"two", "word"}; 26 | assert(answer == actual1); 27 | answer.clear(); 28 | splitString(answer, "A sentence with multiple words!"); 29 | vector actual2 = {"A", "sentence", "with", "multiple", "words!"}; 30 | assert(answer == actual2); 31 | answer.clear(); 32 | cerr << "Congrats! all test cases passed for splitString()\n"; 33 | } 34 | 35 | // printVector function 36 | template 37 | void printVector(const vector& v) { 38 | char comma[3] = {'\0', ' ', '\0'}; 39 | cout << '['; 40 | for (const auto& e: v) { 41 | cout << comma << e; 42 | comma[0] = ','; 43 | } 44 | cout << "]\n"; 45 | } 46 | 47 | int main(int argc, char* argv[]) { 48 | if (argc == 2 and string(argv[1]) == "test") 49 | test_splitString(); 50 | else 51 | { 52 | string data; 53 | cout << "Enter some text: "; 54 | getline(cin, data); 55 | vector tokens; 56 | splitString(tokens, data); 57 | printf("Resulting vector of words:\n"); 58 | printVector(tokens); 59 | } 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /environment.yml: -------------------------------------------------------------------------------- 1 | name: xeus-cling 2 | channels: 3 | - conda-forge 4 | dependencies: 5 | - xeus-cling=0.12.0 6 | - notebook 7 | -------------------------------------------------------------------------------- /exercises/Task - Unit 10.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/exercises/Task - Unit 10.doc -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /exercises/conditionals/vote1/voting_eligibility.cpp: -------------------------------------------------------------------------------- 1 | /*================================================== 2 | US Federal Election Voter Eligibility 3 | Author: Ram Basnet 4 | Copyright: MIT License 5 | 6 | Program determines if someone is eligible to vote in the US Federal Election 7 | 8 | Algorithm steps: 9 | 1. get person's citizenship status 10 | 2. get person's age 11 | 3. determine voter eligibility 12 | - if the person is US citizen and their age is 18 or above they're qualified to vote 13 | ==================================================*/ 14 | #include 15 | #include 16 | 17 | using namespace std; 18 | 19 | int main() { 20 | // variables to store persons's info 21 | string f_name, l_name, us_citizen; 22 | int age; 23 | // greet the user 24 | cout << "Hello there, what's your first and last name? "; 25 | cin >> f_name >> l_name; 26 | cout << "Nice meeting you, " << f_name << '!' << endl; 27 | // 1. get citizenship status 28 | cout << f_name << ", are you a US citizen? Enter [y|yes] or [n|no]: "; 29 | cin >> us_citizen; 30 | // 2. get age 31 | cout << f_name << ", how old are you? "; 32 | cin >> age; 33 | // 3. determine the voting eligibility 34 | if ((us_citizen == "y" || us_citizen == "yes") && age >= 18) 35 | cout << "Congrats, " << f_name << "! You're qualified to vote in the US federal election.\n"; 36 | else 37 | cout << "Sorry, " << f_name << "! You're NOT qualified to vote in the US federal election.\n"; 38 | 39 | cout << "Good bye... " << endl; 40 | 41 | // all done! 42 | return 0; 43 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/header_files/exercise1/exercise1.cpp: -------------------------------------------------------------------------------- 1 | // Sample solution for Exercise 1 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | // linear search function that searches given key in given map 13 | // returns true if key is found; false otherwise 14 | bool searchMap(const map m, char key) { 15 | auto find = m.find(key); 16 | return (find != m.end()); 17 | } 18 | 19 | void test_searchMap() { 20 | assert(searchMap({{'a', 1}, {'b', 5}, {'!', 1}}, 'a') == true); 21 | assert(searchMap({{'q', 2}, {'Z', 1}}, 'm') == false); 22 | cerr << "all test cases passed for searchMap\n"; 23 | } 24 | 25 | // function finds and returns frequency of each character 26 | void letterFrequency(string text, map & freq) { 27 | for (char ch: text) { 28 | ch = char(tolower(ch)); // make case insensitive 29 | // find each c in freq map 30 | if (searchMap(freq, ch)) // found 31 | freq[ch] += 1; // update frequency by 1 32 | else 33 | freq[ch] = 1; // add new element 34 | } 35 | } 36 | 37 | void test_letterFrequency() { 38 | map ans; 39 | letterFrequency("Hi!", ans); 40 | map expected = {{'!', 1}, {'h', 1}, {'i', 1}}; 41 | assert(ans == expected); 42 | ans.clear(); 43 | letterFrequency("Yo yO", ans); 44 | map expected1 = {{' ', 1}, {'o', 2}, {'y', 2}}; 45 | assert(ans == expected1); 46 | ans.clear(); 47 | letterFrequency("Mississippi", ans); 48 | map expected2 = {{'i', 4}, {'m', 1}, {'p', 2}, {'s', 4}}; 49 | assert(ans == expected2); 50 | cerr << "all test cases passed for letterFrequency()\n"; 51 | } 52 | 53 | 54 | int main(int argc, char * argv[]) { 55 | if (argc == 2 && string(argv[1]) == "test") { 56 | test_searchMap(); 57 | test_letterFrequency(); 58 | } 59 | else { 60 | cout << "Enter some text: "; 61 | string input; 62 | getline(cin, input); 63 | map freqency; 64 | letterFrequency(input, freqency); 65 | // print elements of frequency map 66 | for(auto element:freqency) { 67 | cout << element.first << " => " << element.second << endl; 68 | } 69 | } 70 | 71 | return 0; 72 | } -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /exercises/stdio/BMI/main.cpp: -------------------------------------------------------------------------------- 1 | /*================================================== 2 | BMI Calculator 3 | Author: Ram Basnet 4 | Copyright: MIT License 5 | 6 | Program finds Body Mass Index (BMI) of a person 7 | 8 | Algorithm steps: 9 | 1. get person's height 10 | - convert height into inches 11 | 2. get person's weight in pounds (lbs) 12 | 3. calculate BMI using formula: 13 | - BMI = 703 x weight (lbs) / [height (in)]^2 14 | 4. display the result 15 | 5. interpret the result as: 16 | Underweight = <18.5 17 | Normal weight = 18.5–24.9 18 | Overweight = 25–29.9 19 | Obesity = BMI of 30 or greater 20 | 21 | ==================================================*/ 22 | 23 | #include 24 | #include 25 | 26 | using namespace std; 27 | 28 | #define INCHES_IN_FOOT 12 29 | 30 | int main() { 31 | // variables to store persons's info 32 | string f_name, l_name; 33 | int feet, inches, height_in_inches; 34 | float weight_in_pounds, BMI; 35 | // greet the user 36 | cout << "Hello there, what's your first and last name? "; 37 | cin >> f_name >> l_name; 38 | cout << "Nice meeting you, " << f_name << '!' << endl; 39 | // 1. get height 40 | cout << f_name << ", what is your height?\n" 41 | << "\tEnter feet inches, e.g. if you're 5'6\", enter 5 6: "; 42 | cin >> feet >> inches; 43 | // 1.a convert height into inches 44 | height_in_inches = feet*INCHES_IN_FOOT + inches; 45 | // 2. get weight in lbs 46 | cout << f_name << ", now enter your weight in lbs: "; 47 | cin >> weight_in_pounds; 48 | // 3. calculate BMI 49 | BMI = 703*weight_in_pounds/(height_in_inches*height_in_inches); 50 | cout << "Your BMI report card\n"; 51 | cout << "=======================\n"; 52 | cout << "Name: " << f_name << " " << l_name << endl; 53 | cout << "Height: " << feet << "'" << inches << "\"\n"; 54 | cout << "Weight: " << weight_in_pounds << " lbs" << endl; 55 | cout << "BMI: " << BMI << endl; 56 | cout << "=======================\n"; 57 | // FIXME: step #5 58 | 59 | cout << "Thank you for using my BMI Calculator, " << f_name << "!\nGood bye..." << endl; 60 | 61 | // all done! 62 | return 0; 63 | } -------------------------------------------------------------------------------- /exercises/stdio/hangman/Hangman-README.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/exercises/stdio/hangman/Hangman-README.pdf -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /inputfile.txt: -------------------------------------------------------------------------------- 1 | this is first sentence. 2 | this is 2nd sentence 3 | some numbers are below 4 | 10 5 | 20 6 | 30 7 | -------------------------------------------------------------------------------- /inputfile_copy.txt: -------------------------------------------------------------------------------- 1 | this is first sentence. 2 | this is 2nd sentence 3 | some numbers are below 4 | 10 5 | 20 6 | 30 7 | -------------------------------------------------------------------------------- /labs/arrays/modulo/1.ans: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /labs/arrays/modulo/1.in: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | -------------------------------------------------------------------------------- /labs/arrays/modulo/2.ans: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /labs/arrays/modulo/2.in: -------------------------------------------------------------------------------- 1 | 42 2 | 84 3 | 252 4 | 420 5 | 840 6 | 126 7 | 42 8 | 84 9 | 420 10 | 126 11 | -------------------------------------------------------------------------------- /labs/arrays/modulo/3.ans: -------------------------------------------------------------------------------- 1 | 6 2 | -------------------------------------------------------------------------------- /labs/arrays/modulo/3.in: -------------------------------------------------------------------------------- 1 | 39 2 | 40 3 | 41 4 | 42 5 | 43 6 | 44 7 | 82 8 | 83 9 | 84 10 | 85 11 | -------------------------------------------------------------------------------- /labs/arrays/modulo/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 | 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 | # FIXME1 29 | # add a rule to run the program 30 | 31 | unittest: 32 | ./$(PROGRAM) test 33 | 34 | # FIXME2 - add 4 more commands to test the 4 input files 35 | kattis_test: 36 | cat 1.in | ./$(PROGRAM) | diff - 1.ans 37 | cat 2.in | ./$(PROGRAM) | diff - 2.ans 38 | @#FIXME - Add commands to test 4 more input files 39 | @echo "All kattis test cases passed!" 40 | 41 | all: build unitest kattis_test clean 42 | @echo "All done!" 43 | -------------------------------------------------------------------------------- /labs/arrays/numbers/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 | 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 unittest clean 32 | @printf "All done!\n" 33 | -------------------------------------------------------------------------------- /labs/conditionals/menu/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/conditionals/menu/README.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/labs/conditionals/menu/README.docx -------------------------------------------------------------------------------- /labs/conditionals/twostones/1.ans: -------------------------------------------------------------------------------- 1 | Alice 2 | -------------------------------------------------------------------------------- /labs/conditionals/twostones/1.in: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /labs/conditionals/twostones/2.ans: -------------------------------------------------------------------------------- 1 | Bob 2 | -------------------------------------------------------------------------------- /labs/conditionals/twostones/2.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/labs/conditionals/twostones/2.in -------------------------------------------------------------------------------- /labs/conditionals/twostones/3.ans: -------------------------------------------------------------------------------- 1 | Alice 2 | -------------------------------------------------------------------------------- /labs/conditionals/twostones/3.in: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /labs/conditionals/twostones/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 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 | 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 | # FIXME1 29 | # add a rule to run the program 30 | 31 | unittest: 32 | ./$(PROGRAM) test 33 | 34 | # FIXME2 - add 4 more commands to test the 4 input files 35 | test: 36 | cat 1.in | ./$(PROGRAM) | diff - 1.ans 37 | cat 2.in | ./$(PROGRAM) | diff - 2.ans 38 | cat 3.in | ./$(PROGRAM) | diff - 3.ans 39 | @#FIXME - Add commands to test 4 more input files 40 | @echo "All test cases passed!" 41 | 42 | all: build test clean 43 | @echo "All done!" -------------------------------------------------------------------------------- /labs/conditionals/twostones/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Kattis - Take Two Stones 3 | Conditional Logic Lab 4 | Updated By: FIXME 5 | CSCI 111 6 | Date: FIXME 7 | 8 | Read and solve the Kattis problem: https://open.kattis.com/problems/twostones 9 | 10 | Algorithm Steps: 11 | 1. Read the number of stones 12 | 2. Check if the number of stones is odd or even 13 | 3.a. If the number is odd, Alice wins. 14 | 3.b. Otherwise, Bob wins. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | // Function prototypes 23 | // given a positive integer, the function finds and returns 'even' or 'odd' 24 | string oddOrEven(const int unsigned); 25 | // function to test oddOrEven function 26 | void testOddOrEven(); 27 | // given a positive integer, function returns the answer as expected by Kattis 28 | string answer(const int unsigned); 29 | 30 | int main(int argc, char* argv[]) { 31 | if (argc == 2 and string(argv[1]) == string("test")) { 32 | // FIXME1: call testOddOrEven function that unit tests oddOrEven function 33 | // FIXME2: call the test function that unit tests answer function 34 | } 35 | else { 36 | unsigned int stones=0; 37 | // FIXME3: readin the stones 38 | cout << answer(stones) << endl; 39 | } 40 | return 0; 41 | } 42 | 43 | string oddOrEven(const int unsigned number) { 44 | // FIXME4: if the number divided by 2 has 0 remainder, return 'even' 45 | // otherwise, return 'odd' 46 | return "odd"; 47 | } 48 | 49 | string answer(const int unsigned stone) { 50 | string evenorodd = oddOrEven(stone); 51 | if (evenorodd == "odd") return "Alice"; 52 | else return "Bob"; 53 | } 54 | 55 | void testOddOrEven() { 56 | int unsigned number; 57 | number = 99999; 58 | assert(oddOrEven(number) == "odd"); 59 | // FIXME5: Write 2nd test case 60 | // FIXME6: Write 3rd test case 61 | cerr << "All test cases passed for oddOrEven() !\n"; 62 | } 63 | 64 | // FIXME7: Write a function to test answer function 65 | // Write at least 3 test cases 66 | -------------------------------------------------------------------------------- /labs/fileio/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 = fileio.exe 12 | 13 | # list .cpp files separated by space 14 | CPPFILES = fileio.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 | 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 | # rule to run unittest 32 | unittest: 33 | ./$(PROGRAM) "test" 34 | 35 | all: build unittest clean 36 | @echo "All done!" 37 | -------------------------------------------------------------------------------- /labs/fileio/input.txt: -------------------------------------------------------------------------------- 1 | 100 2 | 10 3 | 5 4 | 0 5 | -99 6 | 10 7 | 99 8 | -------------------------------------------------------------------------------- /labs/fileio/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/lastproblem/1.ans: -------------------------------------------------------------------------------- 1 | Thank you, Twilight, and farewell! 2 | -------------------------------------------------------------------------------- /labs/functions/lastproblem/1.in: -------------------------------------------------------------------------------- 1 | Twilight 2 | -------------------------------------------------------------------------------- /labs/functions/lastproblem/2.ans: -------------------------------------------------------------------------------- 1 | Thank you, Luster, and farewell! 2 | -------------------------------------------------------------------------------- /labs/functions/lastproblem/2.in: -------------------------------------------------------------------------------- 1 | Luster 2 | -------------------------------------------------------------------------------- /labs/functions/lastproblem/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 = 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 | 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 | 31 | test: 32 | cat 1.in | ./$(PROGRAM) | diff - 1.ans 33 | cat 2.in | ./$(PROGRAM) | diff - 2.ans 34 | @#FIXME - Add commands to test 4 more input files 35 | @echo "All test cases passed!" 36 | 37 | -------------------------------------------------------------------------------- /labs/functions/lastproblem/main.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 | using namespace std; 20 | 21 | // Function prototypes 22 | // Function finds the answer from given string and restuns the result as a string 23 | string twilight(const string&); 24 | // Function reads the data from standard input and returns the data 25 | string readData(); 26 | 27 | int main() 28 | { 29 | string input = "input"; 30 | // step1. read data 31 | input = readData(); 32 | // FIXME1: Call twilight function passing input as an argument 33 | // store the returned result into answer variable 34 | string answer = input; 35 | // print answer 36 | printf("%s\n", answer.c_str()); 37 | return 0; 38 | } 39 | 40 | // Function implementation 41 | string readData() { 42 | string input; 43 | // FIXME2: using getline reade and store the data into input variable 44 | // FIXME3 return input data 45 | return "FIXME"; 46 | } 47 | 48 | // Function implementation 49 | string twilight(const string& input) { 50 | string ans = "Thank you, " + input + ", and farewell!"; 51 | return ans; 52 | } 53 | -------------------------------------------------------------------------------- /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 = 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 | 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/functions/library/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Library Functions Lab 3 | Updated By: FIXME 4 | CSCI 111 5 | Date: FIXME 6 | 7 | Program prompts user to enter a decimal number. It then finds various trig and mathematical values 8 | of the number using library functions and prints the results using cstdio's printf function. 9 | 10 | Algorithm: 11 | 1. Prompt user to enter a decmial number 12 | 2. Store the number into a variable 13 | 3. Find and print various results form the number 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | #include // various math functions: https://cplusplus.com/reference/cmath 20 | using namespace std; 21 | 22 | int main() 23 | { 24 | double number, result; 25 | 26 | cout << "Program calculates various results from a given number" << endl; 27 | cout << "Enter a decimal number: "; 28 | cin >> number; 29 | // Find ceiling of the number 30 | result = ceil(number); 31 | printf("ceiling(%f) = %.1f\n", number, result); 32 | // Find floor of the number 33 | result = floor(number); 34 | printf("Floor(%f) = %.1f\n", number, result); 35 | //FIXME3 - Using library function, find and print the square root of the number upto 2 decimal points 36 | //FIXME4 - Using library function, find and print the cube root of the number upto 2 decimal points 37 | //FIXME5 - Using library function, find and print the 10th power of the number upto 2 decimal points 38 | //FIXME6 - Using library function, find and print the log_2 of the number upto 2 decimal points 39 | //FIXME7 - Using library function, find and print the log_10 of the number upto 2 decimal points 40 | //FIXME8 - Convert number into radians and store into a variable 41 | //FIXME9 - Using library function, find and print the sine of the radian value in FIXME 8 upto 2 decimal points 42 | //FIXME10 - Using library function, find and print the cosine of the radian value in FIXME 8 upto 2 decimal points 43 | 44 | cin.ignore(1000, '\n'); 45 | cout << "Enter to quit the program: "; 46 | cin.get(); 47 | cout << "Good bye..." << endl; 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /labs/intro/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/intro/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ASCII Lab 3 | ASCII Art and Standard Input/Ouput 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. Write a series of cout statements to print the ASCII art. 12 | */ 13 | 14 | #include //library for input and output 15 | #include 16 | 17 | using namespace std; //resolve cout, cin, and endl names 18 | 19 | //main entry point of the program 20 | int main() 21 | { 22 | 23 | cout << "Hi there!" << endl; 24 | cout << "Hope you like my Tom & Jerry ASCII art...\n\n"; 25 | 26 | // Declare line1 variable of string type and assign the art for line1 27 | string line1 = " |\\_/| ********************** (\\_/)"; 28 | // Declare line2 variable of string type and assign the art for line2 29 | string line2 = " / @ @ \\ * ASCII Lab * (=\'.\'=)"; 30 | // print line1 31 | cout << line1 << endl; 32 | // print line2 33 | cout << line2 << endl; 34 | 35 | //FIXME3: Declare line3 variable, assign the art for the 3rd line and print the variable 36 | //FIXME4: Declare line4 variable, assign the art for the 4th line and print the variable 37 | //FIXME5: Declare line5 variable, assign the art for the 5th line and print the variable 38 | 39 | cout << "\nGood bye... hit enter to exit the program: " << '\n'; 40 | // make the console wait for user input 41 | cin.get(); 42 | return 0; //exit program by returning 0 status to the system 43 | } -------------------------------------------------------------------------------- /labs/loops/doggopher/1.ans: -------------------------------------------------------------------------------- 1 | The gopher cannot escape. 2 | -------------------------------------------------------------------------------- /labs/loops/doggopher/1.in: -------------------------------------------------------------------------------- 1 | 1.000 1.000 2.000 2.000 2 | 1.500 1.500 3 | -------------------------------------------------------------------------------- /labs/loops/doggopher/2.ans: -------------------------------------------------------------------------------- 1 | The gopher can escape through the hole at (2.500,2.500). 2 | -------------------------------------------------------------------------------- /labs/loops/doggopher/2.in: -------------------------------------------------------------------------------- 1 | 2.000 2.000 1.000 1.000 2 | 1.500 1.500 3 | 2.500 2.500 4 | -------------------------------------------------------------------------------- /labs/loops/doggopher/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 | 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 | # FIXME1 29 | # add a rule to run the program 30 | 31 | unittest: 32 | ./$(PROGRAM) test 33 | 34 | # FIXME2 - add 4 more commands to test the 4 input files 35 | test: 36 | cat 1.in | ./$(PROGRAM) | diff - 1.ans 37 | cat 2.in | ./$(PROGRAM) | diff - 2.ans 38 | @#FIXME - Add commands to test 4 more input files 39 | @echo "All test cases passed!" 40 | 41 | all: build test clean 42 | @echo "All done!" -------------------------------------------------------------------------------- /labs/loops/shapes/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/maps/baconeggsandspam/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/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/maps/morsecodepalindromes/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # g++ compiler flags 4 | # -g: adds debugging information to the executable binary 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 = a.out #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 code 18 | # then make a single binary/executable code 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 | unittest: 29 | ./$(PROGRAM) test 30 | 31 | # test the kattis provided samples 32 | kattis_test: # FIXME - add commands to test 2 more sample files 33 | cat ./sample_tests/1.in | ./$(PROGRAM) | diff - ./sample_tests/1.ans 34 | cat ./sample_tests/2.in | ./$(PROGRAM) | diff - ./sample_tests/2.ans 35 | cat ./sample_tests/3.in | ./$(PROGRAM) | diff - ./sample_tests/3.ans 36 | cat ./sample_tests/4.in | ./$(PROGRAM) | diff - ./sample_tests/4.ans 37 | cat ./sample_tests/5.in | ./$(PROGRAM) | diff - ./sample_tests/5.ans 38 | cat ./sample_tests/6.in | ./$(PROGRAM) | diff - ./sample_tests/6.ans 39 | @echo "All Test Cases Passed!" 40 | 41 | all: build unittest kattis_test clean 42 | @echo "All done!" 43 | 44 | 45 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/sample_tests/0.ans: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/sample_tests/0.in: -------------------------------------------------------------------------------- 1 | hello 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/sample_tests/1.ans: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/sample_tests/1.in: -------------------------------------------------------------------------------- 1 | 159 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/sample_tests/2.ans: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/sample_tests/2.in: -------------------------------------------------------------------------------- 1 | Madam I'm Adam 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/sample_tests/3.ans: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/sample_tests/3.in: -------------------------------------------------------------------------------- 1 | footstool 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/sample_tests/4.ans: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/sample_tests/4.in: -------------------------------------------------------------------------------- 1 | SOS 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/sample_tests/5.ans: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/sample_tests/5.in: -------------------------------------------------------------------------------- 1 | A E 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/sample_tests/6.ans: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /labs/maps/morsecodepalindromes/sample_tests/6.in: -------------------------------------------------------------------------------- 1 | % ! & 2 | -------------------------------------------------------------------------------- /labs/maps/sevenwonders/Makefile: -------------------------------------------------------------------------------- 1 | # compiler name 2 | CXX = g++ 3 | # g++ compiler flags 4 | # -g: adds debugging information to the executable binary 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 = a.out #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 code 18 | # then make a single binary/executable code 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 | unittest: 29 | ./$(PROGRAM) test 30 | 31 | # test the kattis provided samples 32 | kattis_test: # FIXME - add commands to test 2 more sample files 33 | cat ./sample_tests/1.in | ./$(PROGRAM) | diff - ./sample_tests/1.ans 34 | cat ./sample_tests/2.in | ./$(PROGRAM) | diff - ./sample_tests/2.ans 35 | cat ./sample_tests/3.in | ./$(PROGRAM) | diff - ./sample_tests/3.ans 36 | 37 | @echo "All Test Cases Passed!" 38 | 39 | all: build unittest kattis_test clean 40 | @echo "All done!" 41 | 42 | 43 | -------------------------------------------------------------------------------- /labs/maps/sevenwonders/sample_tests/1.ans: -------------------------------------------------------------------------------- 1 | 21 2 | -------------------------------------------------------------------------------- /labs/maps/sevenwonders/sample_tests/1.in: -------------------------------------------------------------------------------- 1 | TCGTTC 2 | -------------------------------------------------------------------------------- /labs/maps/sevenwonders/sample_tests/2.ans: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /labs/maps/sevenwonders/sample_tests/2.in: -------------------------------------------------------------------------------- 1 | CCC 2 | -------------------------------------------------------------------------------- /labs/maps/sevenwonders/sample_tests/3.ans: -------------------------------------------------------------------------------- 1 | 26 2 | -------------------------------------------------------------------------------- /labs/maps/sevenwonders/sample_tests/3.in: -------------------------------------------------------------------------------- 1 | TTCCGG 2 | -------------------------------------------------------------------------------- /labs/math/addtwonumbers/1.ans: -------------------------------------------------------------------------------- 1 | 7 2 | -------------------------------------------------------------------------------- /labs/math/addtwonumbers/1.in: -------------------------------------------------------------------------------- 1 | 3 4 2 | -------------------------------------------------------------------------------- /labs/math/addtwonumbers/2.ans: -------------------------------------------------------------------------------- 1 | 1010 2 | -------------------------------------------------------------------------------- /labs/math/addtwonumbers/2.in: -------------------------------------------------------------------------------- 1 | 987 23 2 | -------------------------------------------------------------------------------- /labs/math/addtwonumbers/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 | 31 | # FIXME - add 4 more commands to test the 4 input files 32 | test: 33 | cat 1.in | ./$(PROGRAM) | diff - 1.ans 34 | cat 2.in | ./$(PROGRAM) | diff - 2.ans 35 | @#FIXME - Add commands to test 4 more input files 36 | @echo "All test cases passed!" -------------------------------------------------------------------------------- /labs/math/addtwonumbers/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Kattis Add Two Numbers Lab 3 | By: FIXME 4 | CSCI 111 5 | Date: FIXME 6 | 7 | Read and Solve Add Two Numbers: https://open.kattis.com/problems/addtwonumbers 8 | 9 | Algorithm steps: 10 | 1. Read two numbers 11 | 2. Add them up and print the result 12 | */ 13 | 14 | #include 15 | 16 | using namespace std; 17 | 18 | int main() 19 | { 20 | // declare variables to store input data and answer 21 | int a, b, ans; 22 | cin >> a; 23 | 24 | // FIXME1: Read the 2nd number 25 | // FIXME2: add two numbers and store the result into ans variable 26 | // FIXME3: print the answer 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /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/math/circle/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Circle Lab 3 | By: FIXME1 4 | CSCI 111 5 | Date: FIXME2 6 | 7 | This program prompts the user to enter the radius of a circle. 8 | It then calculates and displays its area and circumference. 9 | 10 | Algorithm steps: 11 | 1. Prompt user to enter radius of a circle and store the radius into a variable 12 | 2. Calculate area using the formula pi x radius x radius and store the value into a variable 13 | 3. Calculate circumference using the formula 2 x pi x radius and store the value into a variable 14 | 4. Output the calculated values for area and circumference 15 | */ 16 | 17 | #include //library for common input, output and formatting 18 | #include // library for string type 19 | #include //library for pow and other math functions 20 | #include // library for output formatting: setprecision() 21 | 22 | using namespace std; //this line resolves cout, cin, endl, etc. 23 | 24 | int main() //main entry function that returns 0 25 | { 26 | const double pi = 3.14159; 27 | // variables declared and initialized 28 | double radius=0, area=0, circumference=0; 29 | 30 | string name = "Anonymous"; // variable to store user's name 31 | cout << "Hi there, what's your full name? "; 32 | // FIXME3: using getline function, read user's fullname and store it into name variable 33 | 34 | cout << "Nice meeting you, " << name << "!" << endl; 35 | 36 | // display some information about this program to the user 37 | cout << "\nProgram finds area and circumference of a circle with the given radius.\n"; 38 | cout << string(75, '=') << endl << endl; 39 | 40 | // prompt user telling what to do 41 | cout << name << ", please enter radius of a circle: "; 42 | cin >> radius; //read the entered value and store it into radius variable 43 | 44 | area = pi * pow(radius, 2); // same as: area = pi * radius * radius; 45 | //FIXME4: calculate circumference and store it into the circumference variable 46 | 47 | cout << "Your circle has radius: " << fixed << setprecision(6) << radius << endl; 48 | cout << "Area of the circle is:\t" << area << '\n'; 49 | //FIXME5: print the calculated value of circumference 50 | 51 | // the following code may be required to make your console pause... 52 | cout << "Good bye...\nHit enter to exit the program!" << '\n'; 53 | cin.ignore(1000, '\n'); //ignore 1000 chars or until \n whichever comes first 54 | // make the console wait for user input 55 | cin.get(); 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /labs/pointers/pointersNamespace/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 = pointers.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 | # FIXME 29 | # add a rule to run the program 30 | 31 | # FXIME 32 | # add a rule to run the program for unittesting 33 | 34 | all: build unittest clean 35 | @printf "All done!\n" 36 | -------------------------------------------------------------------------------- /labs/pointers/timeloop/1.ans: -------------------------------------------------------------------------------- 1 | 1 Abracadabra 2 | 2 Abracadabra 3 | 3 Abracadabra 4 | 4 Abracadabra 5 | 5 Abracadabra 6 | -------------------------------------------------------------------------------- /labs/pointers/timeloop/1.in: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /labs/pointers/timeloop/2.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/pointers/timeloop/2.in: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /labs/pointers/timeloop/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 | 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 | # FIXME1 29 | # add a rule to run the program 30 | 31 | unittest: 32 | ./$(PROGRAM) test 33 | 34 | # FIXME2 - add 4 more commands to test the 4 input files 35 | kattistest: 36 | cat 1.in | ./$(PROGRAM) | diff - 1.ans 37 | cat 2.in | ./$(PROGRAM) | diff - 2.ans 38 | @#FIXME - Add commands to test 4 more input files 39 | @printf "All test cases passed!\n" 40 | 41 | all: build unittest clean 42 | @printf "All done!\n" 43 | -------------------------------------------------------------------------------- /labs/pointers/timeloop/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Kattis - Stuck In A Time Loop 3 | Loop Lab 4 | Updated By: FIXME 5 | CSCI 111 6 | Date: FIXME 7 | 8 | Read and solve the Kattis problem: https://open.kattis.com/problems/timeloop 9 | 10 | Algorithm Steps: 11 | 1. Using a function, read and return N 12 | 2. Declare a dynamic variable to store, N returned by function in 1. 13 | 3. Define a function to get the necessary spell given N 14 | 4. Define a function to print answer 15 | 4.i Within the function, use a loop to call spell function to print spell N times: 16 | 1 Abracadabra 17 | 2 Abracadabra 18 | ... 19 | N Abracadabra 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | using namespace std; 29 | 30 | // declare alias pos_short of type "unsigned int" 31 | using pos_short = unsigned short; 32 | 33 | // Function taken an integer n and returns 34 | // spell: n Abracadabra 35 | string spell(const pos_short); 36 | 37 | // function to test spell function 38 | void testSpell(); 39 | 40 | // function to print the final answer 41 | void printAnswer(const pos_short); 42 | 43 | // function to read N 44 | pos_short readNumber(); 45 | 46 | int main(int argc, char* argv[]) { 47 | if (argc == 2 and string(argv[1]) == string("test")) { 48 | // FIXME1: call testSpell function 49 | return 0; 50 | } 51 | // declare a dynamic variable to store N 52 | pos_short *N = new pos_short; 53 | //FIXME2: Call readNumber function and assign the returned value to N; 54 | //FIXME3: Call answer function passing proper argument 55 | } 56 | 57 | pos_short readNumber() { 58 | //FIXME4: Declare a dynamic variable to read and store N and return it 59 | pos_short *N; 60 | return *N; 61 | } 62 | 63 | string spell(pos_short n) { 64 | return to_string(n) + " Abracadabra"; 65 | } 66 | 67 | void testSpell() { 68 | pos_short * n = new pos_short; 69 | *n = 10; 70 | assert(spell(*n) == "10 Abracadabra"); 71 | // FIXME5: Add two more test cases 72 | delete n; 73 | cerr << "Yay... all test cases passed!\n"; 74 | } 75 | 76 | void printAnswer(const pos_short N) { 77 | for(pos_short i=1; i<=N; i++) { 78 | printf("%s\n", spell(i).c_str()); 79 | } 80 | } -------------------------------------------------------------------------------- /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/stdio/ascii1/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | StdIO Lab 3 | ASCII Art - using literals and 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 data/values 13 | */ 14 | 15 | #include //library for input and output 16 | #include //library for string data 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: prompt user to enter their name and store the value into name variable using getline function 25 | 26 | //FIXME5: greet the name using the variable as the following output 27 | //must output: Nice meeting you, ! 28 | 29 | cout << "Hope you like my Tom & Jerry ASCII art...\n\n"; 30 | 31 | string line1 = " |\\_/| ********************** (\\_/)\n"; 32 | cout << line1; 33 | 34 | //FIXME6: use variable to print the second line line of the graphic 35 | //FIXME7: print the third line of the graphics 36 | //FIXME8: use variable to print the fourth line 37 | //FIXME9: use variable to print the fifth line 38 | //Note: You can add more lines or print more ASCII arts of your choice if you'd like... 39 | 40 | cout << "\nGood bye... hit enter to exit the program: " << '\n'; 41 | //FIXME10: make the console wait for user input 42 | 43 | return 0; //exit program by returning 0 status to the system 44 | } -------------------------------------------------------------------------------- /labs/stdio/ascii2/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 = stdio.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 | 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/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/strings/hissingmicrophone/sample_tests/1.ans: -------------------------------------------------------------------------------- 1 | hiss 2 | -------------------------------------------------------------------------------- /labs/strings/hissingmicrophone/sample_tests/1.in: -------------------------------------------------------------------------------- 1 | amiss 2 | -------------------------------------------------------------------------------- /labs/strings/hissingmicrophone/sample_tests/2.ans: -------------------------------------------------------------------------------- 1 | no hiss 2 | -------------------------------------------------------------------------------- /labs/strings/hissingmicrophone/sample_tests/2.in: -------------------------------------------------------------------------------- 1 | octopuses 2 | -------------------------------------------------------------------------------- /labs/strings/hissingmicrophone/sample_tests/3.ans: -------------------------------------------------------------------------------- 1 | hiss 2 | -------------------------------------------------------------------------------- /labs/strings/hissingmicrophone/sample_tests/3.in: -------------------------------------------------------------------------------- 1 | hiss 2 | -------------------------------------------------------------------------------- /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/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/strings/simonsays/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Kattis - Simon Says 3 | 4 | Updated By: FIXME 5 | Date: FIXME 6 | 7 | Problem Statement: https://open.kattis.com/problems/simonsays 8 | Algorithm steps: 9 | 1. Read N 10 | 2. Loop N times: 11 | i. Read a line 12 | ii. If the line starts with "Simon says", 13 | print the rest of the string. Note: print the leading space after says as well! 14 | iii. Otherwise, skip the line 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | using namespace std; 22 | 23 | // function prototypes 24 | string answer(const string &line); 25 | void testAnswer(); 26 | void solve(); 27 | 28 | int main(int argc, char* argv[]) { 29 | if (argc == 2 and string(argv[1]) == "test") { 30 | // FIXME1: call testAnswer function 31 | } 32 | else 33 | solve(); 34 | } 35 | 36 | string answer(const string &line) { 37 | // FIXME2: If the line starts with "Simon says", return rest of the line after says 38 | // including the space after says, otherwise return empty string "" 39 | // Hint: use find method on line object 40 | return ""; 41 | } 42 | 43 | // unit testing answer() 44 | void testAnswer() { 45 | string ans = answer("Simon says laugh!"); 46 | // let's double check what the returned answer is 47 | cerr << "ans = " << ans << endl; 48 | assert(ans == " laugh!"); 49 | assert(answer("Write more programs.") == ""); 50 | // FIXME3: write at least two test cases to test answer() 51 | cerr << "All test cases passed!\n"; 52 | } 53 | 54 | // solving the problem for kattis 55 | void solve() { 56 | string ans="", line=""; 57 | int N; 58 | cin >> N; 59 | //FIXME4 : read and discard \n left behind 60 | while (N--) { 61 | // Note: i. string consists of phrase with spaces 62 | // ii. don't print an empty line if the line doesn't start with "Simon says" 63 | // FIXME5: read the whole line into line 64 | // FIXME6: call answer function and store the returned value into ans 65 | if (ans == "") continue; 66 | // FIXME7: print ans 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /labs/strings/simonsays/sample_tests/1.ans: -------------------------------------------------------------------------------- 1 | smile. 2 | -------------------------------------------------------------------------------- /labs/strings/simonsays/sample_tests/1.in: -------------------------------------------------------------------------------- 1 | 1 2 | Simon says smile. 3 | -------------------------------------------------------------------------------- /labs/strings/simonsays/sample_tests/2.ans: -------------------------------------------------------------------------------- 1 | raise your right hand. 2 | raise your left hand. 3 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /labs/strings/simonsays/sample_tests/3.ans: -------------------------------------------------------------------------------- 1 | raise your left hand. 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/unittest/triangleArea/1.ans: -------------------------------------------------------------------------------- 1 | 0.5 2 | -------------------------------------------------------------------------------- /labs/unittest/triangleArea/1.in: -------------------------------------------------------------------------------- 1 | 1 1 2 | -------------------------------------------------------------------------------- /labs/unittest/triangleArea/2.ans: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /labs/unittest/triangleArea/2.in: -------------------------------------------------------------------------------- 1 | 2 2 2 | -------------------------------------------------------------------------------- /labs/unittest/triangleArea/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 | CPPFILES = main.cpp 8 | 9 | all: 10 | $(CXX) $(CXXFLAGS) $(CPPFILES) 11 | $(CXX) -o $(PROGRAM) *.o 12 | 13 | run: 14 | ./$(PROGRAM) 15 | 16 | # make clean rule 17 | # delete object and binary files 18 | clean: 19 | rm -f $(PROGRAM) *.o 20 | 21 | test: 22 | @echo "diff doesn't work correctly on floating point numbers, e.g. 5.0 and 5.0000000 are different!" 23 | @echo "stick to unit testing!" 24 | -------------------------------------------------------------------------------- /labs/unittest/triangleArea/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Kattis - Triangle Area problem 3 | Function and Unit Testing 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 | 2.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 //assert function 21 | #include 22 | using namespace std; 23 | 24 | // Function prototypes 25 | // Function finds the answer from given string and restuns the result as a string 26 | float areaOfTriangle(const unsigned height, const unsigned base); 27 | // function to test area function 28 | void testArea(); 29 | 30 | #define MAX_ERROR 1e-7 // 10^-7 or 0.0000001 31 | 32 | int main() 33 | { 34 | // call testArea function 35 | testArea(); 36 | unsigned height, base; 37 | float answer; 38 | // read height and base into corresponding variables 39 | cin >> height >> base; 40 | // FIXME1: Call area function passing proper arguments 41 | // store the returned result into answer variable 42 | answer = 0; 43 | // print answer 44 | printf("%.7f\n", answer); 45 | return 0; 46 | } 47 | 48 | // Function implementation 49 | float areaOfTriangle(const unsigned height, const unsigned base) { 50 | float area = 0; 51 | // FIXME2: Find the area of traingle using the formular given in algorithm step: 2.a 52 | // store the area into area variable 53 | return area; 54 | } 55 | 56 | // function to test area function 57 | void testArea() { 58 | unsigned height, base; 59 | float answer, expected; 60 | height = 10; 61 | base = 5; 62 | answer = areaOfTriangle(height, base); 63 | expected = 25.0; 64 | assert(abs(answer-expected) < MAX_ERROR); 65 | // FIXME3: Write 2nd test case 66 | // FIXME4: Write 3rd test case 67 | // FIXME5: Write 4th test case 68 | cerr << "All test cases passed!\n"; 69 | } 70 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/vectors/foxsays/1.ans: -------------------------------------------------------------------------------- 1 | wa pa pa pa pa pa pow 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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!" -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /latex/resources/BuildingBlocks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/BuildingBlocks.png -------------------------------------------------------------------------------- /latex/resources/CPPDevelopment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/CPPDevelopment.png -------------------------------------------------------------------------------- /latex/resources/Cartesian-coordinates.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/Cartesian-coordinates.png -------------------------------------------------------------------------------- /latex/resources/Compiler.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/Compiler.png -------------------------------------------------------------------------------- /latex/resources/Do-While-Loop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/Do-While-Loop.png -------------------------------------------------------------------------------- /latex/resources/For-Loop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/For-Loop.png -------------------------------------------------------------------------------- /latex/resources/Intrepreter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/Intrepreter.png -------------------------------------------------------------------------------- /latex/resources/Map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/Map.png -------------------------------------------------------------------------------- /latex/resources/VariablesAndMemory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/VariablesAndMemory.png -------------------------------------------------------------------------------- /latex/resources/While-Loop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/While-Loop.png -------------------------------------------------------------------------------- /latex/resources/array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/array.png -------------------------------------------------------------------------------- /latex/resources/chess-board.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/chess-board.jpg -------------------------------------------------------------------------------- /latex/resources/ifelsestatement.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/ifelsestatement.png -------------------------------------------------------------------------------- /latex/resources/ifstatement.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/ifstatement.png -------------------------------------------------------------------------------- /latex/resources/launchbinder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/launchbinder.png -------------------------------------------------------------------------------- /latex/resources/memory-layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/memory-layout.png -------------------------------------------------------------------------------- /latex/resources/multi-wayselector.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/multi-wayselector.png -------------------------------------------------------------------------------- /latex/resources/pointers-in-cpp.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/pointers-in-cpp.jpg -------------------------------------------------------------------------------- /latex/resources/range-begin-end.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/range-begin-end.png -------------------------------------------------------------------------------- /latex/resources/range-rbegin-rend.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/range-rbegin-rend.png -------------------------------------------------------------------------------- /latex/resources/record.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/record.png -------------------------------------------------------------------------------- /latex/resources/records.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/records.png -------------------------------------------------------------------------------- /latex/resources/scopesandnameresolution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/scopesandnameresolution.png -------------------------------------------------------------------------------- /latex/resources/string_rep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/string_rep.png -------------------------------------------------------------------------------- /latex/resources/switch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/switch.png -------------------------------------------------------------------------------- /latex/resources/tic-tac-toe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/latex/resources/tic-tac-toe.png -------------------------------------------------------------------------------- /makefile_demos/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 | -------------------------------------------------------------------------------- /makefile_demos/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 | -------------------------------------------------------------------------------- /makefile_demos/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 | } -------------------------------------------------------------------------------- /makefile_demos/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 | -------------------------------------------------------------------------------- /makefile_demos/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 | } -------------------------------------------------------------------------------- /makefile_demos/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 | -------------------------------------------------------------------------------- /makefile_demos/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 | } -------------------------------------------------------------------------------- /makefile_demos/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 | -------------------------------------------------------------------------------- /makefile_demos/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 | } -------------------------------------------------------------------------------- /makefile_demos/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 | -------------------------------------------------------------------------------- /makefile_demos/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 | } -------------------------------------------------------------------------------- /notes/Part 1 Lessons 1 to 4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/notes/Part 1 Lessons 1 to 4.pdf -------------------------------------------------------------------------------- /notes/Part 2 Lessons 5 to 8.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/notes/Part 2 Lessons 5 to 8.pdf -------------------------------------------------------------------------------- /notes/Part 3 Lessons 9 to 10.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/notes/Part 3 Lessons 9 to 10.pdf -------------------------------------------------------------------------------- /notes/Part 4 Lessons 11 to 13.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/notes/Part 4 Lessons 11 to 13.pdf -------------------------------------------------------------------------------- /notes/Unit 10.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/notes/Unit 10.pdf -------------------------------------------------------------------------------- /outputfile.txt: -------------------------------------------------------------------------------- 1 | ================================================= 2 | Item Price 3 | ================================================= 4 | Apple 5.99 5 | Carrots 2.55 6 | ************************************************* 7 | -------------------------------------------------------------------------------- /outputfile1.txt: -------------------------------------------------------------------------------- 1 | 2 + 2 = 4 2 | -------------------------------------------------------------------------------- /pdfs/00-TableOfContents.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/pdfs/00-TableOfContents.pdf -------------------------------------------------------------------------------- /pdfs/Arrays.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/pdfs/Arrays.pdf -------------------------------------------------------------------------------- /pdfs/Conditionals.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/pdfs/Conditionals.pdf -------------------------------------------------------------------------------- /pdfs/DataVariablesAndOperations.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/pdfs/DataVariablesAndOperations.pdf -------------------------------------------------------------------------------- /pdfs/DevEnvironmentSetup.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/pdfs/DevEnvironmentSetup.pdf -------------------------------------------------------------------------------- /pdfs/FileIO.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/pdfs/FileIO.pdf -------------------------------------------------------------------------------- /pdfs/HeaderFiles.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/pdfs/HeaderFiles.pdf -------------------------------------------------------------------------------- /pdfs/Introduction.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/pdfs/Introduction.pdf -------------------------------------------------------------------------------- /pdfs/JupyterNotebookSetup.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/pdfs/JupyterNotebookSetup.pdf -------------------------------------------------------------------------------- /pdfs/Kattis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/pdfs/Kattis.pdf -------------------------------------------------------------------------------- /pdfs/LibraryAndFunction.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/pdfs/LibraryAndFunction.pdf -------------------------------------------------------------------------------- /pdfs/Loops.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/pdfs/Loops.pdf -------------------------------------------------------------------------------- /pdfs/Maps.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/pdfs/Maps.pdf -------------------------------------------------------------------------------- /pdfs/Namespaces-Enumerations.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/pdfs/Namespaces-Enumerations.pdf -------------------------------------------------------------------------------- /pdfs/Pointers.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/pdfs/Pointers.pdf -------------------------------------------------------------------------------- /pdfs/StdInputOutput.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/pdfs/StdInputOutput.pdf -------------------------------------------------------------------------------- /pdfs/Strings.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/pdfs/Strings.pdf -------------------------------------------------------------------------------- /pdfs/Structures.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/pdfs/Structures.pdf -------------------------------------------------------------------------------- /pdfs/Unions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/pdfs/Unions.pdf -------------------------------------------------------------------------------- /pdfs/UserDefinedFunctions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/pdfs/UserDefinedFunctions.pdf -------------------------------------------------------------------------------- /pdfs/Vectors.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/pdfs/Vectors.pdf -------------------------------------------------------------------------------- /practicums/Data Types and fileIOAssignment.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/practicums/Data Types and fileIOAssignment.pdf -------------------------------------------------------------------------------- /practicums/Dynamic Memory and Data Types Assignment.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/practicums/Dynamic Memory and Data Types Assignment.pdf -------------------------------------------------------------------------------- /practicums/Practicum 10 Pointers hands study guide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/practicums/Practicum 10 Pointers hands study guide.pdf -------------------------------------------------------------------------------- /practicums/Practicum 12 Exceptions Theory and examples/Exception_handling Ex1.cpp: -------------------------------------------------------------------------------- 1 | /* Handling Exceptions within a program */ 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | const double conversion = 2.54; 9 | 10 | const int inchesInFoot = 12; 11 | 12 | double getLength(); 13 | 14 | int main () 15 | { 16 | double feet; 17 | double inches; 18 | double centimeters; 19 | 20 | cout << fixed << showpoint << setprecision(2); 21 | 22 | cout << "Feet: "; 23 | feet = getLength(); 24 | cout << endl; 25 | 26 | cout << "Inches: "; 27 | inches = getLength(); 28 | cout << endl; 29 | 30 | centimeters = (inchesInFoot * feet + inches ) * conversion; 31 | 32 | cout << "Centimeter: " << centimeters << endl; 33 | 34 | return 0; 35 | } 36 | 37 | double getLength() 38 | { 39 | bool done = false; 40 | double number = 0; 41 | 42 | string str = 43 | "The input stream is in the fail state."; 44 | 45 | do 46 | { 47 | try 48 | { 49 | cout << "Enter a nonnegative number: "; 50 | cin >> number; 51 | cout << endl; 52 | 53 | if(number < 0) 54 | throw -1; 55 | 56 | if (!cin) 57 | throw str; 58 | done = true; 59 | 60 | } 61 | catch(int) 62 | { 63 | cout << "A non positive number is entered" << endl; 64 | number = 0; 65 | } 66 | catch(string messageStr) 67 | { 68 | cout << messageStr << endl << "Restoring the input stream." 69 | << endl; 70 | cin.clear(); 71 | cin.ignore(100, '\n'); 72 | } 73 | } while (!done); 74 | 75 | 76 | return number; 77 | } 78 | -------------------------------------------------------------------------------- /practicums/Practicum 12 Exceptions Theory and examples/Exception_handling Ex2.cpp: -------------------------------------------------------------------------------- 1 | // Exception example 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int x; 10 | 11 | try 12 | { 13 | cout << "Enter a number less than 100: "; 14 | cin >> x; 15 | if ( x >= 100) 16 | throw 1; 17 | 18 | cout << "Congratulations, you entered good data\n\n"; 19 | } 20 | catch (int i) 21 | { 22 | cout << "Exception " << i << " thrown\n\n"; 23 | //system("PAUSE"); // uncoment for DevC++ 24 | exit(1); 25 | } 26 | 27 | cout<<"Now lets get on with the resemainder of the program\n\n"; 28 | 29 | /* remainder of program */ 30 | 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /practicums/Practicum 12 Exceptions Theory and examples/Exception_handling Ex3.cpp: -------------------------------------------------------------------------------- 1 | // catching memory allocation failure with exceptions 2 | 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main() { 9 | 10 | double *ptr[ 50 ]; 11 | 12 | try { 13 | for ( int i = 0; i < 50; i++ ) { 14 | ptr[ i ] = new double[ 5000000 ]; 15 | cout << "Allocated 5000000 doubles in ptr[ " << i << " ]\n"; 16 | //system("PAUSE"); // uncoment for DevC++ 17 | } 18 | } 19 | catch ( bad_alloc e ) { 20 | cout << "Exception occurred: "< 13 | #include 14 | using namespace std; 15 | 16 | linkedlist::linkedlist() // default constructor 17 | { 18 | head = NULL; 19 | } 20 | 21 | linkedlist::~linkedlist() // destructor for linked list 22 | { 23 | nodeptr current; 24 | current = head; 25 | while (head != NULL) 26 | { 27 | head = current->next; 28 | delete current; 29 | current = head; 30 | } 31 | head = NULL; 32 | } 33 | 34 | void linkedlist::addtotail(const string& newdata) // add to end of the list 35 | { 36 | nodeptr tmp, curr; 37 | 38 | tmp = new node; 39 | tmp->data = newdata; 40 | tmp->next = NULL; 41 | 42 | if (head != NULL) 43 | { 44 | curr = head; 45 | while (curr->next) 46 | curr = curr->next; 47 | curr->next = tmp; 48 | } 49 | else 50 | head = tmp; 51 | } 52 | 53 | bool linkedlist::isempty() // is the list empty 54 | { 55 | if (head == NULL) 56 | return true; 57 | else 58 | return false; 59 | } 60 | 61 | string linkedlist::removefromhead() // remove node from head of list 62 | { 63 | // YOU ARE TO IMPLEMENT THIS 64 | } 65 | 66 | void linkedlist::insert(const string& newdata) // insertion method 67 | { 68 | nodeptr tmp; 69 | tmp = new node; 70 | tmp->data = newdata; 71 | tmp->next = NULL; 72 | 73 | nodeptr curr; 74 | nodeptr prev; 75 | curr = head; 76 | prev = NULL; 77 | 78 | while (curr && listdatacmp(newdata, curr->data) >= 0) // while not the place to insert 79 | { 80 | prev = curr; 81 | curr = curr->next; 82 | } 83 | 84 | if (prev == NULL) // perform insertion 85 | head = tmp; 86 | else 87 | prev->next = tmp; 88 | tmp->next = curr; 89 | 90 | 91 | } 92 | 93 | int listdatacmp(const string& data1, const string& data2) // list data compare function - provide by user 94 | { 95 | // SUITABLE ADDITION HERE 96 | 97 | return 1; 98 | } 99 | 100 | 101 | -------------------------------------------------------------------------------- /practicums/Practicum 13 Structs uses Linked Lists/linkedlist.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Code implements a linked list whereby strings are the data stored in 4 | each node. 5 | */ 6 | 7 | #ifndef LIST 8 | #define LIST 9 | 10 | #include 11 | using namespace std; 12 | 13 | int listdatacmp(const string&, const string&); // user defined compare function 14 | 15 | class linkedlist 16 | { 17 | public: // public methods 18 | linkedlist(); 19 | ~linkedlist(); 20 | void addtotail(const string&); 21 | bool isempty(); 22 | string removefromhead(); 23 | void insert(const string&); 24 | private: // node data and declaration - hidden in class 25 | struct node; 26 | typedef node* nodeptr; 27 | 28 | struct node 29 | { 30 | string data; 31 | nodeptr next; 32 | }; 33 | nodeptr head; 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /practicums/Practicum 13 Structs uses Linked Lists/string-examples/string1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Introduction to C++ string type 3 | Sherine M Antoun 4 | CMU 2021 Spring 5 | */ 6 | 7 | #include 8 | #include 9 | using namespace std; 10 | 11 | int main() 12 | { 13 | string foo; 14 | string boo; 15 | 16 | foo = "Hello"; 17 | boo = ", get out"; 18 | 19 | string moo = foo + boo; // concatenates strings 20 | 21 | cout << moo << endl; 22 | return 0; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /practicums/Practicum 13 Structs uses Linked Lists/string-examples/string2.cpp: -------------------------------------------------------------------------------- 1 | /* Demonstrating String Constructors Sherine M Antoun CMU 2021 Spring */ #include #include using namespace std; int main() { char statement[] = "Humpty dumptysat on the wall,humpty dumpty had a great fall..."; string s1; string s2(statement); string s3(s2); cout << "string one" << endl; cout << s1 << endl; cout << "string two" << endl; cout << s2 << endl; cout << "string three" << endl; cout << s3 << endl; return 0; } -------------------------------------------------------------------------------- /practicums/Practicum 13 Structs uses Linked Lists/string-examples/string3.cpp: -------------------------------------------------------------------------------- 1 | /* Demonstrating ops on strings i.e. checks for equivalence etc. Sherine M Antoun CMU 2021 Spring erase and append operations on strings */ #include #include using namespace std; int main() { string s1; cin >> s1; // read a string from the tty cout << s1 << endl; string s2; cin >> s2; // read a string from the tty cout << s2 << endl; s2.append(s1, 0, 2); // append the string cout << s2 << endl; s2.erase(0, s2.size()); // erase part of the string cout << s2 << endl; return 0; } -------------------------------------------------------------------------------- /practicums/Practicum 13 Structs uses Linked Lists/string-examples/string4.cpp: -------------------------------------------------------------------------------- 1 | /* Demonstrating ops on strings i.e. checks for equivalence etc. Sherine M Antoun CMU 2021 Spring */ #include #include using namespace std; int main() { string name1; string name2; cout << "Enter name1: "; cin>> name1; cout << "Enter name2:"; cin >> name2; if (name1 == name2) // equivelence { cout << "Go home"< 9 | #include 10 | using namespace std; 11 | 12 | int main() 13 | { 14 | string name1; 15 | 16 | cout << "Enter name1: "; 17 | cin>> name1; 18 | 19 | const char* ptr = name1.c_str();// return me a new pointer to a c string representing name1 20 | 21 | cout << "Pointer to a C string " << ptr << endl; 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /practicums/Practicum 2 Style Guide for CSCI111.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/practicums/Practicum 2 Style Guide for CSCI111.pdf -------------------------------------------------------------------------------- /practicums/Practicum 3 PSEUDO TO Cod.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/practicums/Practicum 3 PSEUDO TO Cod.pdf -------------------------------------------------------------------------------- /practicums/Practicum 4 ArithmaticAndPreceedence.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/practicums/Practicum 4 ArithmaticAndPreceedence.pdf -------------------------------------------------------------------------------- /practicums/Practicum 5 Selection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/practicums/Practicum 5 Selection.pdf -------------------------------------------------------------------------------- /practicums/Practicum 6 Repetition.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/practicums/Practicum 6 Repetition.pdf -------------------------------------------------------------------------------- /practicums/Practicum 6 challenge:assignment.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/practicums/Practicum 6 challenge:assignment.pdf -------------------------------------------------------------------------------- /practicums/Practicum 7 Function.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/practicums/Practicum 7 Function.pdf -------------------------------------------------------------------------------- /practicums/Practicum 8 Data Types Array.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/practicums/Practicum 8 Data Types Array.pdf -------------------------------------------------------------------------------- /practicums/Practicum 9 Enum TypeDef Structs.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/practicums/Practicum 9 Enum TypeDef Structs.pdf -------------------------------------------------------------------------------- /practicums/period.tbl: -------------------------------------------------------------------------------- 1 | H Hydrogen 1 1.008 He Helium 2 4.003 Li Lithium 3 6.94 Be Beryllium 4 9.01 B Boron 5 10.81 C Carbon 6 12.01 N Nitrogen 7 14.01 O Oxygen 8 16.00 F Fluorine 9 19.00 Ne Neon 10 20.18 Na Sodium 11 22.99 Mg Magnesium 12 24.31 Al Aluminium 13 26.98 Si Silicon 14 28.09 P Phosphorus 15 30.97 S Sulphur 16 32.06 Cl Chlorine 17 35.45 Ar Argon 18 39.95 K Potassium 19 39.10 Ca Calcium 20 40.08 Sc Scandium 21 44.96 Ti Titanium 22 47.90 V Vanadium 23 50.94 Cr Chromium 24 52.00 Mn Manganese 25 54.94 Fe Iron 26 55.85 Co Cobalt 27 58.93 Ni nickel 28 58.71 Cu Copper 29 63.55 Zn Zinc 30 65.38 Ga Gallium 31 69.72 Ge Germanium 32 72.59 As Arsenic 33 74.92 Se Selenium 34 78.96 Br Bromine 35 79.90 Kr Krypton 36 83.80 Rb Rubidium 37 85.47 Sr Strontium 38 87.62 Zr Zirconium 40 91.22 Nb Niobium 41 92.91 Mo Molybdenum 42 95.94 Tc Technetium 43 98.91 Ru Ruthenium 44 101.07 Rh Rhodium 45 102.91 Pd Palladium 46 106.4 Ag Silver 47 107.87 Cd Cadmium 48 112.40 In Indium 49 114.82 Sn Tin 50 118.69 Sb Antimony 51 121.75 Te Tellurium 52 127.60 I Iodine 53 126.90 Xe Xenon 54 131.30 Cs Caesium 55 132.91 Ba Barium 56 137.34 La Lanthanum 57 138.91 Ce Cerium 58 140.12 Pr Praseodymium 59 140.91 Nd Neodymium 60 144.24 Pm Promethium 61 145 Sm Samarium 62 150.4 Eu Europium 63 151.96 Gd Gadolinium 64 157.25 Tb Terbium 65 158.93 Dy Dysprosium 66 162.50 Ho Holmium 67 164.93 Er Erbium 68 167.26 Tm Thulium 69 168.93 Yb Ytterbium 70 173.04 Lu Lutetium 71 174.97 Hf Hafnium 72 178.49 Ta Tantalum 73 180.95 W Tungsten 74 183.85 Re Rhenium 75 186.2 Os Osmium 76 190.2 Ir Iridium 77 192.22 Pt Platinum 78 195.09 Au Gold 79 196.97 Hg Mercury 80 200.59 Tl Thallium 81 204.37 Pb Lead 82 207.2 Bi Bismuth 83 208.98 Po Polonium 84 209 At Astatine 85 210 Rn Radon 86 222 Fr Francium 87 223 Ra Radium 88 226.03 Ac Actinium 89 227 Th Thorium 90 232.04 Pa Protactinium 91 231.04 U Uranium 92 238.03 Np Neptunium 93 237.05 Pu Plutonium 94 244 Am Americium 95 243 Cm Curium 96 247 Bk Berkelium 97 247 Cf Californium 98 251 Es Einsteinium 99 254 Fm Fermium 100 257 Md Mendelevium 101 258 No Nobellium 102 255 Lr Lawrencium 103 256 -------------------------------------------------------------------------------- /record_copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/record_copy.png -------------------------------------------------------------------------------- /resources/BuildingBlocks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/BuildingBlocks.png -------------------------------------------------------------------------------- /resources/CPPDevelopment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/CPPDevelopment.png -------------------------------------------------------------------------------- /resources/Cartesian-coordinates.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/Cartesian-coordinates.png -------------------------------------------------------------------------------- /resources/Compiler.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/Compiler.png -------------------------------------------------------------------------------- /resources/Do-While-Loop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/Do-While-Loop.png -------------------------------------------------------------------------------- /resources/For-Loop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/For-Loop.png -------------------------------------------------------------------------------- /resources/Intrepreter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/Intrepreter.png -------------------------------------------------------------------------------- /resources/Map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/Map.png -------------------------------------------------------------------------------- /resources/VariablesAndMemory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/VariablesAndMemory.png -------------------------------------------------------------------------------- /resources/While-Loop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/While-Loop.png -------------------------------------------------------------------------------- /resources/array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/array.png -------------------------------------------------------------------------------- /resources/chess-board.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/chess-board.jpg -------------------------------------------------------------------------------- /resources/ifelsestatement.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/ifelsestatement.png -------------------------------------------------------------------------------- /resources/ifstatement.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/ifstatement.png -------------------------------------------------------------------------------- /resources/launchbinder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/launchbinder.png -------------------------------------------------------------------------------- /resources/memory-layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/memory-layout.png -------------------------------------------------------------------------------- /resources/multi-wayselector.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/multi-wayselector.png -------------------------------------------------------------------------------- /resources/pointers-in-cpp.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/pointers-in-cpp.jpg -------------------------------------------------------------------------------- /resources/range-begin-end.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/range-begin-end.png -------------------------------------------------------------------------------- /resources/range-rbegin-rend.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/range-rbegin-rend.png -------------------------------------------------------------------------------- /resources/record.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/record.png -------------------------------------------------------------------------------- /resources/records.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/records.png -------------------------------------------------------------------------------- /resources/scopesandnameresolution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/scopesandnameresolution.png -------------------------------------------------------------------------------- /resources/string_rep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/string_rep.png -------------------------------------------------------------------------------- /resources/switch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/switch.png -------------------------------------------------------------------------------- /resources/tic-tac-toe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/resources/tic-tac-toe.png -------------------------------------------------------------------------------- /slides/1-2.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/slides/1-2.ppt -------------------------------------------------------------------------------- /slides/10.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/slides/10.ppt -------------------------------------------------------------------------------- /slides/3-4.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/slides/3-4.ppt -------------------------------------------------------------------------------- /slides/5-6.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/slides/5-6.ppt -------------------------------------------------------------------------------- /slides/7.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/slides/7.ppt -------------------------------------------------------------------------------- /slides/8 Repetition.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/slides/8 Repetition.ppt -------------------------------------------------------------------------------- /slides/8 Selection.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/slides/8 Selection.ppt -------------------------------------------------------------------------------- /slides/9.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/slides/9.ppt -------------------------------------------------------------------------------- /slides/Unit 1-2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/slides/Unit 1-2.pdf -------------------------------------------------------------------------------- /slides/Unit 3-4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/slides/Unit 3-4.pdf -------------------------------------------------------------------------------- /slides/Unit 5-6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/slides/Unit 5-6.pdf -------------------------------------------------------------------------------- /slides/Unit 7.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/slides/Unit 7.pdf -------------------------------------------------------------------------------- /slides/Unit 8-0.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/slides/Unit 8-0.pdf -------------------------------------------------------------------------------- /slides/Unit 8-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/slides/Unit 8-1.pdf -------------------------------------------------------------------------------- /slides/Unit 9.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/CPP-Fundamentals/318535e6af306e1ef4385ac619f7015033a1e62a/slides/Unit 9.pdf -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /studentgrades.txt: -------------------------------------------------------------------------------- 1 | John Smith 100 95 85 2 | Jane Doe 85 89 99 3 | Jill Jones 56 89 99 100 4 | --------------------------------------------------------------------------------