Question

In: Computer Science

Write a program: For this assignment, you will need to write three source code files as...

Write a program:

For this assignment, you will need to write three source code files as well as two header files. Each of these files is relatively short, but many inexperienced programmers are overwhelmed by the idea of writing a program as multiple files. "Where do I start?!!" is a common refrain. This assignment sheet attempts to walk you through the steps of writing a multi-file program.

The steps outlined below should not be thought of as a purely linear process, but rather an iterative one - For example, work a little on Step 1, then a little on Step 2, then test what you've written (Step 3).

Step 1: Write the CreditAccount class declaration

The CreditAccount class represents information about a credit card account. The code for the CreditAccount class will be placed in two separate files, which is the norm for non-template C++ classes.

The header file for a class contains the class declaration, including declarations of any data members and prototypes for the methods of the class. The name of the header file should be of the form ClassName.h (for example, CreditAccount.h for the header file of theCreditAccount class).

A skeleton for the CreditAccount.h file is given below. As shown, a header file should begin and end with header guards to prevent it from accidentally being #included more than once in the same source code file (which would produce duplicate symbol definition errors). The symbol name used in the header guards can be any valid C++ name that is not already in use in your program or the C/C++ libraries. Using a name of the format CLASSNAME_H (like CREDIT_ACCOUNT_H in the code below) is recommended to avoid naming conflicts.

   #ifndef CREDIT_ACCOUNT_H
   #define CREDIT_ACCOUNT_H

   //*****************************************************************
   // FILE:      CreditAccount.h
   // AUTHOR:    your name
   // LOGON ID:  your z-ID
   // DUE DATE:  due date of assignment
   // 
   // PURPOSE:   Contains the declaration for the CreditAccount class.
   //*****************************************************************

   class CreditAccount
      {
      // Data members and method prototypes for the CreditAccount class go here
               .
               .
               .
      };

   #endif

Data Members

The CreditAccount class should have the following private data members:

an account number (a char array with room for 19 characters PLUS the null character, i.e. 20 elements total)

a customer name (a char array with room for 20 characters PLUS the null character)

a credit limit (a double variable)

a current account balance (a double variable)

Note: Make that sure you code your data members in THE EXACT ORDER LISTED ABOVE and with THE EXACT SAME DATA TYPES. If you use float instead of double or only make the name array 20 characters long instead of 21, your final program will not work correctly!

C++11 Initialization Option for Data Members

C++11 adds the ability to initialize the non-static data members of a class at the time you declare them using a "brace-or-equal" syntax. This is very convenient, and can eliminate most or all of the code from your default constructor. Here are a few examples of the kind of initializations you can do in a class declaration:

class Foo
   {
   // Data members
   private:

      int x = 0;                                  // Initialize x to 0
      double y = 9.9;                             // Initialize y to 9.9
      char text[21]{};                            // Initialize text to an
                                                  // empty string
      char name[11]{'J', 'o', 'h', 'n', '\0'};    // Initialize name to "John"
      string s{"Hello"};                          // Initialize s to "Hello"

      etc.
   };

Feel free to use this option if you want to.

Method Prototypes

The CreditAccount class declaration should (eventually) contain public prototypes for all of the methods in the CreditAccount.cpp source code file described in Step 2 below.

Step 2: Write the CreditAccount class implementation

The source code file for a class contains the method definitions for the class. The name of the source code file should be of the form ClassName.cpp or ClassName.cc (for example, CreditAccount.cpp for the source code file of the CreditAccount class).

The CreditAccount class implementation should (eventually) contain definitions for all of the methods described below. Make sure to #include "CreditAccount.h" at the top of this file.

CreditAccount default constructor - This "default" constructor for the CreditAccount class takes no parameters. Like all C++ constructors, it does not have a return data type.

This method should set the account number and customer name data members to "null strings". This can be done by copying a null string literal ("") into the character array using strcpy() or by setting the first element of the array to a null character ('\0'). The credit limit and account balance data members should be set to 0.

(If you're working in C++11 and you initialized the data members at declaration as described above under C++11 Initialization Option for Data Members, this method's body can be empty. You still need to code the method though, even though it won't actually do anything.)

Alternate CreditAccount constructor - Write another constructor for the CreditAccount class that takes four parameters: 1) a character array that contains a new account number, 2) a character array that contains a new customer name, 3) a double variable that contains a new credit limit, and 4) a double variable that contains a new balance. DO NOT GIVE THESE PARAMETERS THE SAME NAMES AS YOUR DATA MEMBERS.. Like all C++ constructors, this constructor does not have a return data type.

Use strcpy() to copy the new account number parameter into the account number data member and the new customer name parameter into the customer name data member. The new credit limit and new account balance parameters can be assigned to the corresponding data members.

getAccountNumber() - This accessor method takes no parameters. It should return the account number data member. In C++, the usual return data type specified when you are returning the name of a character array is char* or "pointer to a character" (since returning an array's name will convert the name into a pointer to the first element of the array, which in this case is data type char.

getName() - This accessor method takes no parameters. It should return the customer name data member.

getLimit() - This accessor method takes no parameters. It will have a return data type of double. It should return the credit limit data member.

getBalance() - This accessor method takes no parameters. It will have a return data type of double. It should return the account balance data member.

processPayment() - This method takes one parameter, a double payment amount. It returns nothing. The payment amount should be subtracted from the current account balance data member. (Note that it is possible to have a negative balance on an account as a result of overpayment.)

processCharge() - This method takes one parameter, a double charge amount. It returns a Boolean value. If the charge amount plus the current account balance is greater than the credit limit, the method should return false without altering the balance (because this charge has been declined). Otherwise, the charge amount should be added to the account balance and the method should return true.

print() - This method takes no parameters and returns nothing. The method should print the values of the data members for the account in a format similar to the following:

Account Number: 1938-2348-3843-9683
Name: John Smith
Credit Limit: $5000.00
Current Balance: $127.65 CR

If the balance is negative, it should be printed as a positive number but followed by the letters "CR" (for credit). For example, the sample output shown above is for an account with a balance of -127.65.

Step 3: Test and debug the CreditAccount class

As you write your declaration and implementation of the CreditAccount class, you should begin testing the code you've written. Create a basic main program called assign2.cpp that tests your class. This is not the final version of assign2.cpp that you will eventually submit. In fact, you'll end up deleting most (or all) of it by the time you're done with the assignment. An example test program is given below.

You do not have to have written all of the methods for the CreditAccount class before you begin testing it. Simply comment out the parts of your test program that call methods you haven't written yet. Write one method definition, add its prototype to the class declaration, uncomment the corresponding test code in your test program, and then compile and link your program. If you get syntax errors, fix them before you attempt to write additional code. A larger amount of code that does not compile is not useful - it just makes debugging harder! The goal here is to constantly maintain a working program.

#include <iostream>
#include "CreditAccount.h"

using std::cout;
using std::endl;

int main()
   {
   char code1[20] = "1111-1111-1111-1111";
   char name1[21] = "Jermaine Arnold";
   char code2[20] = "2222-2222-2222-2222";
   char name2[21] = "Vanessa Long";

   // Test default constructor
   CreditAccount account1;

   // Test alternate constructor
   CreditAccount account2(code1, name1, 1000.00, 520.25);

   // Account with negative balance
   CreditAccount account3(code2, name2, 1500.00, -62.95);

   // Test print() method and whether constructors
   // properly initialized objects
   cout << "Printing account1\n\n";
   account1.print();
   cout << endl;

   cout << "Printing account2\n\n";
   account2.print();
   cout << endl;

   cout << "Printing account3\n\n";
   account3.print();
   cout << endl;

   // Test accessor methods
   cout << "Testing accessor methods for account2\n\n";

   cout << account2.getAccountNumber() << endl;
   cout << account2.getName() << endl;
   cout << account2.getLimit() << endl;
   cout << account2.getBalance() << endl << endl;

   // Test the processCharge() method with a successful charge
   bool chargeAccepted = account2.processCharge(400.00);
   if (chargeAccepted)
      cout << "Charge of $400.00 accepted, new balance on account2 is $" << account2.getBalance() << endl;
   else
      cout << "Charge of $400.00 on account2 declined\n";
      
   cout << endl;
   
   // Test the processCharge() method with a failed charge
   chargeAccepted = account2.processCharge(620.00);
   if (chargeAccepted)
      cout << "Charge of $620.00 accepted, new balance on account2 is $" << account2.getBalance() << endl;
   else
      cout << "Charge of $620.00 on account2 declined\n";
      
   cout << endl;

   // Test the processPayment() method
   cout << "Payment of $500.00 on account2\n\n";
   account2.processPayment(500.00);   
   account2.print();

   cout << endl;
      
   // Test the processPayment() method by overpaying - should now have a 
   // credit on the account
   cout << "Payment of $750.00 on account2\n\n";
   account2.processPayment(750.00);
   account2.print();

   return 0;
   }

Once your CreditAccount class has been thoroughly tested and debugged, it's time to write the second class for this assignment.

Step 4: Write the AccountDB class declaration

The AccountDB class represents a database of CreditAccount objects. Like the CreditAccount class, the code for this class will be placed in two separate files.

Place the class declaration in a header file called AccountDB.h. Like the file CreditAccount.h you wrote in Step 1, this file should begin and end with header guards to prevent it from accidentally being #included more than once in the same source code file.

After the header guard at the top of the file but before the class definition, make sure to #include "CreditAccount.h".

Data Members

The AccountDB class should have the following two private data members:

An array of 20 CreditAccount objects

An integer that specifies the number of CreditAccount objects actually stored in the array

Note: Once again, make sure you code your data members in THE EXACT ORDER LISTED ABOVE and with THE EXACT SAME DATA TYPES.

Method Prototypes

The AccountDB class declaration should (eventually) contain public prototypes for all of the methods in the AccountDB.cpp source code file described in Step 5 below.

Step 5: Write the AccountDB class implementation

The AccountDB class implementation should (eventually) contain definitions for all of the methods described below. Make sure to #include "AccountDB.h" at the top of this file.

AccountDB default constructor - This "default" constructor for the AccountDB class takes no parameters. Like all C++ constructors, it does not have a return data type.

This constructor is called to create an empty database, so this method should set the number of accounts data member to 0.

(As with the CreditAccount class, if you initialize the number of accounts data member to 0 when you declare it, this method's body can be empty. You still need to code the method with an empty body.)

Alternate AccountDB constructor - Write a second constructor for the AccountDB class that takes one parameter: a C++ string that contains the name of an existing database file. Like all C++ constructors, this constructor does not have a return data type.

This constructor should do the following:

Declare an input file stream variable (the code below assumes it is named inFile).

Open the file stream for binary input. Check to make sure the file was opened successfully as usual.

Read the database file into your AccountDB object. You can do this with a single statement:

   inFile.read((char*) this, sizeof(AccountDB));

Close the file stream.

print() - This method takes no parameters and returns nothing.

This method should first print a descriptive header line (e.g., "Credit Card Account Listing"). It should then loop through the array of CreditAccount objects and print each of the elements that contains account data, with a blank line between each account. Here we see some of the power of object-oriented programming: since each element of the array is an object, we can call a method for that object. We've already written a print() method for the CreditAccount class, so printing an element of the account array is as easy as calling print() for the array element. The syntax for calling a method using an array element that is an object is pretty straightforward:

   arrayName[subscript].methodName(arguments);

Step 6: Write the main program

Since most of the logic of the program is embedded in the two classes you wrote, the main() routine logic is extremely simple.

Create an AccountDB object using the alternate constructor you wrote. Pass the filename string literal "accounts" as an argument to the constructor.

Call the print() method for the AccountDB object.

Part 2:

For this part of the assignment, you'll need to write one new file and then modify two of the files you wrote for Part 1.

Step 1: Write a makefile

The file named makefile tells the make utility how to build the final executable file from your collection of C++ source code and header files. The makefile for this assignment is given in its entirety below. Makefiles for future assignments will follow this basic pattern.

IMPORTANT NOTE: The commands that appear in the makefile below MUST be indented as shown. Furthermore, the indentation MUST be done using a tab character, not spaces. If you don't indent your makefile commands, or indent using spaces, your makefile WILL NOT WORK.

#
# PROGRAM:    assign2
# PROGRAMMER: your name
# DATE DUE:   due date of program
#

# Compiler variables
CCFLAGS = -Wall -std=c++11

# Rule to link object code files to create executable file
assign2: assign2.o CreditAccount.o AccountDB.o
        g++ $(CCFLAGS) -o assign2 assign2.o CreditAccount.o AccountDB.o

# Rules to compile source code files to object code
assign2.o: assign2.cpp AccountDB.h
        g++ $(CCFLAGS) -c assign2.cpp

CreditAccount.o: CreditAccount.cpp CreditAccount.h
        g++ $(CCFLAGS) -c CreditAccount.cpp

AccountDB.o: AccountDB.cpp AccountDB.h
        g++ $(CCFLAGS) -c AccountDB.cpp

# The AccountDB class depends on the CreditAccount class
AccountDB.h: CreditAccount.h

# Pseudo-target to remove object code and executable files
clean:
        -rm *.o assign2

Once you've written the file makefile, try using the make utility to compile and link your program.

Step 2: Add the following methods to the AccountDB class

sortAccounts() - This method takes no parameters and returns nothing.

This method should sort the array of CreditAccount objects in ascending order by account number using the insertion sort algorithm.

The sort code linked to above sorts an array of integers called numbers of size size. You will need to make a substantial number of changes to that code to make it work in this program:

This will be a method, not a function. Change the parameters for the method to those described above.

In the method body, change the data type of bucket to CreditAccount. This temporary storage will be used to swap elements of the array of CreditAccount objects.

In the method body, change any occurrence of numbers to the name of your array of CreditAccount objects and size to numAccounts (or whatever you called the data member that tracks the number of valid CreditAccount objects stored in the array).

The comparison of accountArray[j-1] and bucket will need to use the C string library function strcmp() to perform the comparison. Also, you'll need to use the getAccountNumber() method to access the accountNumber data member within each CreditAccountobject. The final version of the inner for loop should look something like this:

   for (j = i; (j > 0) && (strcmp(accountArray[j-1].getAccountNumber(), bucket.getAccountNumber()) > 0); j--)
      ...

It is legal to assign one CreditAccount object to another; you don't need to write code to copy individual data members.

Add a call to the sortAccounts() method to the end of the alternate constructor you wrote for the AccountDB class. This will sort the array of CreditAccount objects that were read in from the input file.

searchForAccount() - This method should take one parameter: a character array containing the account number code of the CreditAccount to search for (searchNumber). The method should return an integer.

The logic for this method is a variation of the binary search of a sorted list strategy.

   int low = 0;
   int high = number of valid CreditAccount objects in the array - 1;
   int mid;

   while (low <= high)
      {
      mid = (low + high) / 2;

      if (searchNumber is equal to accountNumber data member of accountArray[mid])
         return mid;

      if (searchNumber is less than accountNumber data member of accountArray[mid])
         high = mid - 1;
      else
         low = mid + 1;
      }

   return -1;

As usual, you'll need to use strcmp() to perform the comparison of account numbers.

processTransactions() - This method should take one parameter: a C++ string containing the name of a file of credit card transaction data. The method should return nothing.

The method should open the specified transaction file for input (not binary input - this file is a text file). Make sure to test that the file was opened successfully; if it wasn't, print an error message and exit the program.

Before reading any transactions, the function should print a report header and column headers. The function should then read transaction data from the file until end of file is reached. A typical transaction is shown below. The first field on the transaction record is the date of the transaction, followed by an account number, then the transaction type ('C' for charge or 'P' for payment), and finally a transaction amount.

06/19 1111-1111-1111-1111 C 430.00

Once all of the data for a given transaction has been read, call the searchForAccount() method to search the accounts array for the account number given in the transaction. If the account number is present in the array, then the transaction may be processed. For a payment, simply call the processPayment() method for the object that contains a matching account number, passing it the transaction amount. For a charge, call the processCharge() method for the object that contains a matching account number, passing it the transaction amount.

For each transaction record processed, print a line in a transaction report with the data from the record and the updated balance for that account. If the balance is negative, it should be printed as a positive number but followed by the letters "CR". If the transaction account number was not found in the account array or if a charge exceeded the account's credit limit (i.e., if the processCharge() method returned false), print an appropriate error message instead of the account balance.

After all transactions have been processed, close the transaction file.

Step 3: Add two method calls to the main program

The main() routine logic will now look like this:

Create an AccountDB object using the alternate constructor you wrote. Pass the filename string "accounts" as an argument to the constructor.

Call the print() method for the AccountDB object.

Call the processTransactions() method for the AccountDB object. Pass the filename string "transactions.txt" as an argument to the method.

Call the print() method for the AccountDB object.

This completes the project.

Solutions

Expert Solution

//main.cpp

#include <iostream>
#include <fstream>
#include "CreditAccount.h"
#include "AccountDB.h"

using std::cout;
using std::endl;

int main()
{
// Test alternate constructor
AccountDB accountDB1("accounts"); /* Creates the only AccountDB object*/

/* Prints all CreditAccounts in the object array, process transactions and prints again */
   accountDB1.print();
   accountDB1.processTransactions("transactions.txt");
   accountDB1.print();

return 0;
}

===========================================================================

// FILE: CreditAccount.cpp
  
#include "CreditAccount.h"
#include <iostream> // Added
#include <cstring> // Added
#include <iomanip> // Added

using std::cout; // Added STDs
using std::endl; // Added STDs
using std::fixed;
using std::setprecision;


CreditAccount::CreditAccount()
   {
   strcpy(account_num,"");
   strcpy(customer_name, "");
   credit_limit = 0;
   currentBalance = 0;
   }

CreditAccount::CreditAccount(char newAcctNum[], char newName[], double newLimit, double newBalance)
   {
   strcpy(account_num,newAcctNum);
   strcpy(customer_name, newName);
   credit_limit = newLimit;
   currentBalance = newBalance;
   }


char* CreditAccount::getAccountNumber()
   {
   return account_num;
   }


char* CreditAccount::getName()
   {
   return customer_name;
   }


double CreditAccount::getLimit()
   {
   return credit_limit;
   }

double CreditAccount::getBalance()
   {
   return currentBalance;
   }

void CreditAccount::processPayment(double paymentAmount)
   {
   currentBalance = currentBalance - paymentAmount;
   }

bool CreditAccount::processCharge(double charge)
   {
   if(charge + currentBalance > credit_limit) /* if charge + current Balance goes pass the credit
                           limit, return false */
       {
       return false;
       }
   else /* If not, go ahead with the transaction and return true */
       {
       currentBalance = charge + currentBalance;
       return true;
       }
   }


void CreditAccount::print()
   {
/* Couts all data members */
   cout <<"Account Number: "<< getAccountNumber() <<endl <<"Name: "<<getName() <<endl <<"Credit Limit: $" <<fixed <<setprecision(2) <<credit_limit <<endl <<"Current Balance: ";

   /* If account balance is negitive, add a CR at the end of the number. If not, don't */
   if(getBalance() < 0)
       cout <<setprecision(2)<<"$" <<getBalance()<<" CR" <<endl;
   else
       cout <<setprecision(2)<<"$" <<getBalance() <<endl;
   }

======================================================================

// FILE: CreditAccount.h
  

#ifndef CREDIT_ACCOUNT_H
#define CREDIT_ACCOUNT_H
class CreditAccount
{
// Data members and method prototypes for the CreditAccount class go here
   char account_num[20];
   char customer_name[21];
   double credit_limit;
   double currentBalance;
// Method Prototypes
   // Constructors
   public:
    CreditAccount();
    CreditAccount(char newAcctNum[], char newName[], double newLimit, double newBalance);
   // Methods - Get
char* getAccountNumber();
char* getName();
double getLimit();
double getBalance();
   // Methods - Processing and Print
void processPayment(double paymentAmount);
bool processCharge(double charge);
void print();


   // Class methods and constructors located in CreditAccount.cpp //
};

#endif

=====================================================================

//AccountDB.cpp

#include "AccountDB.h"
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>

using std::cout;
using std::endl;
// Class Method Prototypes to be copied over to AccountDB header file

AccountDB::AccountDB()
   {
   HowManyAccounts = 0;
   }

AccountDB::AccountDB(const char* existingDB)
   {
   ifstream inFile;
   inFile.open(existingDB, ios::binary);
   if(!inFile)
       {
       cout <<"Error - Unable to open file" <<endl;
       }
   inFile.read((char*) this, sizeof(AccountDB));
   // Call to sortAccounts()
   sortAccounts();
   inFile.close();
   }


void AccountDB::print()
   {
   cout << "***Credit Card Account Holdings***" <<endl;

   for(int i = 0; i <= HowManyAccounts - 1; i++) /*int i is used to cycle through the subscripts in the for loop */
       {
       CreditAccount_Array[i].print();
       cout <<endl;
       }
   }

void AccountDB::sortAccounts()
   {
   int i, j; /* int i and j are used as subscripts */
   CreditAccount bucket; // Credit Account is the object data type

    for (i = 1; i < HowManyAccounts; i++) /* int i is used to cycle through the subscripts in the for loop */
    {
   bucket = CreditAccount_Array[i]; /* Bucket is used to hold a CreditAccount that is in the array while the array is being sorted. */

   /* Sorts through the accounts and lists the lowest numbered one first */
      for (j = i; (j > 0) && (strcmp(CreditAccount_Array[j-1].getAccountNumber() , bucket.getAccountNumber()) > 0); j--)
   CreditAccount_Array[j] = CreditAccount_Array[j-1];

   CreditAccount_Array[j] = bucket;
   }
   }

int AccountDB::searchForAccount(char* searchNumber)
   {
int low = 0; /* Used as the lowest subscript in the array, or binary sort */
int high = HowManyAccounts - 1; /* Used as the highest possible subscript in the accounts array */
int mid; /* The number we are looking for */

/* Binary search returns mid, which is the account we are looking for. -1 is returned if no account is found
   to match the passed in searchNumber */
while (low <= high)
{
mid = (low + high) / 2;

if (strcmp(searchNumber, CreditAccount_Array[mid].getAccountNumber()) == 0) // searchNumber is equal to accountNumber data member of accountArray[mid])
return mid;

if (strcmp(searchNumber, CreditAccount_Array[mid].getAccountNumber()) < 0) //searchNumber is less than accountNumber data member of accountArray[mid])
high = mid - 1;
else
low = mid + 1;
}

return -1;
   }


void AccountDB::processTransactions(char* newTransaction)
   {
   char date[6];
   char account_num[20];
   char TransactionType;
   double TransactionAmount;

/* Opens the passed in text file */
   ifstream inFile;
inFile.open(newTransaction);

/* if is used to make sure the file opened correctly, and if it didn't then is prints an error */
if(!inFile)
{
cout <<"Error - Unable to open file" <<endl;
       exit(1);
}

/* Cout header for the transactions */
cout <<" Transaction Report" <<endl;
cout <<"Date Account Type Amount New Balance" <<endl;


/*Opens a while for while we are in the file */
   while(inFile >> date)
       {
       /* Data members we are populating from the file */
       inFile >> account_num;
       inFile >> TransactionType;
       inFile >> TransactionAmount;
       bool stuff; /* Bool used to see if the transaction passes the accounts credit limit */
       int acct; /* int subscript for the number acct we are looking at. Changes every transaction in
               the while loop */
/* Cout all data members except balance */
       cout << endl << date << " " << account_num << " " << TransactionType << " " << TransactionAmount << " ";

/* Searches for the account we want to change the transactions on */
           acct = searchForAccount(account_num);
           if(acct != -1) /* If account exists */
           {

               if(TransactionType == 'C') /* If transaction is a credit */
                   {
                   stuff = CreditAccount_Array[acct].processCharge(TransactionAmount);
                   if(stuff) /* If Credit Limit is not passed */
                       {
                       cout <<CreditAccount_Array[acct].getBalance();
                       }
                   else   /* If Credit Limit is passed. Transaction does not occur */
                       {
                       cout <<"****Credit Limit Reached***";
                       }
                   }
               else if(TransactionType == 'P') /* If transaction is a payment */
                   {
                   CreditAccount_Array[acct].processPayment(TransactionAmount); /* Processes
                       payment regardless if the balance would be negitive afterwards */
                   if(CreditAccount_Array[acct].getBalance() < 0)
                       {
                       /* Shows account as a positve number instead of negitive, adds CR
                           for overdrafted account */
                       cout << CreditAccount_Array[acct].getBalance() * -1 <<" CR" ;
                       }
                   else /* If balance is still positive then print out */
                       {
                       cout << CreditAccount_Array[acct].getBalance();
                       }
                   }
           }
       else /* Will print out Invalid Account Number if account is not in the Account Array */
   {
           cout <<"Invalid Account Number";
   }
       }
   cout << endl << endl;
inFile.close(); /* Close Input File after While loop */

   }

=================================================================

//AccountDB.h
#ifndef ACCOUNT_DB_H
#define ACCOUNT_DB_H
   #include "CreditAccount.h"

using namespace std;
class AccountDB
{
// Data members and method prototypes for the CreditAccount class go here
   private:
       CreditAccount CreditAccount_Array[20];
       int HowManyAccounts;
   // Account DB Methods
   public: // Constructors
       AccountDB();
       AccountDB(const char*);
       // Other
       void print();
       // Part 2 Methods
       void sortAccounts();
       int searchForAccount(char*);
       void processTransactions(char*);
};

#endif

=============================================================

//transactions.txt
06/19 9858-5420-3025-7452 P 5500.00
06/19 1111-1111-1111-1111 C 430.00
06/20 7307-8304-0929-4295 C 36.45
06/20 1132-2648-4476-0945 P 130.00
06/20 5540-8530-4034-5532 C 275.23
06/20 7307-8304-0929-4295 P 250.00

===================================================================

sample output:


Related Solutions

PLEASE CODE IN JAVA In this assignment you will write a program in that can figure...
PLEASE CODE IN JAVA In this assignment you will write a program in that can figure out a number chosen by a human user. The human user will think of a number between 1 and 100. The program will make guesses and the user will tell the program to guess higher or lower.                                                                   Requirements The purpose of the assignment is to practice writing functions. Although it would be possible to write the entire program in the main function, your...
Source code with comments explaining your code in C# Program 2: Buh-RING IT! For this assignment,...
Source code with comments explaining your code in C# Program 2: Buh-RING IT! For this assignment, you’re going to simulate a text-based Role-Playing Game (RPG). Design (pseudocode) and implement (source) for a program that reads in 1) the hero’s Hit Points (HP – or health), 2) the maximum damage the hero does per attack, 3) the monster’s HP and 4) the maximum monster’s damage per attack. When the player attacks, it will pick a random number between 0 and the...
This problem needs to be solved with source code. I need a C++ program that will...
This problem needs to be solved with source code. I need a C++ program that will help me solve this question. I need it in C++, please. Writing with comments so it maybe cleared. 1.2. We received the following ciphertext which was encoded with a shift cipher: xultpaajcxitltlxaarpjhtiwtgxktghidhipxciwtvgtpilpit ghlxiwiwtxgqadds. 1. Perform an attack against the cipher based on a letter frequency count: How many letters do you have to identify through a frequency count to recover the key? What is...
Write the code in python only. You will need the graphics library for this assignment. Please...
Write the code in python only. You will need the graphics library for this assignment. Please download the library and place it in the same file as your solution. Draw a 12" ruler on the screen. A ruler is basically a rectangular outline with tick marks extending from the top edge. The tick marks should be drawn at each quarter-inch mark. Below the tick marks, your ruler should show large integers at each full-inch position.
There are three steps (open, action, close) required for handling files. You need to write a...
There are three steps (open, action, close) required for handling files. You need to write a Python program what executes each of these three steps. Your program must include:  Extensive comments to ensure explanation of your code (1).  Open a file (file name must include your student number, thus filexxxxxxxx.txt). (1).  Write the details of the five students (from Question 1 above) to a file (3).  Close the file. (1)  Then open the file again...
For this assignment, you need to write a parallel program in C++ using OpenMP for vector...
For this assignment, you need to write a parallel program in C++ using OpenMP for vector addition. Assume A, B, C are three vectors of equal length. The program will add the corresponding elements of vectors A and B and will store the sum in the corresponding elements in vector C (in other words C[i] = A[i] + B[i]). Every thread should execute an approximately equal number of loop iterations. The only OpenMP directive you are allowed to use is:...
I need specific codes for this C program assignment. Thank you! C program question: Write a...
I need specific codes for this C program assignment. Thank you! C program question: Write a small C program connect.c that: 1. Initializes an array id of N elements with the value of the index of the array. 2. Reads from the keyboard or the command line a set of two integer numbers (p and q) until it encounters EOF or CTL - D 3. Given the two numbers, your program should connect them by going through the array and...
I am Writing a C-Program to read and write files. but none of my code is...
I am Writing a C-Program to read and write files. but none of my code is working like it should be. Please fix all code and supply output response. Please try to use existing code and code in comments. But if needed change any code that needs to be changed. Thank you in advance //agelink.c //maintains list of agents //uses linked list #include <stdio.h> #include <stdlib.h> #define TRUE 1 void listall(void); void newname(void); void rfile(void); void wfile(void); struct personnel {...
Need C++ code for following with a document describing the code as well: Write a program...
Need C++ code for following with a document describing the code as well: Write a program to implement the game of Tic Tac Toe Four. The game is played on a 4 × 4 chessboard, within 2 players. The player who is playing "X" always goes first. Players alternate placing Xs and Os on the board until either one player has four in a row, horizontally, vertically, or diagonally; or all 16 squares are filled(which is a draw). The program...
Write a program that solves the Knapsack problem. Code to the following standards. Your source of...
Write a program that solves the Knapsack problem. Code to the following standards. Your source of items to put into the knapsack should consist of five randomly generated integers in the range of 1 to 20. Your knapsack can hold 20 lbs.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT