UQ Students should read the Disclaimer & Warning
Note: This page dates from 2005, and is kept for historical purposes.
COMP2301 – Assignment Four – File I/O in C++
This assignment is a pass/fail assignment. I achieved a pass.
The goal of this assignment is to gain experience using C++ for object-oriented programming.
In this assignment, you will become familiar with:
- C++ I/O methods: operator << and operator >>
- Use of classes in C++
- Some aspects of the standard template library (STL)
Specification
Develop a command-line program to read and manipulate a file of internet banking transactions. Each individual transaction starts on a new line and contains six comma separated transaction details.
- Timestamp: 10-digit: [yymmddhhnnss], [yy] = year, [mm] = month, [dd] = day, [hh] = hour (from [00] to [23]), [nn] = minutes, [ss] = seconds.
- Customer’s last name:
- Customer reference number: 10-digit number.
- Account type : “Check” for (Checking account), “Sav” for (Savings account) or “Cred” for (Credit card account).
- Transaction type : “Dep” for (Deposit) or “With” for (Withdrawal).
- Transaction amount: [dollars.cc], where [dolars] = integer dollars and [cc] = integer cents.
Example input file containing four transaction: ( Timestamp,
Customer’s last name, customer reference number, Account type , Transaction
type , Transaction amount )
Functions required for the command line interface
- The program sorts the transactions when run from the command line in three
ways:
transactionlist [ [/t] | [/n] | [/c] ] INPUTFILE [OUTPUTFILE]
/t [DEFAULT] : sort transactions in Numeric order by Time Stamp
/n : sort transactions in Alphabetic order by Last Name
/c : sort transactions in Numeric order by Time Stamp of combined deposit balance - An error is generated if more than one command line switch is entered.
- If no command line switch is entered the default operation executes and the program writes the sorted transactions to standard output (cout).
- If an [OUTPUTFILE] is specified the program writes the sorted transactions to the named file. Existing file content should be overwritten.
- If [/c] the combined balance switch is entered all transactions with identical
customer reference numbers AND identical account types must be combined into
one transaction.
- Time stamp of the combined transaction = Time stamp of the last transaction that corresponds to the appropriate customer reference number and account type
- Transaction type of the combined transaction is “CombDep” (CombinedDeposit)
- Transaction amount is the [sum of all appropriate deposits] - [sum of all appropriate withdrawals]
- You are to implement the operator <<, operator >>, operator
/=, operator + and comparison operators.
- operator <<, operator >> are to be used to read the file and write to cout.
- operator /= is used to test if two transactions have identical customer reference numbers AND account types.
- operator + combines two transactions.
General
- You will need to write a class called “transaction” in this assignment.
- You must NOTuse stdio.h (i.e. scanf, printf, etc.).
- You may use strcpy, sscanf, and other string manipulation routines included in string.h.
- You MUST use the Standard Template Library’s list (or vector).
- Running your program with no command line parameters must generate a usage statement.
- All transactions with identical customer reference numbers have identical last names
- Transaction amount for a combined balance may be negative.
- Reasonable error checking is required, the program must handle the following
events gracefully
- the specified input file does not exist.
- an incorrect number of command line parameters are given.
- the file contains invalid records or an invalid record structure.
- Transaction.h header file may be obtained by downloading the Zip file for assignment 4.
Compiled
(WIN32) binary (188 KB)
transaction.h
transaction.cpp
transaction.h
transaction.cpp
Code © Copyright 2004 Ned Martin
19-May-2004