GitHub Pages link: https://br815.github.io/CS0_Portfolio/
This repository contains university programming assignments from my introductory C++ lecture and laboratory courses.
The purpose of this repository is archival and educational:
A C++ compiler is necessary to run these assignments (eg. the g++ compiler in MinGW, a Microsoft Windows port of the GNU Compiler Collection).
To install MinGW on Windows 11 or less, follow these instructions (refer to Pages 3-4 of the linked PDF):
X86_64 architecture. Don’t make any other changes with the installer.Path Environment Variable. This YouTube video has the steps to follow:
Control Panel >> System and Security >> System >> Advanced System Settings.Settings >> System >> About >> Advanced System Settings.)System Properties.System Properties, go to Environment Variables.Environment Variables, look down at System variables and scroll until you reach Path.Path and hit Edit.Edit environment variable, find the file path for MinGW’s /bin folder in your File Explorer and copy it. C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin
Edit environment variable, hit New, and paste the file path for /bin.OK in Edit environment variable, hit OK in Environment Variables, and hit OK in System Properties.Path. To test in Command Prompt, run:
g++ --version
You should see output similar to:
g++ (MinGW.org GCC-6.3.0-1) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
After installing MinGW and adding it to Path, make sure to restart your IDE to avoid compilation errors.
(Using CS1336 as an example. CS1336 contains a src folder,
which contains 2 source files main.cpp and hw_exercises.cpp, and 1 header file hw_exercises.h.)
Open terminal in CS0_Portfolio and run:
cd CS1336 # cd to project root
mkdir build # make a build folder if it doesn't exist
g++ src/*.cpp -o build/hw # compile executable file into the build folder
build/hw # provide the build folder as the path to the .exe file
C++ compilation & execution can occur from anywhere through the use of relative paths, as long as the compilation instruction specifies the relative path to the .cpp source files & the execution instruction specifies the relative path to the .exe executable file. However, execution should occur from the project root (because that is the conventional location from which your program should retrieve any IO files).
In order to achieve both compilation & execution from the project root, this compilation instruction goes through src/ to compile all .cpp source files in src. Alternatively, each source file can be compiled individually through their paths:
g++ src/main.cpp src/hw_exercises.cpp -o build/hw
By default, C++ compilation produces .exe files directly in the same folder where compilation occurred; however, the provided compilation instruction uses the -o flag to produce the .exe file in a build folder for clearer file organization.
Then, execution can occur from the project root as long as the path to the executable is specified, which for this project is through build/.
Technically, compilation & execution can occur from anywhere as long as the user provides the necessary relative file paths to the source files & executable. However, for user ease in this project, file paths to IO files are hard-coded in the source code to be preprended with data/ so that the user can execute easily from the project root while still only needing to provide the base name of any IO file (eg. hw7ex2_NumListShort.txt). So for this project, compilation & execution must occur from the project root; or, the hard-coded preprending of the data/ file path would need to be edited directly in the source code.
Similar compilation & execution behavior can be achieved through alternative commands, like:
cd CS1336/src
g++ *.cpp # or, g++ main.cpp hw_exercises.cpp (note that here, the default a.exe file is produced directly in src)
cd .. # go back to the project root
src/a.exe # can be executed with or without providing the .exe extension
Note that compilation and execution can be done either…
.exe extention (the code blocks above illustrate both)/ or backslash \ (the code blocks above do it with /)As a learning exercise, some of my code explores alternative designs that go beyond what was required for these courses.
This code is not intended as production software.