Assignment 1, due Tuesday, January 31 at 10pm.

You must submit your program electronically via gsubmit on csa.

Late programs will be accepted, but only if you use one of your two free 48-hour extensions (strongly discouraged at this point in the course).

The code you submit must conform with the programming guidelines.

Please be sure that you have subscribed to the CS 112 mailing list (by typing "csmail -a cs112b1" at the csa.bu.edu prompt) to receive updates, corrections and clarifications to this and other assignments.


Programming Assignment

Write and submit a program contained in two files called payroll.cpp and test_payroll.cpp

In the file called payroll.cpp, implement the classes Employee and Payroll (defined in the provided header file, payroll.h). An Employee is a class with just three public data members.

class Employee
{
public:
    string name;
    int ID;
    double salary;
};

You can implement constructor, read and print functions for Employee in payroll.cpp if you wish.

A Payroll is defined as follows.

class Payroll
{
public:
    Payroll();
    unsigned int size();
    void print(ostream &os) const;
    void add(const Employee& newbie);
    void remove(int i);
    int position(string &target_name) const;
    void operator =(const Payroll& source);
    void operator +=(const Payroll& source);
private:
    Employee *people;
    unsigned int maximum_size;
    unsigned int current_size;
    void double_maximum_size();
};

The Payroll class consists of a set of Employees, pointed to by the people variable. The constructor will allocate an array of some positive size to people. This size is remembered in the private member variable maximum_size. Later, a private member function can double the size of the payroll as needed. (We will not worry about decreasing the size of the payroll.) Only the initial part of the array will store actual Employees: you should store the number of actual Employees in the private variable current_size.

You get to implement the following member functions:

  1. Payroll() -- default constructor.  Allocate a payroll of some positive size (you decide how large) to the people variable, set the maximum_size appropriately, and the current_size to zero.
  2. unsigned int size(); -- return current_size.
  3. void print(ostream &os) const; -- print the Employees currently on the Payroll, one per line.
  4. void add(const Employee& newbie); -- add a new Employee to the payroll, making more room on the payroll if necessary.
  5. void remove(int i); -- remove Employee in people[i], shifting other Employees over to fill its place (or just replacing it with the last Employee: remove is not guaranteed to keep order). Throw an exception if there is no entry at position i.
  6. int position(string &target_name) const; -- return the first i such that people[i].name == target_name. Throw an exception if no such i is found.
  7. void operator =(const Payroll& source); -- assign one Payroll to another (this should look like a copy constructor, plus checking for self-assignment).
  8. void operator +=(const Payroll& source); -- combine two Payrolls into one. Do not worry about repeated items, but if the two Payrolls are the same, then, like in self-assignment, don't do anything.
You may use other private members for Payroll to implement the required public members if you wish, you may also need appropriate constructors and destructors.

In the file called test_payroll.cpp write a program that tests all public member functions of your Payroll class.

We recommend that you use our Makefile to compile your code.


What to Submit

Create an 01 directory using gsubmit.

Be sure to remove all debugging statements before submission.

Then gsubmit only the following four files into the 01 directory: payroll.h, payroll.cpp, test_payroll.cpp, Makefile.

Grading Criteria

Refer to the grading criteria file: p1.criteria

You are responsible for thoroughly testing your program to make sure that it works. Your code must run correctly on csa. In grading your program, we will verify that your test cases adequately test your routines, then test your program on some payroll test files of our own.


Academic Honesty and Collaboration

Cooperation is acceptable in understanding programming concepts and system features. But the actual solution of the assignments including all programming must be your individual work. For example, copying without attribution any part of someone else's program is plagiarism, even if you have modified the code. The University takes acts of cheating and plagiarism very seriously; first time violators are routinely suspended for a semester.