├── student-class ├── student ├── student.h ├── Makefile ├── student-main.cc └── student.cc ├── Makefile ├── README.md ├── .gitignore ├── random.cc ├── counter.cc ├── sentinel.cc ├── files.cc ├── input-failure.cc ├── default-params.cc ├── cube.cc ├── structures.cc ├── char-files.cc ├── average.cc ├── LICENSE ├── wages.cc ├── switch.cc ├── string-functions.cc ├── output-files.cc ├── arrays.cc ├── formatting.cc ├── student-struct.cc ├── vectors.cc ├── colors.h ├── rectangle-project └── rectangle-main.cc └── student-class.cc /student-class/student: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nasseef/cs2400/HEAD/student-class/student -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile generated by genmake 1.0 2 | CC = g++ 3 | CFLAGS = -Wall -std=c++11 -g 4 | 5 | # target executable 6 | a.out: test.cc 7 | $(CC) $(CFLAGS) test.cc 8 | 9 | 10 | clean: 11 | rm -f a.out 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ## CS 2400 (Introduction to Computer Science I), Ohio University, EECS 3 | 4 | #### Contact: Nasseef Abukamail (abukamai@ohio.edu) 5 | 6 | --- 7 | 8 | Welcome to CS 2400. In this class we will be writing programs in C++. In order to prepare for class, you need to install a C++ compiler and other software tools on your own machines. 9 | 10 | Full instructions for installing all the needed tools can be found [here](https://github.com/nasseef/cs) 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # settings 2 | .vscode 3 | test*.* 4 | *.txt 5 | genmake.cc 6 | #debug information 7 | *.dSYM 8 | # Prerequisites 9 | *.d 10 | 11 | # Compiled Object files 12 | *.slo 13 | *.lo 14 | *.o 15 | *.obj 16 | sqlite-ex.cc 17 | *.db 18 | 19 | # Precompiled Headers 20 | *.gch 21 | *.pch 22 | genmake 23 | # Compiled Dynamic libraries 24 | *.so 25 | *.dylib 26 | *.dll 27 | 28 | # Fortran module files 29 | *.mod 30 | *.smod 31 | 32 | # Compiled Static libraries 33 | *.lai 34 | *.la 35 | *.a 36 | *.lib 37 | 38 | # Executables 39 | *.exe 40 | *.out 41 | *.app 42 | endl.cc 43 | overflow.cc 44 | -------------------------------------------------------------------------------- /random.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * @file: random.cc 3 | * @author: Nasseef Abukamail 4 | * @date: September 24, 2025 5 | * @brief: Add Description 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | ///function prototypes 14 | 15 | int main(int argc, char const *argv[]) { 16 | srand(time(nullptr)); 17 | cout << "5 random numbers: "; 18 | for (size_t i = 0; i < 5; i++) 19 | { 20 | int randomNumber = rand() % 6 + 1; 21 | 22 | cout << randomNumber << " "; 23 | } 24 | 25 | cout << endl; 26 | return 0; 27 | } /// main -------------------------------------------------------------------------------- /student-class/student.h: -------------------------------------------------------------------------------- 1 | #ifndef STUDENT_H 2 | #define STUDENT_H 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | class Student { 9 | public: 10 | Student(); // Default contstuctor 11 | Student(int newId, string newName); 12 | string getName() const; 13 | int getId(); 14 | double getScore(); 15 | /** 16 | * 17 | */ 18 | void setName(string newName); 19 | void setId(int newId); 20 | void setScore(double newScore); 21 | 22 | void output(ostream &out); 23 | 24 | private: 25 | string name; 26 | int id; 27 | double score; 28 | }; 29 | #endif -------------------------------------------------------------------------------- /counter.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * @file: counter.cc 3 | * @author: Nasseef Abukamail 4 | * @date: September 17, 2025 5 | * @brief: Add Description 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | ///Constants and function prototypes 14 | 15 | int main(int argc, char const *argv[]) { 16 | 17 | int count = 0; 18 | int total = 0; 19 | int num; 20 | 21 | while (count < 3) 22 | { 23 | cout << "Enter a number: "; 24 | cin >> num; 25 | total += num; 26 | count++; 27 | } 28 | cout << "Total is " << total << endl; 29 | return 0; 30 | } /// main -------------------------------------------------------------------------------- /student-class/Makefile: -------------------------------------------------------------------------------- 1 | # Author: Nasseef Abukamail 2 | 3 | # Variables 4 | CFLAGS = -Wall -std=c++14 5 | CC = g++ 6 | 7 | 8 | # Rules 9 | # first rule is the one executed automatically 10 | a.out: student-main.o student.o #dependencies 11 | $(CC) $(CFLAGS) student.o student-main.o 12 | # g++ -Wall -std=c++14 student.o student-main.o 13 | 14 | 15 | student.o: student.cc student.h 16 | $(CC) -c $(CFLAGS) student.cc 17 | 18 | student-main.o: student-main.cc student.h 19 | $(CC) -c $(CFLAGS) student-main.cc 20 | 21 | # list any file you want deleted with the command 22 | # make clean 23 | clean: 24 | rm -rf student.o student-main.o 25 | mv a.out student 26 | 27 | 28 | -------------------------------------------------------------------------------- /student-class/student-main.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * @file: student-class.cc 3 | * @author: Nasseef Abukamail 4 | * @date: November 10, 2025 5 | * @brief: Add Description 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "student.h" 13 | 14 | using namespace std; 15 | 16 | 17 | int main(int argc, char const* argv[]) { 18 | Student s; // default contstructor is called 19 | s.output(cout); 20 | 21 | s.setName(""); 22 | s.setId(-562); 23 | s.setScore(55); 24 | cout << "The first student" << endl; 25 | s.output(cout); 26 | 27 | Student s2(500, "N/A"); 28 | s2.setId(-300); 29 | s2.output(cout); 30 | return 0; 31 | } /// main 32 | 33 | -------------------------------------------------------------------------------- /sentinel.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * @file: sentinel.cc 3 | * @author: Nasseef Abukamail 4 | * @date: September 17, 2025 5 | * @brief: Add Description 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | /// Constants and function prototypes 14 | 15 | int main(int argc, char const *argv[]) { 16 | int total = 0; 17 | int num; 18 | int count = 0; 19 | cout << "Enter a number: "; 20 | cin >> num; 21 | while (num >= 0) { 22 | count++; 23 | total += num; 24 | cout << "Enter a number: "; 25 | cin >> num; 26 | } 27 | cout << "Total is " << total << endl; 28 | if (count != 0) 29 | { 30 | cout << "Average is " << (total/count) << endl; 31 | } 32 | 33 | 34 | return 0; 35 | } /// main -------------------------------------------------------------------------------- /files.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * @file: files.cc 3 | * @author: Nasseef Abukamail 4 | * @date: October 08, 2025 5 | * @brief: Add Description 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | /// 1 12 | #include 13 | 14 | using namespace std; 15 | 16 | /// Constants and function prototypes 17 | 18 | int main(int argc, char const *argv[]) { 19 | /// 2 20 | ifstream inStream; 21 | /// 3 22 | inStream.open("numbers.txt"); 23 | if (inStream.fail()) { 24 | cout << "Error: file does not exist" << endl; 25 | exit(0); 26 | } 27 | /// 4 use it 28 | int num; 29 | inStream >> num; 30 | while (!inStream.eof()) { 31 | cout << "Number is " << num << endl; 32 | inStream >> num; 33 | } 34 | 35 | /// 5 36 | inStream.close(); 37 | return 0; 38 | } /// main -------------------------------------------------------------------------------- /input-failure.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * @file: sentinel.cc 3 | * @author: Nasseef Abukamail 4 | * @date: September 19, 2025 5 | * @brief: Add Description 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | /// Constants and function prototypes 14 | 15 | int main(int argc, char const *argv[]) { 16 | double total; 17 | int count = 0; 18 | total = 0; 19 | double number; 20 | cout << "Enter a number, q to quit: "; 21 | cin >> number; //I 22 | while (!cin.fail()) { //C 23 | count++; 24 | total += number; 25 | //cout << "Enter a number, q to quit: "; 26 | cin >> number; //U 27 | } 28 | 29 | if (cin.fail()) 30 | { 31 | cin.clear(); //clear the flag 32 | cin.ignore(100, '\n'); 33 | } 34 | 35 | cout << "Total is " << total << endl; 36 | cout << "Count is " << count << endl; 37 | return 0; 38 | } /// main -------------------------------------------------------------------------------- /default-params.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * @file: default-params.cc 3 | * @author: Nasseef Abukamail 4 | * @date: October 08, 2025 5 | * @brief: Example of default function parameters 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | /// Constants and function prototypes 14 | /** 15 | * precOutput: precOutput a value with specified prec 16 | * @param: value - the value to be displayed 17 | * @param: prec - precision of the display (0 by default) 18 | */ 19 | void precOutput(double value, int prec = 0); 20 | 21 | int main(int argc, char const *argv[]) { 22 | double value = 1234.934567; 23 | precOutput(value, 3); // use 3 decimal places 1234.235 24 | precOutput(value, 5); // use 5 decimal places 1234.23457 25 | precOutput(value); // use 0 (default) decimal place 1235 26 | return 0; 27 | } /// main 28 | 29 | void precOutput(double value, int prec) { 30 | cout << setprecision(prec) << fixed; 31 | cout << value << endl; 32 | } 33 | -------------------------------------------------------------------------------- /cube.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * @file: cube.cc 3 | * @author: Nasseef Abukamail 4 | * @date: September 29, 2025 5 | * @brief: Add Description 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | ///Constants and function prototypes or function declaration 14 | /** 15 | * cube: A function to find the cube of an integer 16 | * @param: value - integer value to be cubed 17 | * @return: return the cube of value 18 | */ 19 | //int cube(int value); //function declaration/prototype 20 | 21 | int main(int argc, char const *argv[]) { 22 | 23 | int number = 3; 24 | int numberCubed; 25 | numberCubed = cube(number); 26 | cout << "cube is " << numberCubed << endl; 27 | cout << "cube of 9 is " << cube(9) << endl; 28 | return 0; 29 | } /// main 30 | 31 | //function definition 32 | int cube(int value){// function heading, value is a formal parameter 33 | int result; //local variable 34 | result = value * value * value; 35 | return result; 36 | } 37 | -------------------------------------------------------------------------------- /structures.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * @file: structures.cc 3 | * @author: Nasseef Abukamail 4 | * @date: November 03, 2025 5 | * @brief: Add Description 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | struct Student{ 14 | string name; 15 | int id; 16 | double score; 17 | }; 18 | ///Constants and function prototypes 19 | void printStudent(const Student &theStudent); 20 | 21 | int main(int argc, char const *argv[]) { 22 | Student s; 23 | s.name = "John"; 24 | s.id = 562; 25 | s.score = 55; 26 | cout << "The first student" << endl; 27 | printStudent(s); 28 | Student s2 = {"Sue", 976, 90.0}; 29 | cout << "The second student" << endl; 30 | printStudent(s2); 31 | 32 | return 0; 33 | } /// main 34 | 35 | void printStudent(const Student &theStudent){ 36 | cout << " Name: " << theStudent.name << endl; 37 | cout << " ID: " << theStudent.id << endl; 38 | cout << "Score: " << theStudent.score << endl; 39 | } 40 | -------------------------------------------------------------------------------- /char-files.cc: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file: files.cc 4 | * @author: Nasseef Abukamail 5 | * @date: October 08, 2025 6 | * @brief: Add Description 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | /// 1 13 | #include 14 | 15 | using namespace std; 16 | 17 | /// Constants and function prototypes 18 | 19 | int main(int argc, char const *argv[]) { 20 | /// 2 21 | ifstream inStream; 22 | /// 3 23 | inStream.open("numbers.txt"); 24 | if (inStream.fail()) { 25 | cout << "Error: file does not exist" << endl; 26 | exit(0); 27 | } 28 | /// 4 use it 29 | char ch; 30 | 31 | while (inStream.get(ch)) { 32 | cout << ch; 33 | } 34 | cout << endl; 35 | // string line; 36 | // getline(inStream, line); 37 | 38 | // while (!inStream.eof()) { 39 | // cout << line << endl; 40 | // getline(inStream, line); 41 | // } 42 | // cout << endl; 43 | 44 | /// 5 45 | inStream.close(); 46 | return 0; 47 | } /// main -------------------------------------------------------------------------------- /average.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * @file: average.cc 3 | * @author: Nasseef Abukamail 4 | * @date: September 29, 2025 5 | * @brief: Add Description 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | ///Constants and function prototypes 14 | /** 15 | * function documentation 16 | */ 17 | double average(double first, double second); 18 | /** 19 | * 20 | */ 21 | double average(double first, double second, double third); 22 | 23 | int main(int argc, char const *argv[]) { 24 | 25 | cout << "Average is " << average(9, 6) << endl; 26 | 27 | cout << "Average is " << average(9, 6, 5) << endl; 28 | 29 | double avg = average(10, 20); 30 | cout << "Average is " << avg << endl; 31 | return 0; 32 | } /// main 33 | 34 | double average(double first, double second){ 35 | double result = (first + second) / 2.0; //local variable 36 | return result; 37 | } 38 | double average(double first, double second, double third){ 39 | return (first + second + third) / 3.0; 40 | } 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Nasseef Abukamail 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 | -------------------------------------------------------------------------------- /student-class/student.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "student.h" 5 | 6 | 7 | using namespace std; 8 | Student::Student() { 9 | id = 0; 10 | name = "N/A"; 11 | score = -1; 12 | } 13 | 14 | Student::Student(int newId, string newName) { 15 | name = newName; 16 | id = newId; 17 | score = -1; 18 | if (newId < 0) { 19 | id = 0; 20 | } 21 | // id = newId < 0 ? 0 : newId; 22 | if (newName == "") { 23 | name = "N/A"; 24 | } 25 | } 26 | void Student::output(ostream &out) { 27 | out << " Name: " << name << endl; 28 | out << " ID: " << id << endl; 29 | out << "Score: " << score << endl; 30 | } 31 | 32 | string Student::getName() const{ return name; } 33 | int Student::getId() { return id; } 34 | double Student::getScore() { return score; } 35 | 36 | void Student::setName(string newName) { 37 | if (newName != "") { 38 | name = newName; 39 | } 40 | } 41 | void Student::setId(int newId) { 42 | if (newId >= 0) { 43 | id = newId; 44 | } 45 | } 46 | void Student::setScore(double newScore) { 47 | if (newScore >= -1) { 48 | score = newScore; 49 | } 50 | } -------------------------------------------------------------------------------- /wages.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * @file: wages.cc 3 | * @author: Nasseef Abukamail 4 | * @date: September 05, 2025 5 | * @brief: Add Description 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | ///Constants and function prototypes 14 | 15 | int main(int argc, char const *argv[]) { 16 | 17 | //1. decalare variables 18 | double hours, rate, pay; 19 | 20 | cout << endl; 21 | //2. Input hours and rate 22 | cout << "Enter the rate: "; 23 | cin >> rate; 24 | if (rate < 10 || rate > 50) 25 | { 26 | cout << "Error: rate is invalid (10-50)" << endl; 27 | exit(0); 28 | } 29 | 30 | cout << "Enter the hours: "; 31 | cin >> hours; 32 | 33 | if (hours < 0 || hours > 40) 34 | { 35 | cout << "Error: hours are invalid (0-40)" << endl; 36 | exit(0); 37 | } 38 | 39 | //3. calculation 40 | pay = hours * rate; 41 | 42 | //4. output results 43 | cout << fixed; 44 | cout << setprecision(2); 45 | cout << "Number of hours worked: " << hours << " hours" << endl; 46 | cout << "Your hourly rate: $" << rate << endl; 47 | cout << "Your weekly wages: $" << pay << endl; 48 | 49 | return 0; 50 | } /// main -------------------------------------------------------------------------------- /switch.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * @file: switch.cc 3 | * @author: Nasseef Abukamail 4 | * @date: September 15, 2025 5 | * @brief: Add Description 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | /// Constants and function prototypes 14 | 15 | int main(int argc, char const *argv[]) { 16 | int choice; 17 | do { 18 | cout << "1. first option" << endl; 19 | cout << "2. second option" << endl; 20 | cout << "3. third option" << endl; 21 | cout << "4. Fourth option" << endl; 22 | cout << "5. Quit" << endl; 23 | 24 | cout << "Enter your choice: "; 25 | cin >> choice; 26 | switch (choice) { 27 | case 1: 28 | cout << "You entered 1" << endl; 29 | // break; 30 | case 2: 31 | cout << "You entered 2" << endl; 32 | break; 33 | case 3: 34 | cout << "You entered 3" << endl; 35 | break; 36 | case 4: 37 | cout << "You entered 4" << endl; 38 | break; 39 | default: 40 | cout << "Quit: You entered a choice less than 1 or greater than 4" << endl; 41 | 42 | } 43 | } while (choice != 5); 44 | 45 | return 0; 46 | } /// main -------------------------------------------------------------------------------- /string-functions.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * @author: Nasseef Abukamail 3 | * @date: October 27, 2025 4 | * @brief: Example to demonstrate string built-in functions 5 | */ 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | using namespace std; 12 | 13 | //function prototypes 14 | 15 | int main() 16 | { 17 | string line1 = "Ohio U. Athens, Ohio"; 18 | string line2 = " EECS Department"; 19 | 20 | string line3 = line1 + line2; 21 | cout << line3 << endl; 22 | 23 | cout <<"line 1 length: " << line3.length() << endl; 24 | int location = line1.find("Ohio"); 25 | 26 | //if not found returns string::npos 27 | cout << "Ohio is located at position " << location << endl; 28 | location = line1.find("Ohio", location + 4); 29 | if (location == string::npos){ 30 | cout << "Ohio not found" << endl; 31 | } 32 | cout << "The second Ohio is at position " << location << endl; 33 | 34 | 35 | //line1 = "Ohio U. Athens, Ohio."; 36 | line1.replace(location, 4, "OH"); 37 | cout << line1 << endl; 38 | line1.erase(location, 2); 39 | cout << line1 << endl; 40 | 41 | line1.insert(location, "OHIO"); 42 | cout << line1 << endl; 43 | 44 | 45 | string line4 = line1.substr(location, 4); 46 | cout << line4 << endl; 47 | 48 | 49 | string s = to_string(981); 50 | cout << "The second digit character in 981 is " << s.at(1) << endl; 51 | 52 | string doubleString = "123.567"; 53 | double value = stod(doubleString); 54 | cout << fixed << setprecision(2) << "The double number is " << value << endl; 55 | return 0; //or EXIT_SUCCESS 56 | } 57 | -------------------------------------------------------------------------------- /output-files.cc: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file: files.cc 4 | * @author: Nasseef Abukamail 5 | * @date: October 08, 2025 6 | * @brief: Add Description 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | /// 1 13 | #include 14 | 15 | using namespace std; 16 | 17 | /// Constants and function prototypes 18 | void copy(ifstream &inp, ofstream &out); 19 | int main(int argc, char const *argv[]) { 20 | 21 | //check that argc is the right value 22 | if (argc != 3) 23 | { 24 | cout << "Error: supply two file names" << endl; 25 | cout << "Usage: ./a.out file1 file2" << endl; 26 | exit(0); 27 | } 28 | 29 | /// 2 30 | ifstream inStream; 31 | ofstream outStream; 32 | /// 3 33 | string inFileName; 34 | inFileName = argv[1]; 35 | 36 | inStream.open(inFileName); 37 | if (inStream.fail()) { 38 | cout << "Error: file does not exist" << endl; 39 | exit(0); 40 | } 41 | 42 | string outFileName; 43 | outFileName = argv[2]; 44 | // cout << "Enter an output file name: "; 45 | // cin >> outFileName; 46 | 47 | outStream.open(outFileName); 48 | if (outStream.fail()) 49 | { 50 | cout << "Error: creating output file" << endl; 51 | exit(0); 52 | } 53 | 54 | /// 4 use it 55 | copy(inStream, outStream); 56 | 57 | 58 | /// 5 59 | inStream.close(); 60 | outStream.close(); 61 | return 0; 62 | } /// main 63 | 64 | void copy(ifstream &inp, ofstream &out){ 65 | char ch; 66 | 67 | while (inp.get(ch)) { 68 | out << ch; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /arrays.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * @file: arrays.cc 3 | * @author: Nasseef Abukamail 4 | * @date: October 17, 2025 5 | * @brief: Add Description 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | ///Constants and function prototypes 14 | int indexOfSmallest(const int data[], int start, int count); 15 | 16 | ///Selection sort 17 | void sort(int data[], int count); 18 | void printArray(const int data[], int count); 19 | 20 | int main(int argc, char const *argv[]) { 21 | 22 | int numbers[20] = {20, 15, 60, 7, 55, 40, 30, 25, 80, 45, 17}; 23 | int count = 11; 24 | for (size_t i = 0; i < count; i++) 25 | { 26 | cin >> numbers[i]; 27 | } 28 | 29 | //int index = indexOfSmallest(numbers, 0, count); 30 | printArray(numbers, count); 31 | sort(numbers, count); 32 | printArray(numbers, count); 33 | 34 | 35 | return 0; 36 | } /// main 37 | 38 | int indexOfSmallest(const int data[], int start, int count){ 39 | int smallest = data[start]; 40 | int index = start; 41 | for (int i = start + 1; i < count; i++) 42 | { 43 | if (data[i] < smallest) 44 | { 45 | smallest = data[i]; 46 | index = i; 47 | } 48 | 49 | } 50 | return index; 51 | } 52 | 53 | void sort(int data[], int count){ 54 | for (size_t i = 0; i < count - 1; i++) 55 | { 56 | int index = indexOfSmallest(data, i, count); 57 | swap(data[i], data[index]); 58 | } 59 | } 60 | 61 | void printArray(const int data[], int count){ 62 | for (size_t i = 0; i < count; i++) 63 | { 64 | cout << data[i] << " "; 65 | } 66 | cout << endl; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /formatting.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * File Name: formatting.cc 3 | * Author: Nasseef Abukamail 4 | * Date: September 12, 2025 5 | * Description: Example program to demonstrate different formatting options in C++. 6 | * 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | using namespace std; 13 | 14 | int main() { 15 | double largeNumber = 12345356789.12355678; 16 | cout << "Default display (6 digits, scientific)>" << largeNumber << "<" << endl; 17 | 18 | // Use only two digits in Scientific notation 19 | cout << setprecision(3); 20 | cout << "Scientific, precision of 3 >" << largeNumber << "<" << endl; 21 | 22 | // When using fixed, use two digits after the decimal point 23 | cout << fixed; 24 | cout << "Fixed, precision of 3 >" << largeNumber << "<" << endl << endl; 25 | 26 | // using setw right justification (default) 27 | int intNum = 1234; 28 | double smallNumber = 3.14159; 29 | cout << "setw(10) right justification(default) >" 30 | << setw(10) << intNum 31 | << setw(10) << smallNumber << "<" << endl; 32 | 33 | 34 | ///left justification 35 | cout << left; 36 | cout << " setw(10) left justification >" 37 | << setw(10) << intNum << setw(10) 38 | << smallNumber << "<" << endl << endl; 39 | 40 | 41 | ///changing the fill character for setw 42 | cout << setfill('*'); 43 | cout << "setw(10) left justification with '*' fill character >" 44 | << setw(10) << intNum << setw(10) 45 | << smallNumber << "<" << endl << endl; 46 | 47 | 48 | cout << setprecision(2); 49 | cout << "Your salary is $" << largeNumber << endl; 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /student-struct.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * @file: structures.cc 3 | * @author: Nasseef Abukamail 4 | * @date: November 03, 2025 5 | * @brief: Add Description 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace std; 14 | 15 | struct Student{ 16 | string name; 17 | int id; 18 | double score; 19 | }; 20 | ///Constants and function prototypes 21 | void printStudent(const Student &theStudent); 22 | void printAllStudents(const vector &allStudents); 23 | 24 | int main(int argc, char const *argv[]) { 25 | Student s; 26 | s.name = "John"; 27 | s.id = 562; 28 | s.score = 55; 29 | cout << "The first student" << endl; 30 | printStudent(s); 31 | 32 | Student s2 = {"Sue", 976, 90.0}; 33 | cout << "The second student" << endl; 34 | printStudent(s2); 35 | 36 | cout << "Printing all Students" << endl; 37 | vector allStudents; 38 | ifstream ins; 39 | ins.open("students.txt"); 40 | if (ins.fail()) 41 | { 42 | cout << "File does not exist" << endl; 43 | exit(0); 44 | } 45 | 46 | //read student data into the vector allStudents 47 | //importStudents(allStudents, ins); 48 | ins.close(); 49 | 50 | printAllStudents(allStudents); 51 | return 0; 52 | } /// main 53 | 54 | void printStudent(const Student &theStudent){ 55 | cout << " Name: " << theStudent.name << endl; 56 | cout << " ID: " << theStudent.id << endl; 57 | cout << "Score: " << theStudent.score << endl; 58 | } 59 | 60 | void printAllStudents(const vector &allStudents){ 61 | for (size_t i = 0; i < allStudents.size(); i++) 62 | { 63 | printStudent(allStudents.at(i)); 64 | } 65 | // for(Student s : allStudents){ 66 | // printStudent(s); 67 | // } 68 | } 69 | -------------------------------------------------------------------------------- /vectors.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * @file: vectors.cc 3 | * @author: Nasseef Abukamail 4 | * @date: October 24, 2025 5 | * @brief: Add Description 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace std; 14 | 15 | ///Constants and function prototypes 16 | void printNumbers(vector numbers); 17 | 18 | vector updateByOne(vector &numbers); 19 | 20 | int main(int argc, char const *argv[]) { 21 | vector numbers; 22 | cout << numbers.empty() << endl; 23 | numbers.push_back(4); 24 | cout << numbers.empty() << endl; 25 | 26 | numbers.push_back(5); 27 | numbers.push_back(2); 28 | numbers.push_back(9); 29 | numbers.push_back(33); 30 | numbers.push_back(44); 31 | cout << "Vector Size = " << numbers.size() << endl; 32 | cout << "First element: " << numbers.front() << endl; 33 | cout << "Last element: " << numbers.back() << endl; 34 | 35 | 36 | numbers.pop_back(); 37 | 38 | printNumbers(numbers); 39 | 40 | 41 | numbers.erase(numbers.begin() + 1); 42 | 43 | printNumbers(numbers); 44 | 45 | vector updatedNumbers = updateByOne(numbers); 46 | 47 | printNumbers(updatedNumbers); 48 | 49 | updatedNumbers.insert(updatedNumbers.begin(), 99); 50 | 51 | printNumbers(updatedNumbers); 52 | 53 | vector names = {"Susan", "Jim", "John", "Kate"}; 54 | int lastIndex = names.at(0).length() - 1; 55 | 56 | cout << names.at(0).at(lastIndex) << endl; 57 | return 0; 58 | } /// main 59 | 60 | void printNumbers(vector numbers){ 61 | // for (size_t i = 0; i < numbers.size(); i++) 62 | // { 63 | // cout << numbers.at(i) << " "; 64 | // } 65 | for(int value : numbers){ 66 | cout << value << " "; 67 | } 68 | cout << endl; 69 | } 70 | vector updateByOne(vector &numbers){ 71 | for (size_t i = 0; i < numbers.size(); i++) 72 | { 73 | numbers.at(i)++; 74 | } 75 | return numbers; 76 | } 77 | -------------------------------------------------------------------------------- /colors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: colors.h 3 | * Author: Nasseef Abukamail 4 | * Date: July 04, 2019 5 | * Description: Defines colors to be used in C++. Examples are provided 6 | * in the comments below. Add this file in the same directory as your project. 7 | * To use: #include "colors.h" 8 | */ 9 | #ifndef COLORS_H 10 | #define COLORS_H 11 | 12 | /* Colors 13 | * Example: Change the color to RED and reset it when done. 14 | * cout << RED << 5 << 5.6 << someVar << "text" << RST; 15 | */ 16 | #define RST "\33[0m" 17 | #define RED "\33[31m" 18 | #define GRN "\33[32m" 19 | #define YEL "\33[33m" 20 | #define BLU "\33[34m" 21 | #define MAG "\33[35m" 22 | #define CYN "\33[36m" 23 | #define WHT "\33[37m" 24 | 25 | /* 26 | * Forground colors 27 | * change the forground color. For example to change the color to red: 28 | * cout << FRED("Some text"); 29 | */ 30 | #define FRED(text) RED text RST // 31 | #define FGRN(text) GRN text RST 32 | #define FYEL(text) YEL text RST 33 | #define FBLU(text) BLU text RST 34 | #define FMAG(text) MAG text RST 35 | #define FCYN(text) CYN text RST 36 | #define FWHT(text) WHT text RST 37 | 38 | 39 | /* 40 | * background colors 41 | * Change the background color of the text. 42 | * Example 1: Change the background color to red 43 | * cout << BRED("Some text"); 44 | * 45 | * Example 2: Change the forground to yellow and background to green 46 | * cout << BGRN(FYEL("Some text")); 47 | */ 48 | #define BBLK(text) "\33[40m" text RST 49 | #define BRED(text) "\33[41m" text RST 50 | #define BGRN(text) "\33[42m" text RST 51 | #define BYEL(text) "\33[43m" text RST 52 | #define BBLU(text) "\33[44m" text RST 53 | #define BMAG(text) "\33[45m" text RST 54 | #define BCYN(text) "\33[46m" text RST 55 | #define BWHT(text) "\33[47m" text RST 56 | 57 | 58 | /* 59 | * Bold, underline, and inv 60 | * Example: 61 | * cout << INV("some text"); 62 | * cout << UND("some text"); 63 | * cout << INV("some text"); 64 | */ 65 | #define BLD(text) "\33[1m" text RST 66 | #define UND(text) "\33[4m" text RST 67 | #define INV(text) "\33[7m" text RST 68 | 69 | 70 | #endif /* COLORS_H */ -------------------------------------------------------------------------------- /rectangle-project/rectangle-main.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * @file: rectangle-main.cc 3 | * @author: Nasseef Abukamail 4 | * @date: November 24, 2025 5 | * @brief: Add Description 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace std; 14 | 15 | class Rectangle { 16 | public: 17 | Rectangle(); 18 | Rectangle(double newLength, double newWidth); 19 | 20 | //getters 21 | double getLength() const; 22 | double getWidth() const; 23 | 24 | //setters 25 | void setLength(double newLength); 26 | void setWidth(double newWidth); 27 | 28 | //helper functions 29 | void output(); 30 | double area(); 31 | double perimeter(); 32 | bool isSquare(); 33 | 34 | friend bool operator ==(Rectangle r1, Rectangle r2); 35 | 36 | 37 | private: 38 | double length; 39 | double width; 40 | }; 41 | 42 | 43 | 44 | int main(int argc, char const *argv[]) { 45 | Rectangle r1(20, 10); 46 | 47 | r1.output(); 48 | cout << endl; 49 | Rectangle r2(20, 10); 50 | 51 | r2.output(); 52 | cout << endl; 53 | 54 | if (r1 == r2) 55 | { 56 | cout << "Equal" << endl; 57 | } 58 | else { 59 | cout << "Not Equal" << endl; 60 | } 61 | 62 | return 0; 63 | } /// main 64 | 65 | Rectangle::Rectangle(){ 66 | length = 0; 67 | width = 0; 68 | } 69 | Rectangle::Rectangle(double newLength, double newWidth){ 70 | length = 0; 71 | width = 0; 72 | if (newLength > 0 && newWidth > 0) 73 | { 74 | length = newLength; 75 | width = newWidth; 76 | } 77 | 78 | } 79 | 80 | double Rectangle::getLength() const{ 81 | return length; 82 | } 83 | double Rectangle::getWidth() const{ 84 | return width; 85 | } 86 | 87 | void Rectangle::output(){ 88 | cout << "(" << length << "x" << width << ")"; 89 | } 90 | 91 | bool operator ==(Rectangle r1, Rectangle r2){ 92 | if (r1.length == r2.length && 93 | r1.width == r2.width) 94 | { 95 | return true; 96 | } 97 | return false; 98 | } 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /student-class.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * @file: student-class.cc 3 | * @author: Nasseef Abukamail 4 | * @date: November 10, 2025 5 | * @brief: Add Description 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace std; 14 | 15 | class Student { 16 | public: 17 | Student(); // Default contstuctor 18 | Student(int newId, string newName); 19 | string getName(); 20 | int getId(); 21 | double getScore(); 22 | 23 | /** 24 | * 25 | */ 26 | void setName(string newName); 27 | void setId(int newId); 28 | void setScore(double newScore); 29 | 30 | void output(); 31 | 32 | private: 33 | string name; 34 | int id; 35 | double score; 36 | }; 37 | /// Constants and function prototypes 38 | void printStudent(const Student& theStudent); 39 | 40 | int main(int argc, char const* argv[]) { 41 | Student s; // default contstructor is called 42 | s.output(); 43 | 44 | s.setName(""); 45 | s.setId(-562); 46 | s.setScore(55); 47 | cout << "The first student" << endl; 48 | s.output(); 49 | 50 | Student s2(500, "N/A"); 51 | s2.setId(-300); 52 | s2.output(); 53 | return 0; 54 | } /// main 55 | 56 | Student::Student() { 57 | id = 0; 58 | name = "N/A"; 59 | score = -1; 60 | } 61 | 62 | Student::Student(int newId, string newName) { 63 | name = newName; 64 | id = newId; 65 | score = -1; 66 | if (newId < 0) { 67 | id = 0; 68 | } 69 | // id = newId < 0 ? 0 : newId; 70 | if (newName == "") { 71 | name = "N/A"; 72 | } 73 | } 74 | void Student::output() { 75 | cout << " Name: " << name << endl; 76 | cout << " ID: " << id << endl; 77 | cout << "Score: " << score << endl; 78 | } 79 | 80 | string Student::getName() { return name; } 81 | int Student::getId() { return id; } 82 | double Student::getScore() { return score; } 83 | 84 | void Student::setName(string newName) { 85 | if (newName != "") { 86 | name = newName; 87 | } 88 | } 89 | void Student::setId(int newId) { 90 | if (newId >= 0) { 91 | id = newId; 92 | } 93 | } 94 | void Student::setScore(double newScore) { 95 | if (newScore >= -1) { 96 | score = newScore; 97 | } 98 | } 99 | --------------------------------------------------------------------------------