For this lab, you are welcome to get technical help from another student on how to use or install any of the tools involved. You may also get syntax help on C. You may not, however, get help on the algorithmic portion of the exercise outside of office hours or piazza questions to TAs or instructors.
$ cd CNET-cs152-spr-16 $ mkdir hw4 $ svn add hw4 $ cd hw4
$ cd cs152-spr-16-duet-X $ svn update $ mkdir hw4 $ svn add hw4 $ cd hw4
You will be using the full power of repositories - repositories have two purposes: 1) backup your work in case you accidentally delete something 2) allow two people to work on different files of the same project at the same time. We will use this for both purposes.
At any given time, you should coordinate with your duet partner as to who is editing which file. Whenever your file is in a stable state (you completed something and, depending on the phases, got the compile errors out of it), you commit your file. Whenever you want to get the latest set of stable changes from your partner, you svn update.
Good luck and have fun learning together!During this warmup, you are going to implement several functions that exercise strings and pointers. If you are using Duet Programming, do not forget to trade off after each function. The functions are ordered to provide specific practice to each student.
You will be adding to these functions in the homework, so do not create warmup files - instead, place all of your code in hw4.h and hw4.c.
All of the linked list operations will hold gymnasts rather than integers. The data declarations necessary for this assignment are:
enum Country { USA=0, MEXICO, BRAZIL, RUSSIA, CHINA, SAFRICA, CHILE, ROMANIA }; enum Event { UNEVEN=0, VAULT, BEAM, FLOOR }; #define NUM_EVENTS 4 typedef struct { char *lastname; char *firstname; enum Country country; float scores[NUM_EVENTS]; } gymnast_info; // for the linked list, we will use the following struct typedef struct _llist llist; struct _llist{ gymnast_info *g; llist *next; }; extern char *country_strings[]; void print_gymnast(gymnast_info *g, FILE *fp); void print_list(llist *head, FILE *fp);In addition, I am providing a function to print out a gymnast so that everyone has consistent output. Place the code below into your hw4.c file.
char *country_strings[] = { "USA", "Canada", "Brazil", "Russia", "China", "South Africa", "Chile", "Romania"}; void print_gymnast(gymnast_info *g, FILE *fp) { fprintf(fp,"%s %s ",g->firstname, g->lastname); fprintf(fp,"%s:",country_strings[g->country]); int i; for(i=0;i<NUM_EVENTS;i++) fprintf(fp,"%f, ",g->scores[i]); fprintf(fp,"\n"); } void print_list(llist *head, FILE *fp) { llist *tmp; for(tmp = head; tmp != NULL; tmp = tmp->next) print_gymnast(tmp->g,fp); }To call print_gymnast or print_list to print to the screen, use stdout as the second argument. In addition, you may print to a file using the code from the print_ppm function from last week. Problem 1: cons
Write a function that adds a gymnast to the list. ginfo will become the first element of the modified list. It returns a pointer to the first element in the modified list.
llist* cons(gymnast_info *ginfo, llist *list);Problem 2: insert_country(gymnast_info *ginfo, llist *list)
Write a function that inserts a gymnast immediately after the first gymnast from the same country. If this is the first gymnast from that country, the new gymnast is inserted at the end of the list. It returns a pointer to the beginning of the modified list.
llist* insert_country(gymnast_info *ginfo, llist *list);Problem 3: max_event
Write a function that returns the gymanist with the highest score in a single event. It returns a pointer to the gymnast_info, not the node. If the event number is too high, return NULL.
gymnast_info* max_event(llist *list, unsigned int event);
Problem 4: max_country(llist *list)
Write a function that returns the country with a sum of the highest score. It returns the Country.
enum Country max_country(llist *list);
$ clang test_hw4.c hw4.c
Now get together and share your results. Work together to get the skeleton to compile and run properly. Go through the test case plan. Then commit the files.
The next time you do Phase 1, Partner A will do test case design for problem 3, and Partner B will do test case design for problem 4.
When you have completed your part of the code, update and commit.
Discussion part 1: Look at the input ranges from the black box tests. Is there separate code to handle each case? If not, are the different ranges equivalent? Also, verify that the boundaries in the input ranges match the boundaries present in the code.
Discussion part 2: Looking at student A's code, jointly develop a set of white box tests that exercise all paths in the code. If you developed more tests than the black box tests, discuss whether that code is necessary, or whether the initial tests were insufficient.
$ svn add hw4
mkdir CNET-cs152-spr-16/hw4 cp cs152-spr-16-duet-0x/hw4/* CNET-cs152-spr-16/hw4/* cd CNET-cs152-spr-16 svn add hw4
$ svn add hw4.h hw4.c test_hw4.c Makefile
$ svn commit -m "hw4 warmup complete"