CMPT 125 Assignment 1 to 4 solutions

$100.00

Original Work ?
Category: Tags: , You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (1 vote)

CMPT 125  Assignment 1

Question 1 [5 marks]
Write a function that replaces a specific digit in an int number with another digit and returns the result as
an int. Return the same number if the target/replacement character is not a digit. Use this function header:
int replaceDigits(int number, char target, char replacement)
For example:
replaceDigits(1, ‘1’, ‘2’) should return 2
replaceDigits(-232, ‘3’, ‘0’) should return -202
replaceDigits(123, ‘4’, ‘5’) should return 123
replaceDigits(1223, ‘!’, ‘?’) should return 1223
replaceDigits(5670, ‘5’, ‘0’) should return 670 (leading zero will not be part of the resulting number)
replaceDigits(30400, ‘0’, ‘9’) should return 39499

You can assume the number does not have leading zeros (e.g., we will not call replaceDigits(01, ‘1’, ‘2’)),
except when the number is actually zero (i.e., we might call replaceDigits(0, ‘1’, ‘1’)).
Only include the a1_question.h header file and the function definition (and your helper functions, if any)
in the source file and name it as a1_question1.c. Do not use recursion in your answer.

Question 2 [5 marks]
Write a function that takes in 4 parameters: an int array, its size, the left index, and the right index; and
checks if the elements between the left and right index (inclusive) in the int array are sorted in ascending
order.

If the left index is larger than the right index, swap them first. Then, if the left index is invalid (e.g.,
negative, larger than the size), use the leftmost valid index of the array; if the right index is invalid, use
the rightmost valid index of the array. Use this function header:

bool rangedCheckforSorted(int array[], unsigned int size, int leftIndex, int rightIndex)
For example (suppose there is a myIntArray created as [-4, 3, -12, 0, 5, 72, 88, 128, 1, 64]):
rangedCheckforSorted(myIntArray, 10, -2, 3) will check indexes between 0 and 3, and return false
rangedCheckforSorted(myIntArray, 10, 7, 2) will check indexes between 2 and 7, and return true
rangedCheckforSorted(myIntArray, 10, 5, 5) will check indexes between 5 and 5, and return true
rangedCheckforSorted(myIntArray, 10, 0, 9) will check indexes between 0 and 9, and return false
You can assume the array has one or more elements and the size is always correct. Content of the int
array does not change after calling this function.

Only include the a1_question2.h header file, <stdbool.h>, and the function definition (and your helper
functions, if any) in the source file and name it as a1_question2.c. Do not use recursion in your answer.

Question 3 [6 marks]
In C arrays can be accessed using pointers. As an exercise, write a function that reverses the polarity of
every element in a 2D int array (i.e., -1 becomes 1, 46 becomes -46, …etc.) using only pointers. That is,
your code must not use any [ ], which is the non-pointer version of array access. Use this function header:
void reversePolarity(unsigned int row, unsigned int col, int** array)

For example, suppose we have a 2-by-3 array my2DIntArray with the content [[0, 1, -2], [-999, 2345, 678]].
Then the function will be called as (the array needs to be created differently, see the test file):
reversePolarity(2, 3, my2DIntArray)
And when the function returns, the content of my2DIntArray becomes [[0, -1, 2], [999, -2345, -678]].
You can assume that the row & col parameters always correctly indicate the number of rows & columns
of the array. Do not use [ ] anywhere in your answer (if you do you get 0 for this question).
Only include the a1_question3.h header file and the function definition (and your helper functions, if any)
in the source file and name it as a1_question3.c.

Coding Style [4 marks]
Your program should be properly indented, have clear and meaningful variable names (e.g., no singleletter variable names except loop iterators) and enough white space and comments to make it easy to
read. Named constants should be used where appropriate. Each line of code should not exceed 80
characters. White space should be used in a consistent manner. Remember to include your information.
To help you to get into the habit of good coding style, we will read your code and marks will be deducted
if your code is not styled properly.

Before You Submit
Before submitting your assignment, make sure you have test-run your code in our CSIL machines using
the steps covered in class: open your assignment folder in VS Code, use the gcc command with options
in the terminal to compile your code, and run the executable. We will use these steps when marking
your submission and will deduct marks if your code does not compile/run – to maintain fairness we do
not accept reasons like “but it worked on my computer” or “but it ran just fine in my IDE”.

The Makefile provided in this assignment is used by a command in the CSIL machines called “make” to
quickly compile your code. It is especially useful if you have multiple source files. To use it, type the
following command in the prompt (make sure you are in the directory with all the files of Assignment 1):
$ make test1

The example above illustrates how Question 1 is compiled into an executable called “test1” when using
the Makefile. Replace the “test1” with “test2”, “test3”, …etc. for other questions. You can then run the
executable by typing ./test1 to test your code for Question 1. If you make changes to your code, use the
make command again. You can also use make all if you want to compile all your code at once.
The test files (test1.c, test2.c, …etc.) are provided in this assignment for you to test your code. Each
typically contains a main function along with other tester functions and/or calls. You can modify them to
further test your code, but do not submit these test files because we will be using our test files that are
similar but not identical to grade your assignment. This makes sure that your code is not written to
produce hard-coded output.

The header files (question1.h, question2.h, …etc.) are there to make the compilation work. You can look
at them but do not modify them. You also do not have to submit them.

Submission
Submit only the 3 source files indicated above (a1_question1.c, a1_question2.c, a1_question3.c) to
CourSys. Refer to the corresponding Canvas assignment entry for details.
Assignment late penalty: 10% per calendar day (each 0 to 24 hour period past due), max 2 days late.

CMPT 125 Assignment 2

Question 1 [6 marks] Write a recursive solution that does exactly the same as what the function in Question 1 of Assignment 1 does. That is, replaces a specific digit in an int number with another digit and returns the result as an int. Return the same number if the target/replacement character is not a digit. Use this function header: int replaceDigitsRecursive(int number, char target, char replacement)

For example (for more examples refer to the description in Assignment 1): replaceDigitsRecursive(1, ‘1’, ‘2’) should return 2 replaceDigitsRecursive(-232, ‘3’, ‘0’) should return -202 replaceDigitsRecursive(998, ‘9’, ‘0’) should return 8 (leading zeros will not be part of the resulting number)

You can assume the number does not have leading zeros (e.g., we will not call replaceDigitsRecursive(01, ‘1’, ‘2’)), except when the number is actually zero (i.e., we might call replaceDigitsRecursive(0, ‘1’, ‘1’)). This question aims to let you practice recursion. One way to do so is to look at your answer for Assignment 1, separate the recursive case (most likely where you use a loop) from the base case (most likely the last step you do before returning the result). You should be able to see a significant simplification to your code. Do not use any global or static variables, or pass-by-reference (if you do so you get 0 for this question). Depends on how you solve this, you might have to create a recursive helper function that passes an extra parameter preserving the partial answer. IOnly include the a2_question1.h header file and the function definition (and your helper functions, if any) in the source file and name it as a2_question1.c.

Question 2 [4 marks] In the header file for this question, a struct called Superhero is defined like this: typedef struct { char* name; short feetInHeight; short inchesInHeight; char* superpower; char* traits; } Superhero; First, write a function that takes in 5 parameters: a pointer to a char array representing a name, two shorts representing feet in height and inches in height respectively, a pointer to a char array representing a superpower, and a pointer to a char array representing the traits; and returns the address of a dynamically (i.e., uses malloc) created Superhero struct variable storing those parameters.

Use this function header: Superhero* createSuperhero(const char* name, short feetInHeight, short inchesInHeight, const char* superpower, const char* traits) For example, given the code (name, superpower and traits are Cstrings storing the proper information): Superhero* superhero = createSuperhero(name, 6, 0, superpower, traits); printf(“%s\n%d\’%d\”\n%s: %s\n”, superhero->name, superhero->feetInHeight, superhero->inchesInHeight, superhero->superpower, superhero->traits); will result in an output like this: Thunderstrike 6’0″ Weather Control: Harnessing storms, Thunderstrike commands thunder and lightning, using nature’s fury to protect the innocent and fight against evil. You can assume all the height measurements are valid (i.e., feet & inches will not be negative), and all the Cstrings are properly formed (\0 terminated).

Field variables name, superpower, and traits in the struct must be created dynamically and are copies of the parameters, instead of simply pointing to the parameters’ addresses. This is called “deep-copy”. Next, write another function that takes in 1 parameter: the address of a Superhero struct variable; and releases (i.e., uses free) the memory created for the 3 field variables name, superpower, and traits. Use this function header: void clearSuperhero(Superhero* superhero) Note that the parameter can be NULL (if so the function should do nothing). Also, this function does not release the memory used for the struct variable, but only those used by the variable’s fields. To release all the memory dynamically allocated for the struct variable, you should call the free() function with the address of this struct variable right after the function returns. For details read Question 3. Only include the a2_question2.h header file and the function definitions(and your helper functions, if any) in the source file and name it as a2_question2.c. Do not use recursion in your answer.

Question 3 [6 marks] In this question you are going to make use of your answer for Question 2 to create a working program (so finish it first). You are also going to write your own main function so the program runs. Create a program that reads all the superhero information from the provided superheros.txt file and prints the information to the screen. Your program must meet these requirements: • Include the header file from Question 2 and use the functions defined there (createSuperhero and clearSuperhero) to complete this question. Do not redefine those functions. • Use a dynamic array of Superhero struct pointers to store the superhero information. This is the recommended approach (instead of a static array with a fixed size) as we might change the number of entries in the provided file, and dynamic arrays can accommodate that variation.

• There must be no memory leaks (e.g., your program requests some memory but does not release them all before it terminates). We will use a tool called valgrind to test the program compiled from your code which reports if there is any memory leaks (refer to Canvas for details). • Start with a fancy banner. There is no specific requirement besides it must include your name, 9- digit SFU ID, and your SFU email address. Let your creativity shine, just nothing offensive. • Print all the entries from the first to the last, along with a Superhero #. Do not reorder the entries*. *The entries are randomly generated using ChatGPT with a specific format and then lightly modified. Hence, the content might not make sense and have very similar wording patterns – no need to worry. Here is a sample output (the program terminates once the last entry is printed, note the Superhero #):

And here are some hints for you to write your code: • Use a loop to go through the file and call the functions from Question 2 in each iteration to build the dynamic array. A while-loop is likely the best as the number of entries in the file can change. • To learn to read and write to files see section “C Programming Files” in https://www.programiz.com/c-programming or https://www.tutorialspoint.com/cprogramming/c_file_io.htm or any other online resources. o In particular, look at the fscanf and fgets functions from stdlib.h (you’ll use both). • Don’t forget to close the file after reading it.

• To create a dynamic array with unknown size, a typical strategy is to start with a small array and double its size when it is at capacity. For example: int capacity = 16; //initial small size int used = 0; //no items in use yet int *intArray = (int *)malloc(sizeof(int)*capacity); //create an array of size 16 //… after filling up the array, keep increasing used each time you assign an item if (used == capacity) { capacity = capacity * 2; //double the capacity intArray = (int *)realloc(sizeof(int)*capacity); //request an array of size 32, keeping the items } Use this to build your dynamic array to store the superhero information (in this example each item is an int, in your code each item should be a pointer to a Superhero struct variable). You can assume the file will always have the name superheros.txt and will be available in the same directory as the program.

You can also assume the format for a superhero entry is consistent (first line starts with **Name:**, second line starts with **Height:**, third line starts with **Superpower:**, fourth line are the traits, and fifth line is an empty line), with each line having at most 300 characters. However, there is no guarantee on how many superhero entries are inside the file (the provided file is just an example), though each entry will have the exact same set of information. Write the main function (and your helper functions, if any) in the source file and name it as a2_question3.c. You can include any libraries that are covered in class (i.e., stdio, stdlib, string, math, stdbool).

Coding Style [4 marks] Your program should be properly indented, have clear and meaningful variable names (e.g., no singleletter variable names except loop iterators) and enough white space and comments to make it easy to read. Named constants should be used where appropriate. Each line of code should not exceed 80 characters. White space should be used in a consistent manner. Remember to include your information. Keep your code concise and efficient. If your code is unnecessarily long or inefficient (e.g., hard-code for all possible cases, extraneous function calls), we might deduct marks. To help you to get into the habit of good coding style, we will read your code and marks will be deducted if your code is not styled properly. Before You Submit Before submitting your assignment, make sure you have test-run your code in our CSIL machines using the steps covered in class: open your assignment folder in VS Code, use the gcc command with options in the terminal to compile your code, and run the executable. We will use these steps when marking

your submission and will deduct marks if your code does not compile/run – to maintain fairness we do not accept reasons like “but it worked on my computer” or “but it ran just fine in my IDE”. The Makefile provided in this assignment is used by a command in the CSIL machines called “make” to quickly compile your code. It is especially useful if you have multiple source files. To use it, type the following command in the prompt (make sure you are in the directory with all the files of Assignment 2): $ make test1

The example above illustrates how Question 1 is compiled into an executable called “test1” when using the Makefile. Replace the “test1” with “test2”, “test3”, …etc. for other questions. You can then run the executable by typing ./test1 to test your code for Question 1. If you make changes to your code, use the make command again. You can also use make all if you want to compile all your code at once. The test files (test1.c, test2.c, …etc.) are provided in this assignment for you to test your code. Each typically contains a main function along with other tester functions and/or calls. You can modify them to further test your code, but do not submit these test files because we will be using our test files that are similar but not identical to grade your assignment. This makes sure that your code is not written to produce hard-coded output. The header files (a2_question1.h, a2_question2.h, …etc.) are there to make the compilation work. You can look at them but do not modify them. You also do not have to submit them. Submission Submit only the 3 source files indicated above (a2_question1.c, a2_question2.c, a2_question3.c) to CourSys.

Refer to the corresponding Canvas assignment entry for details. Assignment late penalty: 10% per calendar day (each 0 to 24 hour period past due), max 2 days late.

CMPT 125 Assignment 3

Question 1 [16 marks]
In this question you are going to extend the program you made in Assignment 2 by providing more
functionalities. You are again going to write your own main function so the program runs.
Create a program that reads all the superhero information from a file and provide an interface for the
user to query superhero entries. Your program must support the following functionalities as options:

• Option 1: to load a data file – ask the user to input the name of the file containing superhero
information and load the entries from that file (report # of entries). Note that the file can be nonexistent (if so the program should print the error and keep running), but if it exists you can assume
the format inside that file is valid and consistent, with each line having at most 300 characters. It
is possible for the user to load a different file by choosing this option again, which will replace the
previously loaded entries. You can assume the filename has at most 50 characters and no space.

• Option 2: to list entries sorted by height – list the superheroes from shortest to tallest. Within
entries with the same height (if exist), they should be ordered by name (as determined by strcmp).
• Option 3: to list entries sorted by name – list the superheroes sorted by name (as determined by
strcmp). Within entries with the same name (if exist), they should be ordered by height.

• Option 4: to lookup a superhero – ask the user for a superpower for at most 50 characters (space
included), then report all entries with superpower having the input as a substring. There can be
more than one entry. The lookup is case-sensitive (i.e., “fly” and “Fly” are not the same).
o If one or more entries are found, print all the information. Any order is acceptable.
o If no entry is found, print “No such superhero on record.”
You can assume the user will always enter at most 50 characters.
• Option 5: to terminate the program – thank the user and end the program.

Your program must meet these requirements:
• Include the provided header file (.h file) and use the functions defined in the corresponding
implementation file (.c file) in your driver file (where main is), do not redefine those functions.
• Use a dynamic array of Superhero struct pointers to store the superhero information. This is the
recommended approach from A2 (instead of a static array with a fixed size) as we might change
the number of entries in the provided file, and dynamic arrays can accommodate that variation.

• There must be no memory leaks (e.g., your program requests some memory but does not release
them all before it terminates). In CSIL you can use the Valgrind tool as described to check for that.
• Start with a fancy banner. There is no specific requirement besides it must include your name, 9-
digit SFU ID, and your SFU email address. Let your creativity shine, just nothing offensive.

• If a functionality (e.g., list, lookup) is requested by the user but no file has been loaded, the
program should print an error message telling the user that no file have been loaded and prompt
the user to do so (e.g., “No superheroes file loaded. Load one first.”).
• The sorting for Options 2&3 can be done using any sorting algorithms covered in class, including
the built-in qsort, which requires to you to write your own compare functions. See
a3_superherolib.h for details.

And here are some hints for you to write your code:
• The program interface is essentially a do-while loop where in each iteration it asks for an option
and determines what to do, with a repeating conditional of the terminating option has not been
inputted. It is a common approach for menu-based interfaces.

• Since each item in the dynamic array for the superhero entries are pointers, be careful with how
you are casting the pointer variables in the compare functions for qsort (they are pointers to the
items) – suppose the dynamic array has the type A**, then the variables should be cast to A**.
• The scanf() function works slightly differently between different formats. One difference is how
it handles leading and trailing newlines (look up “dangling newline character” if you are curious).
One option to get around this is put a space in front of the format string (e.g., “ %d”, “ %s”). You
are encouraged to explore different ways to get around this issue.

*The entries are randomly generated using ChatGPT with a specific format and then lightly modified.
Hence, the content might not make sense and have very similar wording patterns – no need to worry.
Include the function definitions corresponding to a3_superherolib.h (and your helper functions, if any) in
a source file named as a3_superherolib.c. Remember the .h file only contains the function headers.
Include your main function definition (and of your helper functions, if any) in another source file named
as a3_superheroLookupSystem.c. We call this the driver file because this is where the program starts.

To determine where to place a helper function, think about its purpose. If it provides functionality with
the Superhero structs (e.g., create/clear Superheroes, compare Superheroes), it is a library function; if it
provides functionality of the program (e.g., print a fancy banner), it is a program function. Incorrectly
placing these functions will lead to mark deductions in the Coding Style category.

Here are some sample input and output (you can assume user input is always valid, but could be incorrect):
Figure 1. Inputting an incorrect option (9), opening a non-existent file (incorrect input) then an existing file (with 100 entries).

Figure 2. Listing superheroes sorted by height (note those with the same height are sorted by name).
Figure 3. Looking up for “strength” which has no result (but with “Strength” there will be one – Iron Guardian).

Figure 4. Looking up for “Sound” (4 results, order doesn’t matter) – yes there are actually name duplicates in the file!
Coding Style [4 marks]
Your program should be properly indented, have clear and meaningful variable names (e.g., no singleletter variable names except loop iterators) and enough white space and comments to make it easy to
read. Named constants should be used where appropriate. Each line of code should not exceed 80
characters. White space should be used in a consistent manner. Remember to include your information.
Keep your code concise and efficient. If your code is unnecessarily long or inefficient (e.g., hard-code for
all possible cases, extraneous function calls), we might deduct marks. To help you to get into the habit of
good coding style, we will read your code and marks will be deducted if your code is not styled properly.

Before You Submit
Before submitting your assignment, make sure you have test-run your code in our CSIL machines using
the steps covered in class: open your assignment folder in VS Code, use the gcc command with options
in the terminal to compile your code, and run the executable. We will use these steps when marking
your submission and will deduct marks if your code does not compile/run – to maintain fairness we do
not accept reasons like “but it worked on my computer” or “but it ran just fine in my IDE”.

The Makefile provided in this assignment is used by a command in the CSIL machines called “make” to
quickly compile your code. It is especially useful if you have multiple source files. To use it, type the
following command in the prompt (make sure you are in the directory with all the files of Assignment 3):
$ make test1

The example above illustrates how Question 1 is compiled into an executable called “test1” when using
the Makefile. Replace the “test1” with “test2”, “test3”, …etc. for other questions. You can then run the
executable by typing ./test1 to test your code for Question 1. If you make changes to your code, use the
make command again. You can also use make all if you want to compile all your code at once.

The header file a3_superherolib.h is there to make the compilation work. Take a look at it for information
about how each function should work. You might have to modify it and you will have to submit it this time.

Submission
Submit only the 3 source files (a3_superherolib.h, a3_superherolib.c, a3_superheroLookupSystem.c) to
CourSys. Refer to the corresponding Canvas assignment entry for details.
Assignment late penalty: 10% per calendar day (each 0 to 24 hour period past due), max 2 days late.

CMPT 125 Assignment 4

Question 1 [16 marks] In this question you are going to extend the program you made in Assignment 2&3 by providing more functionalities. You are also again going to write your own main function so the program runs. In addition, you are going to implement everything in C++. Create a program that reads all the superhero information from a file and provide an interface for the user to query superhero entries*.

Your program must support the following functionalities as options: • Option 1: to load a superheroes file – ask the user to input the name of the file containing superhero information and load the entries from that file (report # of entries). Note that the file can be non-existent (if so the program should print the error and keep running by printing all the options again), but if it exists you can assume the format inside that file is valid and consistent, with each line having at most 300 characters. It is possible for the user to load a different file by choosing this option again, which will replace the previously loaded entries. You can assume the filename has at most 50 characters and no space.

• Option 2: to list entries sorted by height – list the superheroes from shortest to tallest. Within entries with the same height (if exist), they should be ordered by name (as determined by strcmp). • Option 3: to list entries sorted by name – list the superheroes sorted by name (as determined by strcmp). Within entries with the same name (if exist), they should be ordered by height.

• Option 4: to lookup a superhero – ask the user for a superpower for at most 50 characters (space included), then report all entries with superpower having the input as a substring. There can be more than one entry. The lookup is case-sensitive (i.e., “fly” and “Fly” are not the same). o If one or more entries are found, print all the information. Any order is acceptable. o If no entry is found, print “No such superhero on record.”

You can assume the user will always enter at most 50 characters. • (NEW) Option 5: to add an entry – ask the user for all the information for a superhero (name, height, superpower, traits) and add it to the currently loaded entries. After adding, report and print “Entry added.”. You can assume the user will always input something in the correct format. o There is no need to check for duplicates. o Check for invalid height values: feet that are <0. If that happens, inform the user and keep asking for a valid feet, then do the same for inches.

• (NEW) Option 6: to save a file – ask the user to input the name of a file to which the current entries will be saved in the same format as the sample files. It is possible for the name to be the same as the file just being loaded. If so, it will be overwritten. Report # entries saved when done. • Option 7: to terminate the program – thank the user and end the program.

Options 1-4&7 are basically the same as Assignment 3. Yet, there are also some differences. In particular, since a vector is now used to store the superhero pointer entries, some functions that were defined in superherolib previously are now moved to better organize functions according to class definitions. The compare functions are also done differently. Pay attention to the provided .hpp files for details. Your program must meet these requirements: • Include the provided header file (.hpp file) and use the functions defined in the corresponding implementation file (.cpp file) in your driver file (where main is), do not redefine those functions. • Use the vector template in C++ (see https://www.programiz.com/cpp-programming/vectors) in combination of the Superhero struct defined in a4_superherolib to store and handle the entries. This allows different numbers of superhero entries and lets you practice using templates.

• Although C++ supports most of the operations in C, any operations we covered in the lecture replacing C must be used. This includes: console I/O must be done by cin/cout (see iostream), file I/O must be done by fin/fout (see fstream), text must be done by the string class, and memory management must be done by new/delete. • There must be no memory leaks (e.g., your program requests some memory but does not release them all before it terminates). In CSIL you can use the Valgrind tool as described to check for that.

• Start with a fancy banner. There is no specific requirement besides it must include your name, 9- digit SFU ID, and your SFU email address. Let your creativity shine, just nothing offensive. • If a functionality (e.g., list, lookup, add) is requested by the user but no file has been loaded, the program should print an error message telling the user that no superheroes file have been loaded and prompt the user to do so. • Use the built-in stable_sort in C++ (see https://cplusplus.com/reference/algorithm/sort/) to do the sorting for Options 2&3.

And here are some hints for you to write your code: • The program interface is essentially a do-while loop where in each iteration it asks for an option and determines what to do, with a repeating conditional of the terminating option has not been inputted. It is a common approach for menu-based interfaces. o Getting the user to input a valid input is exactly the same, with the repeating conditional being the input invalid (e.g., 0>userInput).

• The built-in stable_sort from C++ (defined in ) can sort items in different kinds of container classes as long as they provide access to the items using an “iterator”, which is a common design pattern in Object-Oriented Programming. Refer to our lecture examples and the reference link above for details. Also pay attention to how the compare function pointer works. • The way things are being read from the console and file is simplified with cin and fin. Besides the >> operator, there is a getline function for strings. Use it like this: getline(cin, stringVariable), or this after an int is read: getline(cin >> ws, stringVariable). You are encouraged to explore why.

*The entries are randomly generated using ChatGPT with a specific format and then lightly modified. Hence, the content might not make sense and have very similar wording patterns – no need to worry. Include the function definitions corresponding to a4_superherolib.hpp (and your helper functions, if any) in a source file named as a4_superherolib.cpp. Do the same for a4_superheroList. Both the .hpp files are provided to help you get started. They are adequate to complete this assignment, but if you want you can add/remove functions as appropriate – as long as they fulfill all the requirements stated above. Include your main function (and your helper functions, if any) in another source file named as a4_superheroLookupSystem.cpp.

We call this the driver file because this is where the program starts. To determine where to place a helper function, think about its purpose. If it provides functionality with the Superhero structs (e.g., create/clear Superheroes, compare Superheroes), it is a library function; if it provides functionality of the program (e.g., print a fancy banner), it is a program function; and if it provides functionality that directly accesses private members of the SuperheroList, it should be a member function of SuperheroList. Incorrectly placing these functions will lead to mark deductions in the Coding Style. Here are some sample input and output (you can assume user input is always valid, except Option 5): Figure 1. Choosing an option without opening any file then opening an existing file.

Figure 2. Listing superheroes sorted by height, note how they are also sorted by name (only showing the first 2 here for space). Figure 3. Looking up for “strength” which has no result (but with “Strength” there will be one – Iron Guardian). Figure 4. Adding a superhero to the list (it’ll be Superhero #16 when choosing Option 3 next). Figure 5. Saving the entries to a file (100 entries were loaded at start, adding 1 makes it 101) and loading it back.

Coding Style [4 marks] Your program should be properly indented, have clear and meaningful variable names (e.g., no singleletter variable names except loop iterators) and enough white space and comments to make it easy to read. Named constants should be used where appropriate. Each line of code should not exceed 80 characters. White space should be used in a consistent manner. Remember to include your information. Keep your code concise and efficient. If your code is unnecessarily long or inefficient (e.g., hard-code for all possible cases, extraneous function calls), we might deduct marks. To help you to get into the habit of good coding style, we will read your code and marks will be deducted if your code is not styled properly.

Before You Submit Before submitting your assignment, make sure you have test-run your code in our CSIL machines using the steps covered in class: open your assignment folder in VS Code, use the gcc command with options in the terminal to compile your code, and run the executable. We will use these steps when marking your submission and will deduct marks if your code does not compile/run – to maintain fairness we do not accept reasons like “but it worked on my computer” or “but it ran just fine in my IDE”. The Makefile provided in this assignment is used by a command in the CSIL machines called “make” to quickly compile your code. It is especially useful if you have multiple source files. To use it, type the following command in the prompt (make sure you are in the directory with all the files of Assignment 3): $ make test1 The example above illustrates how Question 1 is compiled into an executable called “test1” when using the Makefile.

Replace the “test1” with “test2”, “test3”, …etc. for other questions. You can then run the executable by typing ./test1 to test your code for Question 1. If you make changes to your code, use the make command again. You can also use make all if you want to compile all your code at once. The header files are there to make the compilation work. Take a look at them for information about how each function should work. You might have to modify them and you will have to submit them this time. Submission Submit only the 5 source files (a4_superherolib.hpp, a4_superherolib.cpp, a4_superheroList.hpp a4_superheroList.cpp, a4_superheroLookupSystem.cpp) to CourSys. Refer to the corresponding Canvas assignment entry for details. Assignment late penalty: 10% per calendar day (each 0 to 24 hour period past due), max 2 days late.