100% Guaranteed Results


CMSC 216 Exercise 3 Solved
$ 20.99
Category:

Description

5/5 – (1 vote)

1 Objectives
To practice dynamic memory allocation.
2 Overview
First, copy the directory photo album from the grace 216public exercises directory. As usual, that folder contains the .submit file that allows you to submit.
3 Grading Criteria
Your assignment grade will be determined based on the following weights:
Results of public tests 70%
Results of release tests 30%
5 Specifications
For this exercise, you will implement functions that support a photo album application. The prototypes for the functions are in file photo album.h.
1. 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 dynamically allocates memory to hold description’s string and sets the Photo struct’s description field to point to this allocated memory. If parameter description is NULL, no memory allocation takes place and the Photo struct’s description field 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).
2. 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.
3. void destroy photo(Photo *photo)
Deallocates all dynamically-allocated memory associated with parameter photo. The function does nothing if parameter photo is NULL.
4. void initialize album(Album *album)
1
Initializes 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.
5. 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.
6. void destroy album(Album *album)
7. 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
1. Use the C code development strategy described at http://www.cs.umd.edu/~nelson/classes/resources/ cdebugging/development_strategy/.
2. Your code must be written in the file photo album.c.
3. Do not add a main function to the photo album.c file.
4. Use the provided makefile to build public tests.
5. Your program should be written using good programming style as defined at http://www.cs.umd.edu/~nelson/classes/resources/cstyleguide/
6. You only have to implement the functions described above. You can have additional functions, but define them as static.
7. Do not change the photo album.h file provided.
8. You are encouraged to define your own tests (files similar to the public01.c, public02.c, etc. files provided).
9. You don’t need to use the macros SUCCESS and FAILURE defined in file photo album.h.
7 Submitting your assignment
Submit as usual.
2

Reviews

There are no reviews yet.

Be the first to review “CMSC 216 Exercise 3 Solved”

Your email address will not be published. Required fields are marked *

Related products