Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program Specifications You're asked to write a program to analyze (or report) a customer's credit card's monthly purchase transactions. The program is to read all

Program Specifications

You're asked to write a program to analyze (or report) a customer's credit card's monthly purchase transactions. The program is to read all customer's transactions from a text file and store them in an array of pointers to transactions. The program will then generate two reports: first is to list all transactions and second is to produce a summary report of reward points.

The assignment basically illustrates the following concepts:

Inheritance and Polymorphism (virtual functions and virtual destructors)

Abstract classes (pure virtual functions)

dynamic_cast for polymorphic classes

Operator overloading

Class Design

You need to define the following classes described below. Feel free to come up with more classes if needed.

class Customer (minimum implementation specified below)

A Customer possesses a credit card and may initiate multiple transactions. Transactions are of different kinds: Banking transaction, Department Store transaction, Grocery transaction. They may get reward points for certain transactions.

Private member data

Customer name

Credit card number (a string)

Transaction balance

Reward points total (default to 1000 points)

Array of pointers to Transaction objects (size 16)

Public constructors: default and non-default constructors similar to previous labs (initialize all pointers in the array of pointers to NULL)

Public destructor: free memory for the array of pointers

Public member functions:

ReadTransactions: read a text file containing Transactions information, properly instantiate the corresponding derived objects, and then assign them to the base class pointer array elements. Must use a switch statement based on transaction type ('D', 'B', or 'G')

ReportAllTransactions: invoke the listing method for each Transaction in the Transaction array. This should list all transactions' information. Also prepare a summary of transactions per category. Hint: to list all transactions there is no need to perform static_cast or dynamic_cast when calling Display function because polymorphism will take care of invoking the correct version. However in the Transaction Summary part of the same report you will need to perform dynamic_cast on the Transaction pointers to one of the derived pointers and figure out the required information to display for each transaction.

ReportRewardSummary: invoke the earnPoints to compute total points for different transaction category and then produce the report. Again dynamic_cast will be needed here.

class Transaction: this is an abstract class

Protected data members: transaction date (in the form mm/dd/yy), transaction id, transaction amount

Public Constructors: default and non-default constructor

Destructor: implement virtual destructor that output ("Transaction destroyed...").

Overload equality operator (==). Two transactions are identical if they have the same transaction date and transaction amount

Public member functions:

Display: pure virtual function

EarnPoints: pure virtual function

accessor/mutator

Derived classes (from Transaction class)

DepartmentStoreTransaction: department name (Macys, Ross, Marshall, ...), return policy (30 days, 60 days, or 90 days)

BankingTransaction: type (ATM withdraw or CASH withdraw), fee charge

GroceryTransaction: store name (Lucky, Walmart, Safeway, ..),

Keep those derived classes simple.

At minimum they should have the following:

private member data indicated above

pubic default and non-default constructors (must explicitly call the base class constructor)

Note: The non-default constructors of those derived classes must take transaction date, transaction id, transaction amount (required by the base class' non-default constructor) in addition to parameters required by their own member data

Destructor: implement virtual destructor that output ("Transaction destroyed..." You must explicitly prefix the destructor with keyword virtual

accessor/mutator

Provide implementation for the Display pure virtual functions in the Transaction base class to display a transaction in the following format:

Date Transaction type Specific info about transaction Amount

Example:

03/12/16 Banking ATM withdraw $300

Provide implementation for the pure virtual function EarnPoints as follows

Department Store: 1.5 points/$1

Grocery: 2.5 points/ $1

Banking: no point (always return 0)

Text file format

For simplicity you may create a text file containing exactly 16 transactions.

~~~~<Transaction-specific data>

D~04/23/16~1111~25.67~Macys~60

B~03/12/16~2222~300.0~ATM~6.00

G~04/20/16~4444~57.95~Lucky

B~05/01/16~5555~100.0~CASH~4.00

G~04/23/16~6666~17.39~Safeway

D~04/01/16~7777~211.67~Sears~90

............................................................

Transaction type:

D: Department Store transaction

B: Banking transaction

G: Grocery transaction

Report format

ReportAllTransactions

Transactions Listings

04/23/16 Department Store Macys, return in 60 days $ 25.67

03/12/16 Banking ATM withdraw $300.00

................................................................................................................................

Total fee charge: $ 14

Total balance: $ 905.95 (= total transaction amount + total fee charge)

Transaction Summary

Transaction type Transaction count Total Purchase

Department Store 4 125.89

Banking 2 400.00

Grocery 3 356.06

-----------------------------------------------------------------------------------

$891.95

ReportRewardSummary

Rewards Summary for

Previous points balance 1000

+ Department store purchases: 2710

+ Grocery Purchases: 750

----------------------------------------------------------------------------------

= Total points available for redemption 4460

Main program implementation

The main function should do the following:

Dynamically instantiate a Customer object using non-default constructor Invoke ReadTransactions Invoke ReportAllTransactions Invoke ReportRewardSummary Free memory for the Customer object

// Your code here to show the implemented equality operator (==) is working.

Testing

Run the program to verify the reports are correct

Verify there must be 32 output for the destructor calls (2 for each transaction: one for the base class and the other for the derived class)

How to submit your assignment and late policy

Same as programming assignment #1.

Extra credit (5 points)

Produce a third report to check for duplicate transactions. Note that the overloaded equality operator (==) only tells if two transactions are "the same" based on date and amount. Duplicated transactions must be of the same transaction additionally. For example BankingTransaction on 3/20/2016 in the amount of $300 and GroceryTransaction on 3/20/2016 in the amount of $300 are NOT duplicated transactions. The report must identify all possible duplicated transactions. For simplicity you may assume there can be at most two duplicated transactions for each transaction type. The report should list those duplicated transactions along with their transaction id.

If no duplicated transaction is found:

DUPLICATE TRANSACTION REPORT

No duplicate transaction found.

If some duplicated transaction is found:

DUPLICATE TRANSACTION REPORT

Transaction type Date Amount Transaction ID

Banking 3/20/2016 $200 1234

Banking 3/20/2016 $200 1235

Dept Store 4/20/2016 $100 345

Dept Store 4/20/2016 $100 621

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What are the two main objectives of using digital signatures?

Answered: 1 week ago

Question

600 lb 20 0.5 ft 30 30 5 ft

Answered: 1 week ago