Description
Academic integrity statement
Please carefully read the academic honesty section of the course syllabus. We take academic integrity matters
seriously. Please do not post assignment solutions online (e.g., Chegg, github) where others can see your
work. Posting code online can lead to an academic case where you will be reported to the Offifice of Student
Conduct.
5
Specififications
For this exercise, you will implement functions that support a photo album application. The prototypes for
the functions are in fifile photo album.h.
- Photo *create photo(int id, const char *description)
Returns a dynamically-allocated Photo struct initialized based on the provided parameters. If parameter
description is not NULL, assume it points to a nul-terminated string. In this case, the function dynami
cally allocates memory to hold description’s string and sets the Photo struct’s description fifield to point
to this allocated memory. If parameter description is NULL, no memory allocation takes place and the
Photo struct’s description fifield is initialized to NULL. The function returns NULL if a memory allocation
fails. You don’t have to worry about freeing memory if any memory allocation fails (e.g., one memory
allocation is successful, but a second one fails).
- void print photo(Photo *photo)
Prints the photo’s id and description. If the description is NULL, the message description message is
”None”. The function does nothing if the photo parameter is NULL. See the public tests for information
regarding output format.
- void destroy photo(Photo *photo)
Deallocates all dynamically-allocated memory associated with parameter photo. The function does
nothing if parameter photo is NULL.
- void initialize album(Album *album)
1Initializes the album size to 0. Assume this function is not called on an album that has already been
initialized. The function does nothing if parameter album is NULL.
- void print album(const Album *album)
Prints the contents of the album. If the album has no photos, the message ”Album has no photos.” is
printed. The function does nothing if parameter album is NULL. See the public tests for information
regarding output format.
- void destroy album(Album *album)
Deallocates all dynamically-allocated memory associated with parameter album and sets the album’s
size to 0. (The Album struct itself is not deallocated, so “clear album” may be a better name for this
function.) The function does nothing if parameter album is NULL.
- void add photo to album(Album *album, int id, const char *description)
Appends (to the end of the array) a photo if there is space (if the album size is less than MAX ALBUM SIZE).
photo is added if a photo cannot be created. The function does nothing if parameter album is NULL or
the album has no space for the photo.
You want to look at the public tests in order to understand the functionality associated with the functions
above.
6
Requirements
- Use the C code development strategy described at http://www.cs.umd.edu/~nelson/classes/resources/
cdebugging/development_strategy/.
- Your code must be written in the fifile photo album.c.
- Do not add a main function to the photo album.c fifile.
- Use the provided makefifile to build public tests.
- Your program should be written using good programming style as defifined at
http://www.cs.umd.edu/~nelson/classes/resources/cstyleguide/
- You only have to implement the functions described above. You can have additional functions, but
defifine them as static.
- Do not change the photo album.h fifile provided.
- You are encouraged to defifine your own tests (fifiles similar to the public01.c, public02.c, etc. fifiles pro
vided).
- You don’t need to use the macros SUCCESS and FAILURE defifined in fifile photo album.h.
- To check for memory problems, you can use the CMSC216 memory tool (my memory checker), val
grind, or gcc -fsanitize=address. Remember to only use one at a time, otherwise you may get confusing
information. If you want to disable the CMSC216 memory tool in the public tests, comment out the
function calls start memory check() and stop memory check().





