solutions22 - CSCI-1100 Computer Science I Rensselaer...

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

View Full Document Right Arrow Icon
CSCI-1100 Computer Science I Rensselaer Polytechnic Institute Spring 2004 Studio 22 -- Solutions #include <iostream> #include <iomanip> #include <string> #include <fstream> using namespace std; // Create bank account data type struct acct { // bank account data int num; // account number string name; // owner of account float balance; // balance in account }; // Function Prototypes int find(acct bank[ ], int numaccts, int goal); void insert(acct bank[ ], int &numaccts, acct newacct); void remove(acct bank[ ], int &numaccts, int acctnum); int main () //PURPOSE: simulate a small bank //PRECONDITIONS: existing accounts in file account.txt // in project folder //POSTCONDITIONS: finds, inserts and deletes accounts { acct bank[1000]; // list of bank accounts int numaccts; // total number of accounts ifstream vault; // file with list of bank accounts string command; // user request int goal; // account number to find or delete int goal2; // 2 nd goal for transfer op int loc; // subscript of account in list int loc2; // subscript of 2 nd account acct account; // a bank account float amount; // amount of money // read existing accounts from file"accounts.txt"); numaccts=0; vault >> bank[0].num >> bank[0].name >> bank[0].balance; while (!vault.eof()) { numaccts = numaccts + 1; vault >> bank[numaccts].num >> bank[numaccts].name >> bank[numaccts].balance; } // display dollar values with 2 digits to right of decimal point cout << setiosflags(ios::fixed) << setprecision(2);
Background image of page 1

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

View Full DocumentRight Arrow Icon
// get ready to process user commands cout << "The bank is now open." ; cout << endl << endl; // loop to process user commands cout << endl << "----------" << endl; cout << "Enter a command (exit to stop): "; cin >> command; while (command != "exit") {
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This homework help was uploaded on 04/16/2008 for the course CSCI 1100 taught by Professor Hardwick during the Fall '08 term at Rensselaer Polytechnic Institute.

Page1 / 6

solutions22 - CSCI-1100 Computer Science I Rensselaer...

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

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