Due Wednesday, April 27th, 11:59pm

Goals for this Warmup

  • Practice programming with structs and enumerated types
  • Introduce linked structures with pointers.

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.

Set up

Remember to create a new directory in your repository for this lab.
$  cd CNET-cs152-spr-16
$  mkdir hw4
$ svn add hw4
$  cd hw4

Duet Programming Setup

Do not forget to copy your finished files from your duet repository into your personal repository.. Your duet repository is https://phoenixforge.cs.uchicago.edu/svn/cs152-spr-16-duet-X. with your own pair number in place of X. Remember to create a new directory in your repository for this lab.
$  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!

Problems:

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);

Phase 1: Problem Clarification, Test Design

Remember - for each file you create, "touch" it first, then add it to svn. Partner A:
1. Determine exact interfaces for functions. This has already been done for you.
2. Implement the "skeleton" files - main, .h, and .c files.
  • Create hw4.h and place all of the function declarations in the file, along with the required preprocess commands (e.g. #ifndef).
  • Create hw4.c and place a skeleton of each function in the file. It contains only the signature and, if it returns something, a single return statement that returns a value of the right type.
  • Create test_hw4.c. Put in the #includes you need, the main function, and everything necessary to make a single function call to each function.
  • Update your repository to get the Makefile from your partner.
  • Compile with:
    $ clang test_hw4.c hw4.c
    
  • commit your results
Partner B:
  • Make a Makefile for this project. Commit it to the repository.
  • Identify the attributes to be varied for test cases in problems 1 and 2.
  • Identify ranges of valid inputs for each attribute.
  • Suggest a set of test cases that are "normal" cases, "border" cases, and "error" cases.

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.

Phase 2: Implementation

Partner A: Implement problem 1.
Partner B:
Use svn update to receive the starting code from Partner A.
Implement the test cases to problem 1. Don't forget to use good function decomposition techniques (make a function that does the testing).

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.


Phase 3: Compilation and Testing

Make sure you have both updated your files. Then you can begin compiling and testing. Whoever wrote the tests for the last group edits the main file, and whoever write the functions edits the functions file.

Roadmap

When you are finished with this phase, make sure you commit your code! Now you're ready to repeat the process with other problems. For this assignment, all problems are slightly different, so there is no complex roadmap. Go through phases 1, 2, and 3 for each problem, reversing your roles each problem. The problems are designed with overlapping skills so that each student gets to practice most of the skills by the end.

Good luck!

Submit

At this point, you should have done the following:
  • Checked out your repository
  • Created a folder named hw4 in your repository and run svn add hw4
    $ svn add hw4
  • Created , added, and filled in four files: hw4.h, hw4.c, test_hw4.c and Makefile inside your hw4 directory.
  • If you participated in Duet Programming, make sure you svn update your duet repository, then copy over the files into your personal repository. The cp command copies files.
    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
  • Compiled your executable manually and with the Makefile
  • Executed your code to make sure it runs properly and inspected the results.
  • $ svn commit -m "hw4 warmup complete"
Now you're ready to move on to hw4!! Remember that the homework is completed individually.