Alex09-work.zip
Alex09-0000/.gitignore
*~*.swp*.omainmain-testsgrader-outputresults.json
Alex09-0000/images/imageCube.png
Alex09-0000/input/input.txt
| . | | * | * . / * | . / . ___—___ / . .– –./ ~-_ * ./ . * _-~ ~-_ / ^ ^ _-~ * * ~-/ ___ ___ -~ . | (_O_) (_O_) | . * | | * ———–| |———– . | < > | . * | / | * _- `. .' /-_ * . _-~ . `-.___.-' / ~-_ _-~ ` /'* ~-_ ~ /`–___ ___–' ~ * / — . jgs . / * | / | * . | . | | ' . ' . . . : . . '. ______ .' ' _.-"` `"-._ ' .' '. `'–. / .–'` / ; ; – — | | — – | _. | ; /__`A ,_ ; .-' |= |;._.}{__ / '-. _.-""-|.' # '. ` `.-"{}<._ / 1938 x `" —-/ _.-'|–X—- -=_ | | |- X. =_ – __ |_________|_.-'|_X-X## jgs `'-._|_|;:;_.-'` '::. `"- .:;. .:. ::. '::. __. .-".' .–. _…_ .' .' .' .-"" __ ""-. / / .' : –..:__.-"" ""-. : : / ;.d$$ sbp_.-""-:_: ; : : ._ 😛 .-. ,"TP : T–…-; : d$b :d$b `. `..' ; $ $ ;$ $ `. "-. ). : T$P :T$P ..—^.. / `-' `._`._ .' "-. .-" T$$$b / "-._.-" ._ '^' ; : .`. / ; -. `."-._.-'-' : .' ; ; /: . ; : : , ; `. `.; : ; ; ; "-._: ; : `. : : / ; /"-. ; : : / "-. : : ; : .' T-; ; ; ; : ; ; / : ; ; : : .' ; : : ;: _..-" : : : ; / ; ; . '. '-; / ; : ; ; : : : : '-. '.._L.:-' : ; bug ; . `. ; : : ; : : '-.. '.._L.:-' ; , `. : ; : '..__L.:-' , `-._ __ \ `-..____,.' `. :`. / `. : ) : : ;' ' ; | : ).. .. .:.`.; : /::… .:::… ` ; ; _ ' __ /: `:o> /o_> ;:. `. `-`.__ ; __..— /:. === _/ ;=====_.':. ; ,/'`–'…`–…. ; ; ; .' ; .' ; .' .. , . ; : ::.. / ;::. | / `.;::. | ;:.. ; : |:. : ;:. ; : :: ;:.. |. ; : :; :::….| | / ,/ ;:::::; ; .:. :..| : ; '.–| ; ::. :'' `-.,,; ;' ; ; .-'. _.' / `; ,__: `—' `—-' ; / ,.,,,/ `—-` fsc __ .d$$b .' TO$; / : TP._; / _.; :Tb| / / ;j$j _.-" d$$$$ .' .. d$$$$; / /P' d$$$$P. | / " .d$$$P' |^"l .' `T$P^""""" : ._.' _.' ; `-.-".-'-' ._. _.-" .-" `.-" _____ ._ .-" -(.g$$$$$$$b. .' ""^^T$$$P^) .(: _/ -" /.' /:/; ._.'-'`-' ")/ /;/; `-.-"..–"" " / / ; .-" ..–"" -' : ..–""–.-" ( .-( ..–"" `-(/;` _. : ;`- : ; bug /| | `__\ //__' || || __` |'__/ `_\ //_' _.,:—;,._ _: :_/ |@. .@| | | ,.-./ ;;`-' `—__________—–.-. ;;; _ ';;; | ; | ; | / _, / | |';| |,,,,,,,,/ _ | | | / | | | / | | || | | | | | | || | | | | | | || | | | | | |_||_| |_| |_| /_//_/ /_/ /_/
Alex09-0000/INSTRUCTIONS.md
# Lab 09 – ArraysIn this lab assignment, we'll be practicing the following:* Loading n-dimensional arrays from a file* Printing 2D arrays that happen to be sitting inside 3D arrays* Utilizing parallel arrays to (begin to) store more complex data## Source FilesYou should see the following files:|File / Folder |Description |Should you edit? ||:– |:– | –:||main.cpp |Sample code you can use to test your functions, yourself. |Edit if you wish, but not required ||Makefile |Tells our build system how to build your project and tests. |Do not edit ||my_functions.hpp |This file needs the declarations of all required functions. |***YES, complete this!*** ||my_functions.cpp |This is the primary source file you'll write. It will contain definitions of all required functions. |***YES, complete this!*** |Essentially, you should complete ***my_functions.hpp*** and ***my_functions.cpp***. The ***main.cpp*** file is optional and already setup to help you check your work a bit.You can also look inside each file and see a reminder in a comment at the top.### main.cppDo what you want to this file, or nothing at all. It will probably be helpful to comment-out all existing code here, and use `main()` to test only the one specific function you're working on at any given time. Executing `make run` will run *main.cpp* as a standalone program.### my_functions.hppYou are now also responsible for filling out *my_functions.hpp* with the prototypes of all your functions. You should also add include guards.Do not modify the line containing `class MyClass{};`. That will help the tester detect your include guards. Removal or tampering of this line will result in grading penalties.### my_functions.cppNearly all of your work goes into the ***my_functions.cpp*** file. Here, you'll define all required functions. For each of the following sibling subsections, carefully craft a function that meets the described requirements. When you're done, try `make run` to see some sample output against all functions, and modify *main.cpp* as you please (again, *main.cpp* won't be graded).## What to Do### Loading n-dimensional ArraysYou will load data from a file located at `input/input.txt` within your repository. Make a `void` function named `loadImages` that takes a 3D `char` array as its first argument, and the `std::string` name of an input file as its second argument. The *main.cpp* program is already setup to call this function with the appropriate file name for you.Recall that we can use [std::ifstream](https://en.cppreference.com/w/cpp/io/basic_ifstream) to load data from a text file. We also *could* use the [stream operator](https://en.cppreference.com/w/cpp/io/basic_istream/operator_gtgt) to load and parse data at the same time (but we won't today). This project will provide you with a data file that isn't formatted, and shouldn't be parsed with stream operators. Instead, you are to grab [one byte at a time](https://en.cppreference.com/w/cpp/io/basic_istream/get) and load them into your 3 dimensional array.#### Multiple Images as a CuboidImagine for a moment, what a picture might look like in a 2D array. You have rows and columns – just like a 2D table – but each cell is merely a single pixel. What if you stacked multiple images on top of each other? You'd end up with a *cuboid*, where each 2D slice of pixels is an image. Fanned out slightly, the cuboid might look like the following:> Image credits:> > * [Birds and nature magazine (1896)](https://commons.wikimedia.org/wiki/File:Birds_and_nature_magazine_(1896)_(19761463464).jpg)> * [Birds and nature magazine (1896)](https://commons.wikimedia.org/wiki/File:Birds_and_nature_magazine_(1896)_(20375679492).jpg)> * [Nature Village](https://commons.wikimedia.org/wiki/File:Nature_Village,_Ratnagiri,_Maharashtra_(kokan)_5.jpg)> * [Shaqi Waterfall](https://commons.wikimedia.org/wiki/File:Shaqi_jrvej.jpg)#### Accessing a Cuboid ArrayYou can probably imagine accessing a single image from a 2D array using X and Y coordinates. But how would we access images stored within a 3D cuboid in this way? We can simply use a third coordinate, which we'll call *Z* here. The *Z* coordinate will refer to the *index of the image we want*. We can now imagine a 3D cuboid array of pictures that might look something like:“`cppPixel images[N_IMAGES][IMAGE_HEIGHT][IMAGE_WIDTH];// Dimension: Z Y X“`Notice that the above example orders the dimensions in a slightly surprising way. You might normally expect width to precede height, and Z to come last, and see *X, Y, Z*. Honestly, the order doesn't matter *too much* if your program is consistent everywhere. However, when creating arrays that dynamically change their size as you fill them (e.g., *vectors* which we'll learn later), it is often convenient to start with the "largest" dimension first (i.e., dimension that might be a container for other dimensions) and work your way down. We'll start using this pattern now.So imagine accessing an image. The first biggest thing you'd want to know is *What image are we accessing?*, which explains why the *Z* dimension (`N_IMAGES`) comes first. Next, you'd scan an image row-by-row, so the *Y* dimension (`IMAGE_HEIGHT`) comes next. Finally, within a row, you scan column by column, or the *X* dimension (`IMAGE_WIDTH`).Now imagine, instead of each cell representing a *pixel*, we'll just use a `char` to store images of [ASCII Art](https://en.wikipedia.org/wiki/ASCII_art). Keep supposing that, because that is exactly what we're going to do!“`cppchar images[N_IMAGES][IMAGE_HEIGHT][IMAGE_WIDTH];“`#### Putting it All TogetherSo how do we put this all together to load a cuboid of images from a blob of unformatted data, into a 3D array? Simply put: Use three `for` loops (triply nested) to keep track of each dimension as you grab `char`s from the input file. Iterate over *Z* first, then *Y* for the inner loop, then *X* for the inner-inner loop. At that point, each `char` you grab can be placed into the correct position of your 3D array using those XYZ coordinates. Don't forget to grab [one byte at a time](https://en.cppreference.com/w/cpp/io/basic_istream/get) rather than using a stream operator.“`cpp//This is totally pseudo-code, for inspirational purposes onlyfor Z COORDINATE {for Y COORDINATE {for X COORDINATE {}}}“`The real question is: *How big is each dimension?* Here you go:|Dimension|Meaning |Size ||:——-:|:————————-|—-:||x |Width of each image |60 ||y |Height of each image |34 ||z |Number of images in total |6 |You can assume each image has these exact *X* and *Y* dimensions, for convenience.Recall also, you can only size an array using a constant or literal value. In this case, we want to setup the following in our *hpp* function header file:“`cppconst size_t IMAGE_COUNT = 6;const size_t IMAGE_WIDTH = 60;const size_t IMAGE_HEIGHT = 34;“`#### N-DimensionsWe won't go beyond 3 dimensions for this lab, but you can probably imagine reasons to use 4 or more dimensions. What if you wanted to group images together into *sets*? You could assign an additional dimension to denote the set. What if you wanted *sets* that belong to a particular user? You could probably add a fifth dimension. And on and on and on …### Printing a 2D ASCII ImageAt this point, printing one of the 2D images should be a breeze. Just use two `for` loops – one for the *X* and the other for the *Y* coordinate (not necessarily in that order). The *Z* coordinate should remain fixed to the index of the image you wish to print. All you really need to do, is print each `char` as it's loaded, and print a newline (`endl`) when you reach the end of a row.Create another `void` function named `printImage` that takes in your 3D array as its first argument, and a `size_t` index as its second argument. The function will then print the entire ASCII image specified by the index argument.You'll know you've written `loadImages` and `printImage` correctly when the *main.cpp* program shows you pictures of cute animals and nature.You'll also probably notice that the default *main.cpp* let's the user use a 1-based index scheme for input, then silently adjusts it to a 0-based index scheme. This is another example of translating the user's input a bit (and/or translating output) so the user can have a better experience.### School Admin (Parallel Arrays)Next, we'll practice parallel arrays by writing a fictitious system to store and manipulate student information. You will create three parallel arrays:* An array of `std::string`s representing student names* An array of `double`s representing student GPAs* An array of `bool`s representing whether a student is currently enrolled, or notThe parallel arrays will represent 50 students total.Create a `void` function named `schoolAdmin`. The function should start by initializing all students:* Set their names to `"Unnamed Student"`* Set their GPAs to `0.0`* Set their enrollment status to `false` (aka *Not enrolled*)The function will then enter into a loop where it continually asks the user which student they'd like to edit. Have it print the range of valid indexes, which would be from 0 to *n-1*, where *n* is the total number of students. Once the user enters an invalid index, complain *Invalid student; Quitting!* and break the loop, which in turn returns from the function.If the user enters a valid index, consider that to be the student's *ID*. At that point, call the next function: `editStudent`.### Editing a StudentMake a void function called `editStudent` that takes the following arguments:1. The student's ID as a `size_t`2. An array of `std::string`s representing student names3. An array of `double`s representing student names4. An array of `bool`s representing student enrollment statuses * `true` means the student is currently enrolled * `false` means the student isn't enrolledThe function should inform the user of which student is being edited, then provide a secondary menu, with the following choices:1. Edit the student's name2. Edit the student's GPA3. Edit the student's enrollment statusThis menu should *not* be looped.If the user provides an invalid selection, complain *Invalid Input!*Otherwise, call one of the following functions based on the user's input:* `editStudentName`* `editStudentGPA`* `editStudentEnrollmentStatus`### Editing a Student's NameMake another `void` function named `editStudentName`, and give it the same signature as `editStudent`. When calling this function from `editStudent`, you'll already have all the arrays you need (they were provided to `editStudent`) to send into `editStudentName`.The function should ask the user to enter the student's new name (with no spaces, to make it easy to use `cin`), and and then apply that name to the particular student in question. Remember, the student's ID is actually their `size_t` array index.After setting the new data, call `printStudent` to print out the entire student.### Editing a Student's GPAMake another `void` function named `editStudentGPA`. This will have the same signature as `editStudentName` and behave very similarly.However, have this function ask the user to enter the student's new *GPA*, and then apply it to the particular student in question.Again, after setting the new data, call `printStudent` to print out the entire student.### Editing a Student's Enrollment StatusMake another `void` function named `editStudentEnrollmentStatus`, which again, will have the same signature as `editStudentName` and behave similarly.However, have this function ask the user whether the student is currently enrolled, by entering a value of `y` or `n` (yes or no). Process the user's input *cAsE-iNSEnsitIVEly*. If the user enters `y` (yes), set their enrollment status `bool` to `true`. If the user enters no, set it to `false`. Otherwise, complain *Invalid input; Won't change enrollment status* and don't change anything.Again, after setting the new data, call `printStudent` to print out the entire student.### Printing the StudentFinally, we need something to print an entire student. Make a `void` function named `printStudent` that has the same signature as the functions above (ID, names, gpas, enrollments).Quickly check that the student ID is in-bounds. If it is not, throw a runtime error with the following code:“`cppthrow std::runtime_error("printStudent() – Invalid student ID: " + std::to_string(id));“`Otherwise, print the following information:“`textStudent ID: STUDENT_IDStudent Name: STUDENT_NAMEStudent GPA: STUDENT_GPAStudent Enrolled: ENROLLMENT_STATUS“`Obviously, replace the above tokens with the following:|Token |Replacement ||:—————–|:——————————————————————————||STUDENT_ID |The current student's ID ||STUDENT_NAME |The current student's name ||STUDENT_GPA |The current student's GPA, using 1 digit of precision after the decimal point ||ENROLLMENT_STATUS |`Enrolled` if the student is enrolled; `Not Enrolled` if they are not enrolled |## Hints and TipsThis section to contain hints and tips.The *main.cpp* file will be tremendously helpful this time around. Don't forget to try your program with `make run` as you work.## Sample OutputsThe output of a winning program might look like the following, if you choose not to modify *main.cpp*:“`console$ ./mainHello, my name is Burgundy Flemming!Please enter an image to print from 1 to 6: 2[ASCII image removed to create suspense]Please enter an image to print from 1 to 6: 3[ASCII image removed to create suspense]Please enter an image to print from 1 to 6: 10Out of bounds; Quitting!***** School Admin *****What student would you like to edit?Enter a student ID from 0 to 49 ==> 3*** Editing Student #3 ***Student ID: 3Student Name: Unnamed StudentStudent GPA: 0.0Student Enrolled: Not Enrolled1. Edit student name2. Edit student GPA3. Edit student enrollment statusEnter your selection: 1Enter the student's new name (no spaces): BurgundyStudent ID: 3Student Name: BurgundyStudent GPA: 0.0Student Enrolled: Not Enrolled***** School Admin *****What student would you like to edit?Enter a student ID from 0 to 49 ==> 3*** Editing Student #3 ***Student ID: 3Student Name: BurgundyStudent GPA: 0.0Student Enrolled: Not Enrolled1. Edit student name2. Edit student GPA3. Edit student enrollment statusEnter your selection: 2Enter the student's new GPA: 3.6Student ID: 3Student Name: BurgundyStudent GPA: 3.6Student Enrolled: Not Enrolled***** School Admin *****What student would you like to edit?Enter a student ID from 0 to 49 ==> 5*** Editing Student #5 ***Student ID: 5Student Name: Unnamed StudentStudent GPA: 0.0Student Enrolled: Not Enrolled1. Edit student name2. Edit student GPA3. Edit student enrollment statusEnter your selection: 1Enter the student's new name (no spaces): GaryStudent ID: 5Student Name: GaryStudent GPA: 0.0Student Enrolled: Not Enrolled***** School Admin *****What student would you like to edit?Enter a student ID from 0 to 49 ==> 5*** Editing Student #5 ***Student ID: 5Student Name: GaryStudent GPA: 0.0Student Enrolled: Not Enrolled1. Edit student name2. Edit student GPA3. Edit student enrollment statusEnter your selection: 2Enter the student's new GPA: 2.5Student ID: 5Student Name: GaryStudent GPA: 2.5Student Enrolled: Not Enrolled***** School Admin *****What student would you like to edit?Enter a student ID from 0 to 49 ==> 5*** Editing Student #5 ***Student ID: 5Student Name: GaryStudent GPA: 2.5Student Enrolled: Not Enrolled1. Edit student name2. Edit student GPA3. Edit student enrollment statusEnter your selection: 3Is the student currently enrolled? (y/n): yStudent ID: 5Student Name: GaryStudent GPA: 2.5Student Enrolled: Enrolled***** School Admin *****What student would you like to edit?Enter a student ID from 0 to 49 ==> 3*** Editing Student #3 ***Student ID: 3Student Name: BurgundyStudent GPA: 3.6Student Enrolled: Not Enrolled1. Edit student name2. Edit student GPA3. Edit student enrollment statusEnter your selection: 3Is the student currently enrolled? (y/n): yStudent ID: 3Student Name: BurgundyStudent GPA: 3.6Student Enrolled: Enrolled***** School Admin *****What student would you like to edit?Enter a student ID from 0 to 49 ==> -3Invalid student; Quitting!“`
Alex09-0000/main.cpp
Alex09-0000/main.cpp
/**
* You do not need to edit this file, though you may if you wish.
*
* This file will not be graded. Instead, the unit tests executed by CPP_Tests.cpp will determine your grade.
*
* Feel free to modify this source file to help you test the functions you make, or ignore it altogether.
*/
//
#include < iomanip >
#include < iostream >
#include < string >
//
#include "my_functions.hpp"
//
using std :: cin , std :: cout , std :: endl ;
using std :: string ;
//
int main ()
{
//
cout << "Hello, my name is Burgundy Flemming!" << endl ;
//
char images [ IMAGE_COUNT ][ IMAGE_HEIGHT ][ IMAGE_WIDTH ];
loadImages ( images , "input/input.txt" );
//
while ( true )
{
cout << "Please enter an image to print from 1 to " << IMAGE_COUNT << ": " ;
size_t i ;
cin >> i ;
i -- ;
if ( i >= IMAGE_COUNT ) {
cout << "Out of bounds; Quitting!" << endl ;
break ;
}
printImage ( images , i );
}
//
schoolAdmin ();
return 0 ;
}
Alex09-0000/Makefile
# DO NOT EDIT THIS FILEdefine say$(info [Project Makefile] $1)endef#REPO_PATH := $(realpath .)$(call say,REPO_PATH: $(REPO_PATH))#CC := g++CC_STD := c++17CFLAGS := -Wall -Werror -pedantic -std=$(CC_STD) -g -I. -cLINK_FLAGS := -Wall -Werror -pedantic -std=$(CC_STD) -I.#BIN_NAME := mainBIN := ./$(BIN_NAME)#BIN_TESTS_NAME := main-testsBIN_TESTS := ./$(BIN_TESTS_NAME)#default: helphelp:@echo "***** Build Menu *****"@echo ""@echo "make help ==> This menu"@echo@echo "make build ==> Build all files"@echo "make run ==> Run the program"@echo "make clean ==> Clean the build files"@echo@echo "make gradescope ==> Launch gradescope grader (not for students)"@echo "".PHONY: default help#build: $(BIN).PHONY: build#run: build$(call say,Running: $(BIN_NAME))$(BIN).PHONY: run#gradescope: cleangradescope:testtests:testtest:$(BIN_TESTS)$(BIN_TESTS).PHONY: gradescope tests testdebug-test:debug-testsdebug-tests:$(BIN_TESTS)gdb $(BIN_TESTS) -ex run.PHONY: debug-test debug-tests#$(BIN):main.o my_functions.o$(call say,Building: "$@")$(CC) $(LINK_FLAGS) $^ -o "$@"#$(BIN_TESTS):CPP_Tests.o my_functions.o$(call say,Building: "$@")$(CC) $(LINK_FLAGS) $^ -o "$@"#main.o:main.cpp$(call say,Building: "$@")$(CC) $(CFLAGS) $< -o "$@"#my_functions.o:my_functions.cpp my_functions.hpp$(call say,Building: "$@")$(CC) $(CFLAGS) $< -o "$@"#CPP_Tests.o:CPP_Tests.cpp my_functions.hpp puhp-tests/*.hpp$(CC) $(CFLAGS) $< -o $@#clean:-rm $(BIN)-rm $(BIN_TESTS)-rm *.o-rm results.json.PHONY: clean
Alex09-0000/my_functions.cpp
Alex09-0000/my_functions.cpp
// TODO: Your code here
/// YER WELCOME
#include "my_functions.hpp"
Alex09-0000/my_functions.hpp
/**TODO: Your Code hereYou will fill out this file as an include'able header for your functions.This file should contain all your prototypes,while the other file (my_functions.cpp) will contain your definitions.Refer to previous labs if you forget what this means.*//** * DO NOT remove or edit the following line * Make sure it ends up inside your include guard, though.*/namespace FNFIUNWEF{namespace HF337ZZHF{namespace HEWUFHEUFH{class MyClass{};}}}