CS0004: Programming Project 5

Assigned:April 4, 2007
Final Project Due:
 April 18, 2007


In this assignment you are going to read data from a CSV file and store that data in an array using a user defined structure. The user can then select how they want the data to be sorted, by which column and in what order (ascending or descending). Once the user has selected their sorting preferences they can save their newly sorted data to a file. This will involve you doing three parts:

  • Reading a CSV file into an array of structures
  • Sorting the array of structures
  • Writing data from an array of structures to a CSV file

The CSV file will be formated as the following:


Joey, Person, Pittsburgh, PA, 24, 12500.23

Jackie, Smith, Denver, CO, 35, 50323.52

You will need to create a structure for storing this data and then read the data into this structure and then store it in the array. You will need to use the split function to get each piece of data. You should use the trim function to make sure that all the extra spaces are removed.

The form will allow the user to select his sorting preferences. First they will select what column they want to sort by (First name, Last name, city, etc.). The user can also select a sort order (ie ascending or descending). You will use radio buttons to allow the user to select these prefrences.

Once the user has selected their sorting preference they can write this newly sorted list to a file. You should use the OpenFileDialog to get the file to read and then use SaveFileDialog to get the file to write the data. SaveFileDialog works just like the OpenFileDialog.

You must use the bubble sort algorithm to sort the data. This code has been provided for you in the class notes. You must modify this code to enable to sorting of an array of structures.

To enable sorting of structures you need to write a function called ComeBefore which will look at the various radio buttons and decide how to compare the two person structures. This function will then determine if person 1 comes before person 2. In the bubble sort algorithm there are lines that says if a(i-1) < a(i) then swap the two entires. In this project you will replace this comparison with a call to the ComeBefore function. ComeBefore will take two Person structures (in our case this will be Person a(i-1) and Person a(i)). It will then return true if the first Person paramater comes before the second Person parameter given the users selected sort column and order.

Example Files

Provided are two example data files (you can create your own if you like). They can be downloaded here:

The Interface


When the user hits the load button it should let the user select a file to read data from. The user should then select how they want the data sorted, by what column and what order. Then when the user hits the save button you should show the SaveFileDialog and allow the user to select where to save the file.


The grading sheet for this assignment is posted. The entire project is worth 100 points. Various items will be graded including functionality, design, proper use of form elements, code style, documentation, etc. Please note that documentation is graded, you must document your code!


Again, there are two parts to turn in for the final project. First, you need to bring a printout of the code window to class on April 18. Second, create a zipped folder containing the entire project. Name this file Lastname_Firstname_Assignmentnumber.zip. Example: Mills_Bryan_5.zip

Don't use spaces in your filename thats just bad, not cool, and always wrong.

You then need to upload this zip file to the following location, http://www.cs.pitt.edu/~bmills/upload/ . This web page will allow you to upload your zip file only once. If you need to upload your file again add a revision number to the end of the file (ie Mills_Bryan_5_2.zip, Mills_Bryan_5_3.zip). I will grade the file with highest revision number.

Let me know if you have any problems uploading files by emailing me. I will not accept submissions turned in late some don't even try it, I have millions of little monkeys in the computer watching for late submissions.

Extra Credit

I will offer a 10 point extra credit opportunity. If you have an idea for extra credit, email me or stop by during office hours and we can discuss it. Extra credit is added based upon the level and scope of the extra credit attempted. NO EXTRA CREDIT WILL BE AWARDED FOR ADDITIONS NOT DISCUSSED AND APPROVED!