Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I need some help with a code that I am working on. Here is what it is suppose to do:
- Description of the program: Write an application that serves as a personal account manager that manages multiple accounts for the user. To keep multiple accounts, you are required to use a list.
- Specifications:-** Modify the Account class.** - add an additional data number that represents the (unique) account number. This data member will be used as the key to locate the account. Next modify the constructor(s) and display method. - add a new method getNumber to return the account number. - overload the pipe operator (<<) to display the account information. - overload the equal-to operator (==) to compare two accounts based on the account number. - overload the assignment operator (=) to assign (copy) one account to another.
- This application should also have a menu-driven interface. The application is responsible to produce proper messages and inform the user whether the particular transaction is successful or not. Can define own fuctions to facilitate this application. The menu should contain the following options: Exit: terminate the application Open an account: user will be asked for the opening balance (with interest rate fixed) and the (unique) account number, and a new account will be created. If there is no room in the list, try to double the size of the list and open the account again. Check an account: user will be prompted for the account number, and the information of the account (if exists) is displayed. Close an account: user will be prompted for the account number and the account will be closed. Check all accounts: all accounts' information will be displayed. Deposit: user will be asked for a specific account and the amount to deposit.
- Withdraw: user will be asked for a specific account and the amount to withdraw. Transfer: user will be prompted for the account number to transfer from, the account number to transfer to, and the amount of the transfer.
- Need to use list using dynamic array (ListDA) to implement this application. Start with the default size(CAPACITY) of 2. Need to create a new solution (Personal Account Manager Solution), a new project ( Personal Account Manager Project), and a source file ( main.cpp) that uses Account and ListDA objects. In order to use those objects need to manually copy the class files (header and implementation files) of both classes into project.
- I have five files with code. I will post them and the code in each now.
- main.cpp contains this code:
- #include "stdafx.h"
- #include <iostream>
- #include <iomanip>
- #include "Account.h"
- #include "ListDA.h"
- using namespace std;
- int main()
- {
- int choice;
- int openBal;
- int accountNum;
- int accountNums;
- int depositAmt;
- int withdrawAmt;
- int transferAmt;
- cout << "1. Open an account. " << endl;
- cout << "2. Check an account. " << endl;
- cout << "3. Close an account. " << endl;
- cout << "4. Check all accounts. " << endl;
- cout << "5. Deposit. " << endl;
- cout << "6. Withdraw. " << endl;
- cout << "7. Transfer. " << endl;
- cout << "8. Exit. " << endl;
- cout << " Please make a selcetion from the choices above (1-8): ";
- cin >> choice;
- cout << endl;
- switch (choice){
- case 1:
- cout << "Please enter the opening balence: $ ";
- cin >> openBal;
- cout << endl;
- cout << "Please enter the account number: ";
- cin >> accountNum;
- cout << endl;
- break;
- case 2:
- cout << "Please enter the account number: ";
- cin >> accountNum;
- cout << endl;
- break;
- case 3:
- cout << "Please enter the account number: ";
- cin >> accountNum;
- cout << endl;
- break;
- case 4:
- cout << "Please enter all the account numbers to show: ";
- cin >> accountNums;
- cout << endl;
- break;
- case 5:
- cout << "Please enter the account number you wish to deposit money into: ";
- cin >> accountNum;
- cout << endl;
- cout << "Please enter how much money you want to deposit into the account: $ ";
- cin >> depositAmt;
- cout << endl;
- break;
- case 6:
- cout << "Please enter the account number you wish to make a withdraw from: ";
- cin >> accountNum;
- cout << endl;
- cout << "Please enter the amount you wish to withdraw from the account: $ ";
- cin >> withdrawAmt;
- cout << endl;
- break;
- case 7:
- cout << "Please enter the account number you wish to transfer money from: ";
- cin >> accountNum;
- cout << endl;
- cout << "Please enter the account number you wish to transfer the money to: ";
- cin >> accountNum;
- cout << endl;
- cout << "Please enter the amount of money you want to transfer: $ ";
- cin >> transferAmt;
- cout << endl;
- break;
- case 8:
- cout << "Thank you! Come back soon. ";
- cout << endl;
- break;
- default:
- cout << "That was an invaild choice. " << endl;
- cout << "Please make a selection (1-8): ";
- cin >> choice;
- cout << endl;
- } //end case
- system ("pause");
- return 0;
- } // end main
- Account.h contains this code:
- #pragma once
- #ifndef _ACCOUNT_
- #define _ACCOUNT_
- // default values
- #define START_BALANCE 500.0
- #define START_INTEREST_RATE 0.0175
- // define Account class
- class Account
- {
- private:
- double balance;
- double interestRate;
- public:
- // constructor with default values
- // set to default values if value(s) is/are not valid
- Account(double initialBalance, double initialInterestRate);
- // observers
- double getBalance() const; // return balance
- double getInterestRate() const; // return interestRate
- void displayAccountInformation() const; // display formatted account information through cout
- // transformers
- bool deposit(double amount);
- // disposit amount into account
- // return false if unsuccessful (amount invalid, balance not changed)
- // true otherwise
- bool withdraw(double amount);
- // withdraw amount from account
- // return false if unsuccessful (amount invalid, balance not changed)
- // true otherwise
- void applyInterest(); // apply interestRate to balance
- bool setInterestRate(double newRate);
- // change interestRate to newRate
- // return false if unsuccessful (newRate invalid, interestRate not changed)
- // true otherwise
- bool setBalance(double newBalance);
- // change balance to newBalance
- // return false if unsuccessful (newBalance invalid, balance not changed)
- // true otherwise
- }; // end Account
- #endif
- Account.cpp contains this code:
- #include "stdafx.h"
- #include <iostream>
- #include <iomanip>
- #include "Account.h"
- #include "ListDA.h"
- using namespace std;;
- // constructor with default values
- // set to default values if value(s) is/are not valid
- Account::Account(double initialBalance = START_BALANCE, double initialInterestRate = START_INTEREST_RATE)
- {
- if (initialBalance >= 0)
- balance = initialBalance;
- else // initialBalance < 0
- balance = START_BALANCE;
- if (initialInterestRate >= 0 && initialInterestRate < 1)
- interestRate = initialInterestRate;
- else // initialInterestRate >= 1 or initialInterestRate < 0
- interestRate = START_INTEREST_RATE;
- } // end Account
- // observers
- double Account::getBalance() const
- // return balance
- {
- return balance;
- } // end getBalance
- double Account::getInterestRate() const
- // return interestRate
- {
- return interestRate;
- } // end getInterestRate
- void Account::displayAccountInformation() const
- // display formatted account information through cout
- {
- cout << "Account Information" << endl
- << "Current Balance: $" << fixed << setprecision(2) << balance << endl
- << "Interest Rate: " << interestRate * 100 << "%" << endl;
- } // end displayAccountInformation
- // transformers
- bool Account::deposit(double amount)
- // disposit amount into account
- // return false if unsuccessful (amount invalid, balance not changed)
- // true otherwise
- {
- if (amount < 0) // invalid amount
- return false;
- balance += amount;
- return true;
- } // end deposit
- bool Account::withdraw(double amount)
- // withdraw amount from account
- // return false if unsuccessful (amount invalid, balance not changed)
- // true otherwise
- {
- if (amount < 0 || amount > balance) // invalid amount
- return false;
- balance -= amount;
- return true;
- } // end withdraw
- void Account::applyInterest()
- // apply interestRate to balance
- {
- balance *= 1.0 + interestRate;
- } // end applyInterest
- bool Account::setInterestRate(double newRate)
- // change interestRate to newRate
- // return false if unsuccessful (newRate invalid, interestRate not changed)
- // true otherwise
- {
- if (newRate < 0 || newRate >= 1) // invalid newRate
- return false;
- interestRate = newRate;
- return true;
- } // end setInterestRate
- bool Account::setBalance(double newBalance)
- // change balance to newBalance
- // return false if unsuccessful (newBalance invalid, balance not changed)
- // true otherwise
- {
- if (newBalance < 0) // invalid balance
- return false;
- balance = newBalance;
- return true;
- } // end setBalance
- ListDA.h contains this code:
- // basic assumptions
- // 1. no duplication in the list
- // 2. user is resposible to check the status of the list
- // before using any transformer method
- #pragma once
- #ifndef _LIST_DA_
- #define _LIST_DA_
- #include <iostream>
- #include <iomanip>
- using namespace std;
- const int CAPACITY = 2; // default size
- // flexible element type
- // user is responsible for overloading
- // assignment (=), equal (==), and pipe (<<) operators
- typedef int elemType;
- class ListDA
- {
- private:
- elemType* list; // pointer to the array to hold items
- int size; // number of items in this list
- int maxSize; // capacity of the array
- // utility methods
- int find(const elemType& item) const;
- // returns position of item in this list if present
- // -1 otherwise
- public:
- // constructors
- ListDA(void); // default constructor
- ListDA(int size); // general constructor
- ListDA(const ListDA& aList); // copy constructor
- // observers
- bool isEmpty() const;
- // returns true if this list is empty
- // false otherwise
- bool isFull() const;
- // returns true if this list is full
- // false otherwise
- int getSize() const;
- // returns the number of items in this list
- void display(ostream& out) const;
- // displays every item in this list through out
- bool retrieve(elemType& item) const;
- // retrieves item from this list
- // returns true if item is present in this list and
- // element in this list is copied to item
- // false otherwise
- // transformers
- void insert(const elemType& item);
- // inserts item into this list
- // preconditions: list is not full and
- // item not present in this list
- // postcondition: item is in this list
- void remove(elemType& item);
- // removes item from this list
- // postcondition: item is no longer in this list
- bool changeSize(int newSize);
- // changes the capacity to newSize
- // all items in this list is retained
- // returns true if successful
- // returns false if no memory is available, or
- // the newSize is smaller than size
- // destructor
- // default destructor
- ~ListDA();
- }; // end ListSA
- #endif
- ListDA.cpp contains this code:
- #include "stdafx.h"
- #include <iostream>
- #include <iomanip>
- #include "Account.h"
- #include "ListDA.h"
- using namespace std;
- // utility methods
- int ListDA::find(const elemType& item) const
- // returns position of item in this list if present
- // -1 otherwise
- {
- int pos = -1;
- for (int i = 0; i < size && pos < 0; i++)
- if (list[i] == item)
- pos = i;
- return pos;
- } // end
- // constructors
- ListDA::ListDA(void) // default constructor
- {
- list = new elemType[CAPACITY];
- maxSize = CAPACITY;
- size = 0;
- } // default constructor
- ListDA::ListDA(int aSize) // general constructor
- {
- list = new elemType[aSize];
- maxSize = aSize;
- size = 0;
- }
- ListDA::ListDA(const ListDA& aList) // copy constructor
- {
- maxSize = aList.maxSize;
- list = new elemType[maxSize];
- size = aList.size;
- for (int i = 0; i < size; i++)
- list[i] = aList.list[i];
- } // copy constructor
- // observers
- bool ListDA::isEmpty() const
- // returns true if this list is empty
- // false otherwise
- {
- return size == 0;
- } // end isEmpty
- bool ListDA::isFull() const
- // returns true if this list is full
- // false otherwise
- {
- return size == maxSize;
- } // end isFull
- int ListDA::getSize() const
- // returns the number of items in this list
- {
- return size;
- } // end getSize
- void ListDA::display(ostream& out) const
- // displays every item in this list through out
- {
- for (int i = 0; i < size; i++)
- out << setw(3) << (i+1) << ". " << list[i] << endl;
- } // end display
- bool ListDA::retrieve(elemType& item) const
- // retrieves item from this list
- // returns true if item is present in this list and
- // element in this list is copied to item
- // false otherwise
- {
- int pos = find(item);
- if (pos < 0)
- return false;
- else // post >= 0
- {
- item = list[pos];
- return true;
- }
- } // end retrieve
- // transformers
- void ListDA::insert(const elemType& item)
- // inserts item into this list
- // preconditions: list is not full and
- // item not present in this list
- // postcondition: item is in this list
- {
- list[size++] = item;
- } // end insert
- void ListDA::remove(elemType& item)
- // removes item from this list
- // postcondition: item is no longer in this list
- {
- int pos = find(item);
- if (pos >= 0)
- list[pos] = list[--size];
- } // end remove
- bool ListDA::changeSize(int newSize)
- // changes the capacity to newSize
- // all items in this list is retained
- // returns true if successful
- // returns false if no memory is available, or
- // the newSize is smaller than size
- {
- if (size > newSize) // newSize cannot hold all items
- return false;
- if (maxSize == newSize)
- return true;
- elemType* newList = new elemType[newSize];
- if (newList == 0) // memory allocation failed
- return false;
- for (int i = 0; i < size; i++) // move items
- newList[i] = list[i];
- maxSize = newSize;
- delete [] list; // get rid of old space
- list = newList; // point to new list
- return true;
- } // end changeSize
- // destrcutor
- // default destructor
- ListDA::~ListDA()
- {
- delete [] list;
- } // end ~ListDA
- So there is all my code and at the top is what I am trying to get the program to do. Please help.
Advertisement
Add Comment
Please, Sign In to add comment