CS202 Computer Science II
FAQ Newsboard  Telnet Email TA Lectures Assignments Man pages Help

Assignment 5
Due Nov 2 before class


Last modified 10/20/98 @ 12:00 p.m.

This assignment gets you familiar with dynamic memory, pointers, and operator overloading. You also get the pleasure of sorting again.

As5 is very similar to assignment three. The difference is that you need to implement a dynamically allocated StudentVector class instead of using an array of Student structs. Specifically,

You are to design a StudentVector class, that encapsulates a dynamic array of Student structs. You will need to specify and implement

  1. Constructors
  2. A destructor
  3. A copy constructor
  4. Overloaded assignment
  5. Overloaded subscript operator []. Yes it is an operator.
  6. Overloaded << and >> (I/O) operators
  7. Friends for sorting and searching
  8. Other members that you may need
The subscript ([]), input (>>), and output (<<) operators will be overloaded. You will use a Student struct that is very similar to the one you used in assignment three. Look at my bubblesort.cpp (which you cannot modify) for more information on constraints for this assignment.

as5.cpp therefore looks even simpler than as3.cpp. You must take and use my bubblesort.cpp and command.cpp. I have also taken the liberty of shortening ProcessCommandLine to PCL in my version of command.cpp.

You can use the test cases from assignment three to test your program with my input file.

Constraints

  1. You should put your struct declaration(s) in a file called type.h and your program in as5.cpp.

  2. You may assume that if there is one command line argument it must be the number of records to sort and you sort by gpa. If there are two command line arguments then the first determines the number of records to sort and the second defines the sort field.

  3. You may use the string library function strcmp() to compare two strings. Follow the link to read the manual page and learn how to use strcmp().

  4. NO global variables.

  5. You may NOT assume a maximum size for any arrays (except for the name field for a student).

  6. You must define and use a swap() function that passes structures by reference to swap items in your array of structs.

This is the most difficult assignment you have had so far. Start on the assignment now and ask questions.