COSC 071: Computer Science I

Project 4
Spring 2007

Due Wed, Apr 11 @ 5 PM
10 points

Implement the Transaction class. A transaction has a date, time, code, and minutes. Dates will be in the format "mm/dd/yy". Times will be in the format "hh:mm". Valid codes are the strings "I" for in-network phone calls, "O" for out-of-network phone calls, and "S" for SMS messages. If a transaction has a code of either "I" or "O", then it will have a positive number of minutes.

In addition to constructors, implement accessor and mutator methods. Mutator methods should return true if it set the value successfully and should return false otherwise. (You can assume that dates and times will always be formatted properly.)

One design issue we should discuss in class is what mutator methods to implement and how they should work so they ensure data integrity. For example, if the code is "S", then minutes must be zero. If a programmer using the class changes a transactions code from "S" to, say, "I", then minutes cannot be zero. The design and implementation must prevent a transaction object from being in such an invalid state.

Another important design issue is that the methods of the Transaction class must not stop program execution. The programmer using the Transaction class must be able to make this decision. We can accomplish this by having mutator methods return false if there is an invalid value.

Overload the stream insertion and extraction operators. These friend functions should read and write a transaction in the following format:

3/1/07 12:01 S
3/1/07 13:35 S
3/5/07 8:45  O 49
3/5/07 21:57 S
3/10/07 11:15 I 26
3/11/07 13:20 I 45
3/12/07 16:34 S
We will use these overloaded operators for file input/output, so you should implement a print method that outputs the information for a transaction in a format suitable for a bill.

To demonstrate your implementation of the Transaction class, implement test cases in main. The final task main should do is read transactions from a file "p4.dta" and print the transactions to the console. For example:

fin >> transaction;
while ( fin ) {
  cout << transaction << endl;
  fin >> transaction;
} // while
Develop your own data for testing. We'll use our own for grading.

Hints for development. Keep in mind that this project is about transactions, not bills or plans. Implement your project method by method, testing each thoroughly in main. One difficulty is that, since the data members of transaction objects are private, you will not be able to inspect directly their values. Begin by defining those private data members and implementing a simple print method. Start with the following main function:

int main()
{
  Transaction t;
  t.print();
  return 0;
} // main
It will print default values for date, time, code, and minutes. Next, implement one of the mutator methods, such as setCode. Then test it in main:
int main()
{
  Transaction t;
  if ( t.setCode( "S" ) )
    cout << "valid" << endl;
  else
    cout << "invalid" << endl;
  t.print();
  return 0;
} // main
Continue in this fashion until you have implemented and tested all of the methods of the Transaction class. Finally, overload the stream insertion and extraction operators, testing them on console and file streams.

Instructions for Submission

At the top of the file containing your source code (i.e., the file containing the C++ instructions), place the following header comment, with the appropriate modifications:
/**
 * Project 4
 * Name: <your name>
 * E-mail: <e-mail address>
 * COSC 071, Spring 2007
 *
 * In accordance with the class policies and Georgetown's Honor Code,
 * I certify that, with the exceptions of the lecture notes and those
 * items noted below, I have neither given nor received any assistance
 * on this project.
 *
 * Description: <Describe your program>
 */

When you are ready to submit your program for grading, use the submit program. Both submit.jar and the file containing your program should be in the same directory. This assignment's label is p4, so the form of the submit command is

seva% java -jar submit.jar -a p4 -f <file>
Assuming the file you want to submit is p4.cc, then to submit you enter the command
seva% java -jar submit.jar -a p4 -f p4.cc
Make sure you submit the file containing your program's source, not its executable code; that is, do not submit a.out.

Once you've submitted your project, it is a good idea to keep a copy on seva, which preserves the modification date and time and ensures that you will have a backup copy of your project. If we lose your project or submit breaks, then we will need to look at the modification date and time of your project to ensure that you submitted it before it was due.

The TAs who will be grading your projects this semester are listed on the main page. You must submit your project before 5 PM on the due date.

Plan B

The submit program is pretty reliable, but it is software. If it is three minutes before the deadline and the submit program breaks, here's Plan B. You are to mail your program to our grading account. The syntax for this command is
seva% mail -s "<netid>.cc" cosc071@cush < <filename>
Assume that I want to submit my file named p4.cc. Then I would type
seva% mail -s "maloofm.cc" cosc071@cush < p4.cc
This command sends mail with the subject "maloofm.cc" to our grading account (cosc071@cush). The body of the e-mail is the contents of the file p4.cc. Use Plan B only if you have made sure that submit is truly broken. Finally, don't send normal mail to this account because no one will be checking it regularly.