CProjects - six short assignments to be implemented in the C programming language
CSSE 221 – Fundamentals of Software Development Honors
Fall 2008–2009
Work on these exercises
individually,
but be quick to get help as needed from your student assistants,
your instructor and your classmates.
CProject: ArrayListOfDogs (resizable arrays of structures)
Overview
This project integrates what you have learned about:
- dynamic arrays,
including malloc and free.
- structures,
in particular, pointers to structure objects.
Instructions
- Checkout from your individual repository the project
called ArrayListOfDogs.
- Read all of the code in the project so far, noting especially:
- In ArrayListOfDogs.c:
- What main does.
- What the other (stubbed) functions in main are supposed to do.
(DON'T implement them yet!)
- The fact that ArrayListOfDogs.c
#includes ArrayListOfDogs.h.
- In ArrayListOfDogs.h:
- How the compiler directives prevent the code from being compiled more than once.
- The presence of the prototypes.
- The ArrayListOfDog structure that you will fill in.
(DON'T fill it in yet!)
- In Dog.h:
- In Dog.c:
- The fact that Dog.c
#includes Dog.h.
- Implementations of the Dog functions that are very similar to the implementations
that you wrote in your previous Dog exercise.
- The use of rand() in constructRandomDog.
Make sure you understand rand().
- The fact that for strings of length N, the code malloc's N+1 characters --
the extra character is for the terminating \0.
- The use of the strcpy and strlen functions
in constructDog.
- Run main, noting that it compiles and runs
but prints nonsense values (because of the stubs).
- In ArrayListOfDogs.h,
fill in the fields of the structure called ArrayListOfDogs
so that has the following fields:
- A dynamic array of pointers to Dogs.
- An integer size for the array.
- The size is how many values are actually stored in the array.
Your constructor will initialize the size to 0.
- An integer capacity for the array.
- The capacity is how many values the array
has been allocated to store.
Your constructor will initialize the capacity to 5.
- Get your work so far graded,
by your instructor, student assistant or a newly-promoted student assistant.
- The grader should refer to the written answer key.
- Write and test the stubbed functions in ArrayListOfDogs.c,
per their comments.
- As always, write-and-test in small steps.
- Make sure your internal list grows as specified.
- Make sure that you free the now-unused space when your internal list grows.
- Here is what my solution produces as output
when the loop in main is changed to run 22 (not 6) times.
- Get your work so far graded,
by your instructor, student assistant or a newly-promoted student assistant.
- The grader should refer to the written answer key.
- Turn in your work by committing your project to your individual repository.