Lecture190 Member functio - Bank Simulation (banking.h)...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 1 -- 1 Computer Science I - Martin Hardwick Bank Simulation (banking.h) #include <iostream> #include <iomanip> #include <string> #include <fstream> #include <vector> #include “acct.h” using namespace std; class banking { private: vector <acct> bank; // bank accounts public: banking (); int find(int goal); void insert(acct newacct); int size (); // current size of the bank acct get (int loc); // account at a location }; This class simulates a bank by processing transactions for bank accounts. A vector is used to hold the list of bank accounts. A bank account consists of an account number, the name of the person who owns it, and the current balance. we use a C++ class to do this
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lecture 1 -- 2 Computer Science I - Martin Hardwick Bank Simulation (2) #include “banking.h” int main () //PURPOSE: simulate a small bank //PRECONDITIONS: existing  //     accounts in file account.txt //     in project folder //POSTCONDITIONS: finds,  inserts,  //     deletes, and lists accounts { // list of bank accounts banking  my_bank; // file with list of bank accounts ifstream vault; // user request string command; // account number to find int goal; The main function creates the list of bank accounts and processes user commands to perform transactions. The number of accounts is unlimited. The existing accounts are read from a file at the start of the program. this creates the bank vector  for the program to use User commands are typed as strings (e.g., find, insert, exit).
Background image of page 2
-- 3 Computer Science I - Martin Hardwick Bank Simulation (3) // subscript of account in bank  int loc; // a bank account  acct account; int  num; string  nme; double  bal; // read existing accounts from file vault.open("accounts.txt"); vault >> num >> nme  >> bal;  while (!vault.eof()) {     account = account (num,  nme, bal);     my_bank.insert (account);     vault >> num >> nme >> bal; } // display dollar values correctly cout << setiosflags(ios::fixed)  << setprecision(2); The program assumes that a file named accounts.txt contains the data for existing accounts.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 14

Lecture190 Member functio - Bank Simulation (banking.h)...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online