Lab 9
Logistics
- Due: Friday, April 5th AoE.
- Submission instructions: ensure that you have the eight files for this assignment in your
~/csci112_spring2024/labs/lab9
directory, 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 yourgit
repo and practiced tagging a commit in Classwork 4.)
Outside resources
On this assignment, you may not use the 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 (or the solution
provided in /public/labs/lab8/solution.c
by class time on Friday, March 22) 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 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.c
should contain yourmain
function and no other C code. (It should also contain some#include
preprocessor directives.)county.h
should hold theCounty
struct definition and function prototypes for any county-related functions; at minimum, it should have a function prototype foradd_county
.county.c
should contain the definition of any functions incounty.h
.sort.h
should contain function prototypes for any sorting-related functions. If you are using the provided Lab 8 solution, these areget_min_in_range
andsort
.sort.c
should contain the definitions of any functions insort.h
.utils.h
should contain prototypes for any extra “utility” functions. If you are using the provided Lab 8 solution, these aremenu
,find_seat
, andfind_range
.utils.c
should contain the definitions of any functions inutils.h
.Makefile
should 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
lab9
depends on object files compiled fromlab9.c
,sort.c
,county.c
, andutils.c
. - the lab 9 object file depends on
lab9.c
andcounty.h
- the sort object file depends on
sort.c
andsort.h
- the county object file depends on
county.c
andcounty.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:
make
compileslab9
without warnings - 20:
lab9
still works as Lab 8 (passes tests from Lab 8 autograder) - 10: all header files have header guards
- 10:
lab9.c
containsmain
and no other source code - 5 each:
county.c
defines functions incounty.h
,sort.c
defines functions insort.h
,utils.c
defines functions inutils.h
. - 10:
Makefile
encodes the dependencies of the program so that only code that needs to be recompiled is recompiled - 5:
county.h
contains the definition for aCounty
struct
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.