COSC 071: Computer Science I

Project 2
Spring 2011

Due: Thu, Feb 24 @ 5 PM
6 points

Wow! Hoya Saxa Banking Corporation (HSBC) loved what you did for them for project one. Now they want you to design and implement a Payment class that will let them create Payment objects, rather than having payments as a disassociated collection of variables.

This new program perform the same tasks that the program for p1 did, but it will do so by creating Payment objects and calling the appropriate methods. There is still this odd aspect of their application is that customers always enter transactions in batches of three. HSBC needs a program that prompts for the fields of the three payments, writes this information to the console, and then writes the total of the payments to the console.

As you know from the previous project, a payment has or consists of a number, a date, a payee, and an amount. You can still assume that payees will not contain spaces. You can also assume that all entered values will be correct. We'll relax these assumptions in later projects.

The Payment class should consist of the following methods:

  1. default constructor
  2. explicit constructor
  3. set methods, one for each private data member
  4. get methods, one for each private data member
  5. a print method, that prints the for a transaction to the console (cout)
  6. an enter method, that prompts a user to input a transaction from the keyboard (cin)
  7. a write method, that writes a transaction to a file of a given name
  8. a read method, that reads a transaction from a file of a given name

The file format for storing payments in a file consists of four fields. The first is the number, the second is the date, the third is the payee, and the fourth is the amount. Note that now we are reading and writing information to and from files the order of this information is critically important. Each is separated by one space. As an example, the main function:

int main()
{
  Payment payment( "350", "02/04/2011", "Tombs", 17.95 );
  payment.write( "tombs.out" );
  return 0;
} // main
should produce the file named tombs.out with the contents:
350 02/04/2011 Tombs 17.95
The read method should take the specified filename, open an input file stream, and read a transaction in this format and store the values in the private data members.

As with p1, the main function should prompt the user to enter the information for each of the three payments. After the user enters the information for these payments, the program should print all of the information to the console. It should also print the total of the three payments. A transcript of a sample run appears below with the user's input typeset in bold:

seva% g++ p2.cc
seva% a.out
Enter information for Payment 1:
Number: 345
Date: 01/01/2011
Payee: Tombs
Amount: 34.56
Enter information for Payment 2:
Number: 346
Date: 01/02/2011
Payee: Wisemillers
Amount: 7.95
Enter information for Payment 3:
Number: 347
Date: 01/02/2011
Payee: Safeway
Amount: 45.67

Payment 1:
  Number: 345
  Date: 01/01/2011
  Payee: Tombs
  Amount: $34.56

Payment 2:
  Number: 346
  Date: 01/02/2011
  Payee: Wisemillers
  Amount: $7.95

Payment 3:
  Number: 347
  Date: 01/02/2011
  Payee: Safeway
  Amount: $45.67

Total: $88.18
seva%

As you know, a critical approach to developing software systems is decomposing a programming task into smaller, manageable pieces. The classes and methods required to solve a problem give us a natural way to decompose problems. Begin by designing the class definition. What are the private data members' names? What are their types?

From there, design the public interface. What methods are necessary? What are their names? What parameters do they have? What return types do they have?

Once you have designed the public interface, type the class definition. Start with the code in template.cc and add the class construct. Compile and run, correcting any syntax errors.

Add each of the method declarations. Compile and run, correcting any syntax errors.

Once you have a syntactically correct class definition, start implementing the class methods. Implement the default constructor. Declare a Payment object in the main function. Compile and run. Then implement a print method. It doesn't have to print an entire transaction. Start with printing a single data member. Compile and run. Modify the main function and call the print method for the payment object. Compile and run. Continue in this fashion until you have finished the implementation of the Payment class. Note that you will be able to transfer some of your code from Project 1 to the methods of the Payment class.

The approach of stepwise refinement and incremental development minimizes errors and helps manage the complexity of software development. If you start each step with a working program and you add a few lines of code, if you make a mistake, then it mostly likely involves the last few lines you typed. On the other hand, if you start by entering your 300-line program all at once and compiling, you will be overwhelmed by the number of compiler errors. Even seasoned programmers don't do this.

For this project, you do need to write comments. Documentation comments are discussed in Section 4.19 of the book, and we'll discuss them in class. Use a class comment with @author and @version tags. Document each method with a method comment with @param and @return tags, as appropriate.

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 above the Doc comment documenting your class with the appropriate modifications:
//
// COSC-071 Project 2
// Name: <your name>
// E-mail: <e-mail address>
// Instructor: Maloof
// Spring 2011
//
// 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.
//

When you are ready to submit your program for grading, use the submit program, just like you did for HW2. Both submit.jar and the file containing your program should be in the same directory. You can confirm this by listing the files in your home directory:

seva% ls
p2.cc    submit.jar
You may see other files from previous assignments in your home directory, but p1.cc and submit.jar should be among them.

This assignment's label is p2. Assuming the file you want to submit is p2.cc, then to submit you enter the command

seva% java -jar submit.jar -a p2 -f p2.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.