Lab 9
Logistics
- Due: Friday, March 28th AoE.
- Submission instructions: ensure that you have the eight files for this assignment in your
~/csci112_spring2025/labs/lab9directory, and that the snapshot (commit) of your repository containing the version of that file you want us to grade has been committed and tagged aslab9. (You should have set up yourgitrepo and practiced tagging a commit in Classwork 4.)
Outside resources
On this assignment, you may not use the internet or generative AI such as ChatGPT to solicit solutions to the programming part of the assignment. If you are having trouble writing your program, please go to lab (Fridays, 10am-4pm in Barnard 254) or post in Slack to get help.
However, you may use those resources for help with navigating the Linux terminal, using vim, and using git, although you may get better answers to your questions by going to lab or posting on Discord anyway.
Learning outcomes
- Practice splitting a C program into separate files.
- Practice writing a
Makefile. - Practice compiling a C program with
make.
Assignment
In this lab, you split your Lab 8 solution into multiple header (.h) and source code (.c) files. You will also
write a Makefile so that you can recompile only code that is affected by a
change.
Note: you should not need to write any new code in this assignment, except perhaps function prototypes. If you use your own Lab 8 solution (or solution in /public/labs/lab9/solution.c) and you don’t have functions for sorting or any additional utility functions, you can add those so that you have things to put in the sorting and utility files described below. But you should not change the functionality of the program.
Files
You will need eight total files for this assignment.
lab9.cshould contain yourmainfunction and no other C code. (It should also contain some#includepreprocessor directives.)county.hshould hold theCountystruct definition and function prototypes for any county-related functions; at minimum, it should have a function prototype foradd_county.county.cshould contain the definition of any functions incounty.h.sort.hshould contain function prototypes for any sorting-related functions. If you are using your Lab 8 solution, these areget_min_in_rangeandsort.sort.cshould contain the definitions of any functions insort.h.utils.hshould contain prototypes for any extra “utility” functions. If you are using the provided Lab 8 solution, these aremenu,find_seat, andfind_range.utils.cshould contain the definitions of any functions inutils.h.Makefileshould provide a set of rules for compiling your program.
Header guards
All .h files should include header guards.
Makefile
Your makefile should encode the dependencies of your program and result in a
final executable called lab9. If you used the
Lab 8 solution, your dependencies are:
- the Lab 9 executable
lab9depends on object files compiled fromlab9.c,sort.c,county.c, andutils.c. - the lab 9 object file depends on
lab9.candcounty.h - the sort object file depends on
sort.candsort.h - the county object file depends on
county.candcounty.h - the utils object file depends on
utils.c,utils.h, andcounty.h
Hints
Grading–100 points
- 10: all eight files exists with correct name in correct location
- 20:
makecompileslab9without warnings - 20:
lab9still works as Lab 8 (passes tests from Lab 8 autograder) - 10: all header files have header guards
- 10:
lab9.ccontainsmainand no other source code - 5 each:
county.cdefines functions incounty.h,sort.cdefines functions insort.h,utils.cdefines functions inutils.h. - 10:
Makefileencodes the dependencies of the program so that only code that needs to be recompiled is recompiled - 5:
county.hcontains the definition for aCountystruct
Autograder
You can run the autograder using
/public/labs/lab9/autograder.sh
A detailed breakdown of your score will be present in autograder.txt.
Grading turnaround
Scores will be uploaded to D2L by class time the Monday after the due date.