| | |
Classes and Drivers
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2007
Posts: 31
Reputation:
Solved Threads: 0
Hello! I have written written my own class, which includes a header file and a .cpp file. I have also written the driver for this program. Everything looks fine to me, but I am receiving about 20 random errors. I will post my code for all 3 files but I believe it is a problem that can be diagnosed using just the driver.
The program is a bank account program that adds new accounts, withdraws, deposits, updates, displays, etc. Any help would be greatly appreciated! Thanks.
HEADER
CLASS DEFINITION
DRIVER
The program is a bank account program that adds new accounts, withdraws, deposits, updates, displays, etc. Any help would be greatly appreciated! Thanks.
HEADER
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> using namespace std; class BankAccount { public: BankAccount(); void deposit( double amt ); void withdraw( double amt ); void update(); int getID(); void setID( int anID ); double getBalance(); void setBalance( double amt ); double getInterestRate(); void setInterestRate( double amt ); string getFirstName(); void setFirstName( string theName ); string getLastName(); void setLastName( string theName ); string getFullName(); void display(); private: string firstName, lastName; double interestRate; int ID; double balance; };
CLASS DEFINITION
C++ Syntax (Toggle Plain Text)
#include "BankAccount.h" /* Default Constructor */ BankAccount::BankAccount() { ID = 0; balance = 0.0; interestRate = 0.0; } /* Adds deposit amount to current balance */ void BankAccount::deposit( double amt ) { balance = balance + amt; } /* Withdraws amount from current balance if there are sufficient funds. Fails quietly for insufficient funds. */ void BankAccount::withdraw( double amt ) { if( balance < amt ) return; balance = balance - amt; } /* Getter (accessor) for balance */ double BankAccount::getBalance() { return balance; } /* Setter (mutator) for balance */ void BankAccount::setBalance( double amt ) { balance = amt; } /* Adds interest to account using current interest rate */ void BankAccount::update() { balance = balance + balance * interestRate; } /* Getter for ID */ int BankAccount::getID() { return ID; } /* Setter for ID */ void BankAccount::setID( int anID ) { ID = anID; } /* Getter for balance */ double BankAccount::getInterestRate() { return interestRate; } /* Setter for interest rate */ void BankAccount::setInterestRate( double amt ) { interestRate = amt; } /* Getter for first name */ string BankAccount::getFirstName() { return firstName; } /* Setter for first name */ void BankAccount::setFirstName( string theName ) { firstName = theName; } /* Getter for last name */ string BankAccount::getLastName() { return lastName; } /* Setter for last name */ void BankAccount::setLastName( string theName ) { lastName = theName; } /* Getter for full name */ string BankAccount::getFullName() { return lastName + ", " + firstName; } /* Displays info about about to console. */ void BankAccount::display() { cout << "ID : " << ID << endl; cout << "Name : " << getFullName() << endl; cout << "Balance : $" << balance << endl; cout << "Interest Rate : " << interestRate << " %" << endl; }
DRIVER
C++ Syntax (Toggle Plain Text)
#include "BankAccount.h" int getChoice(); void addBankAccount(); void withdrawAccount(); void depositAccount(); void updateAccounts(); void displayAccount(); void displayBalance(); void displayInfo(); int find(count, accts, id); double tempRate; double balance; int count[10]; BankAccount accts[10]; int nextID = 100; void main() { int choice; do{ choice = getChoice(); if( choice == 1 ) addBankAccount(); else if( choice == 2 ) withdrawAccount(); else if( choice == 3 ) depositAccount(); else if( choice == 4 ) updateAccounts(); else if( choice == 5 ) displayAccount(); else if( choice == 6 ) displayBalance(); else if( choice == 7 ) displayInfo(); if( choice > 8 || choice < 1 ) cout << "ERROR: Please enter valid choice (1-8)." << endl; } while( choice != 8 ); } //This function displays the calculation menu. int getChoice() { int c; cout << "----------------------\n"; cout << "1 - Add a new bank account.\n"; cout << "2 - Withdraw from a specific bank account.\n"; cout << "3 - Deposit to a specific account.\n"; cout << "4 - Update all accounts which will add a fixed interest rate to each account.\n"; cout << "5 - Display one specific bank accout.\n"; cout << "6 - Display the average balance for all of the accounts.\n"; cout << "7 - Display the current information for all accounts.\n"; cout << "8 - Terminate the program.\n"; cout << "----------------------\n"; cout << "Enter number of choice --> "; cin >> c; return c; } //This function adds a bank account for a new member. void addBankAccount() { int count = 0; string temp; cout << "Please enter first name."; cin >> temp; accts[count].setFirstName(temp); cout << "Please enter last name."; cin >> temp; accts[count].setLastName(temp); cout << "Please enter balance."; cin >> balance; accts[count].setBalance(balance); cout << "Please enter interest rate (decimal form)."; cin >> tempRate; accts[count].setInterestRate(tempRate); accts[count].setID(nextID); nextID = nextID + 1; count++; } // This function withdraws an amount from a specific account. void withdrawAccount() { int slot; double amt; int id; cout << "Enter ID number."; cin >> id; int slot = find(count, accts, id) cout << "Enter amount to withdraw."; cin >> amt; accts[slot].withdraw(amt); } //This function deposits an amount into a specific account. void depositAccount() { int slot; double amt; int id; cout << "Enter ID number."; cin >> id; int slot = find(count, accts, id) cout << "Enter amount to deposit."; cin >> amt; accts[slot].deposit(amt); } //This function updates all accounts using a fixed interest rate. void updateAccounts() { for (int i=0; i<count; i++) accts[i].update(); } //This function displays one bank account. void displayAccount() { int target; cout << "Enter account number."; cin >> target; accts[target].display(); } //This function displays the average balance of all accounts. void displayBalance() { } //This function displays the current information for all accounts. void displayInfo() { for (int i=0; i<count; i++) accts[i].display(); } int find(count, accts, id) { int index = 0; bool found = false; while ((!found) && (index < count)) if (id == accts[index]) found = true; else index++; if (found) return index; else return -1; }
Last edited by RaCheer; Apr 13th, 2007 at 12:49 am.
•
•
•
•
Hello! I have written written my own class, which includes a header file and a .cpp file. I have also written the driver for this program. Everything looks fine to me, but I am receiving about 20 random errors. I will post my code for all 3 files but I believe it is a problem that can be diagnosed using just the driver.
The program is a bank account program that adds new accounts, withdraws, deposits, updates, displays, etc. Any help would be greatly appreciated! Thanks.
Don't you think knowing what the errors are and where the errors are might be helpful in fixing the errors?
And please format your code. It's barely readable without proper indentation.
[edit]I see this has been mentioned at least 4 times. Are you bucking for an infraction? I really hate being ignored, and trying to read more unreadable code. Are you having a problem understanding good formatting guidelines?[/edit]
Last edited by WaltP; Apr 13th, 2007 at 1:36 am.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
•
•
Join Date: Feb 2007
Posts: 31
Reputation:
Solved Threads: 0
Sorry...I just thought it might be more obvious to someone else. These are errors that don't make sense to me because they worked before. I have declared what the error says is not and etc. So here are the errors I receive:
C++ Syntax (Toggle Plain Text)
error C2065: 'count' : undeclared identifier error C2065: 'accts' : undeclared identifier error C2065: 'id' : undeclared identifier error C2078: too many initializers error C2040: 'count' : 'int [10]' differs in levels of indirection from ''unknown-type'' error C2040: 'accts' : 'BankAccount [10]' differs in levels of indirection from ''unknown-type'' error C2228: left of '.setFirstName' must have class/struct/union error C2228: left of '.setLastName' must have class/struct/union error C2228: left of '.setBalance' must have class/struct/union error C2228: left of '.setInterestRate' must have class/struct/union error C2228: left of '.setID' must have class/struct/union error C2086: 'int slot' : redefinition see declaration of 'slot' error C2146: syntax error : missing ';' before identifier 'cout' error C2228: left of '.withdraw' must have class/struct/union error C2374: 'slot' : redefinition; multiple initialization see declaration of 'slot' error C2228: left of '.deposit' must have class/struct/union error C2228: left of '.update' must have class/struct/union error C2228: left of '.display' must have class/struct/union error C2228: left of '.display' must have class/struct/union error C2448: 'find' : function-style initializer appears to be a function ==========
•
•
Join Date: Feb 2007
Posts: 31
Reputation:
Solved Threads: 0
HEADER
CLASS DEFINITION
DRIVER
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> using namespace std; class BankAccount { public: BankAccount(); void deposit( double amt ); void withdraw( double amt ); void update(); int getID(); void setID( int anID ); double getBalance(); void setBalance( double amt ); double getInterestRate(); void setInterestRate( double amt ); string getFirstName(); void setFirstName( string theName ); string getLastName(); void setLastName( string theName ); string getFullName(); void display(); private: string firstName, lastName; double interestRate; int ID; double balance; };
CLASS DEFINITION
C++ Syntax (Toggle Plain Text)
#include "BankAccount.h" /* Default Constructor */ BankAccount::BankAccount() { ID = 0; balance = 0.0; interestRate = 0.0; } /* Adds deposit amount to current balance */ void BankAccount::deposit( double amt ) { balance = balance + amt; } /* Withdraws amount from current balance if there are sufficient funds. Fails quietly for insufficient funds. */ void BankAccount::withdraw( double amt ) { if( balance < amt ) return; balance = balance - amt; } /* Getter (accessor) for balance */ double BankAccount::getBalance() { return balance; } /* Setter (mutator) for balance */ void BankAccount::setBalance( double amt ) { balance = amt; } /* Adds interest to account using current interest rate */ void BankAccount::update() { balance = balance + balance * interestRate; } /* Getter for ID */ int BankAccount::getID() { return ID; } /* Setter for ID */ void BankAccount::setID( int anID ) { ID = anID; } /* Getter for balance */ double BankAccount::getInterestRate() { return interestRate; } /* Setter for interest rate */ void BankAccount::setInterestRate( double amt ) { interestRate = amt; } /* Getter for first name */ string BankAccount::getFirstName() { return firstName; } /* Setter for first name */ void BankAccount::setFirstName( string theName ) { firstName = theName; } /* Getter for last name */ string BankAccount::getLastName() { return firstName; } /* Setter for last name */ void BankAccount::setLastName( string theName ) { lastName = theName; } /* Getter for full name */ string BankAccount::getFullName() { return lastName + ", " + firstName; } /* Displays info about about to console. */ void BankAccount::display() { cout << "ID : " << ID << endl; cout << "Name : " << getFullName() << endl; cout << "Balance : $" << balance << endl; cout << "Interest Rate : " << interestRate << " %" << endl; }
DRIVER
C++ Syntax (Toggle Plain Text)
#include "BankAccount.h" int getChoice(); void addBankAccount(); void withdrawAccount(); void depositAccount(); void updateAccounts(); void displayAccount(); void displayBalance(); void displayInfo(); int find(count, accts, id); double tempRate; double balance; int count[10]; BankAccount accts[10]; int nextID = 100; void main() { int choice; do{ choice = getChoice(); if( choice == 1 ) addBankAccount(); else if( choice == 2 ) withdrawAccount(); else if( choice == 3 ) depositAccount(); else if( choice == 4 ) updateAccounts(); else if( choice == 5 ) displayAccount(); else if( choice == 6 ) displayBalance(); else if( choice == 7 ) displayInfo(); if( choice > 8 || choice < 1 ) cout << "ERROR: Please enter valid choice (1-8)." << endl; } while( choice != 8 ); } //This function displays the calculation menu. int getChoice() { int c; cout << "----------------------\n"; cout << "1 - Add a new bank account.\n"; cout << "2 - Withdraw from a specific bank account.\n"; cout << "3 - Deposit to a specific account.\n"; cout << "4 - Update all accounts which will add a fixed interest rate to each account.\n"; cout << "5 - Display one specific bank accout.\n"; cout << "6 - Display the average balance for all of the accounts.\n"; cout << "7 - Display the current information for all accounts.\n"; cout << "8 - Terminate the program.\n"; cout << "----------------------\n"; cout << "Enter number of choice --> "; cin >> c; return c; } //This function adds a bank account for a new member. void addBankAccount() { int count = 0; string temp; cout << "Please enter first name."; cin >> temp; accts[count].setFirstName(temp); cout << "Please enter last name."; cin >> temp; accts[count].setLastName(temp); cout << "Please enter balance."; cin >> balance; accts[count].setBalance(balance); cout << "Please enter interest rate (decimal form)."; cin >> tempRate; accts[count].setInterestRate(tempRate); accts[count].setID(nextID); nextID = nextID + 1; count++; } // This function withdraws an amount from a specific account. void withdrawAccount() { int slot; double amt; int id; cout << "Enter ID number."; cin >> id; int slot = find(count, accts, id) cout << "Enter amount to withdraw."; cin >> amt; accts[slot].withdraw(amt); } //This function deposits an amount into a specific account. void depositAccount() { int slot; double amt; int id; cout << "Enter ID number."; cin >> id; int slot = find(count, accts, id) cout << "Enter amount to deposit."; cin >> amt; accts[slot].deposit(amt); } //This function updates all accounts using a fixed interest rate. void updateAccounts() { for (int i=0; i<count; i++) accts[i].update(); } //This function displays one bank account. void displayAccount() { int target; cout << "Enter account number."; cin >> target; accts[target].display(); } //This function displays the average balance of all accounts. void displayBalance() { } //This function displays the current information for all accounts. void displayInfo() { for (int i=0; i<count; i++) accts[i].display(); } int find(count, accts, id) { int index = 0; bool found = false; while ((!found) && (index < count)) if (id == accts[index]) found = true; else index++; if (found) return index; else return -1; }
Last edited by RaCheer; Apr 13th, 2007 at 2:06 am. Reason: Indentation
•
•
Join Date: Feb 2007
Posts: 31
Reputation:
Solved Threads: 0
I totally overlooked that. Thank you. I have got it down to one error now. It says that count has an undeclared identifier. I declared it in the addBankAccount function. I tried declaring it before main and passing it as a parameter but I got even more errors. Here is my new code for the driver:
C++ Syntax (Toggle Plain Text)
#include "BankAccount.h" int getChoice(); void addBankAccount(); void withdrawAccount(); void depositAccount(); void updateAccounts(); void displayAccount(); void displayBalance(); void displayInfo(); int find(int count, int accts[], int id); double tempRate; double balance; BankAccount accts[10]; int nextID = 100; void main() { int choice; do{ choice = getChoice(); if( choice == 1 ) addBankAccount(); else if( choice == 2 ) withdrawAccount(); else if( choice == 3 ) depositAccount(); else if( choice == 4 ) updateAccounts(); else if( choice == 5 ) displayAccount(); else if( choice == 6 ) displayBalance(); else if( choice == 7 ) displayInfo(); if( choice > 8 || choice < 1 ) cout << "ERROR: Please enter valid choice (1-8)." << endl; } while( choice != 8 ); } //This function displays the calculation menu. int getChoice() { int c; cout << "----------------------\n"; cout << "1 - Add a new bank account.\n"; cout << "2 - Withdraw from a specific bank account.\n"; cout << "3 - Deposit to a specific account.\n"; cout << "4 - Update all accounts which will add a fixed interest rate to each account.\n"; cout << "5 - Display one specific bank accout.\n"; cout << "6 - Display the average balance for all of the accounts.\n"; cout << "7 - Display the current information for all accounts.\n"; cout << "8 - Terminate the program.\n"; cout << "----------------------\n"; cout << "Enter number of choice --> "; cin >> c; return c; } //This function adds a bank account for a new member. void addBankAccount() { int count = 0; string temp; cout << "Please enter first name."; cin >> temp; accts[count].setFirstName(temp); cout << "Please enter last name."; cin >> temp; accts[count].setLastName(temp); cout << "Please enter balance."; cin >> balance; accts[count].setBalance(balance); cout << "Please enter interest rate (decimal form)."; cin >> tempRate; accts[count].setInterestRate(tempRate); accts[count].setID(nextID); nextID = nextID + 1; count++; } // This function withdraws an amount from a specific account. void withdrawAccount() { double amt; int id; cout << "Enter ID number."; cin >> id; int slot = find(count, accts, id); cout << "Enter amount to withdraw."; cin >> amt; accts[slot].withdraw(amt); } //This function deposits an amount into a specific account. void depositAccount() { double amt; int id; cout << "Enter ID number."; cin >> id; int slot = find(count, accts, id); cout << "Enter amount to deposit."; cin >> amt; accts[slot].deposit(amt); } //This function updates all accounts using a fixed interest rate. void updateAccounts() { for (int i=0; i<count; i++) accts[i].update(); } //This function displays one bank account. void displayAccount() { int target; cout << "Enter account number."; cin >> target; accts[target].display(); } //This function displays the average balance of all accounts. void displayBalance() { } //This function displays the current information for all accounts. void displayInfo() { for (int i=0; i<count; i++) accts[i].display(); } int find(int count, int accts[], int id) { int index = 0; bool found = false; while ((!found) && (index < count)) if (id == accts[index]) found = true; else index++; if (found) return index; else return -1; }
That's because count is only a local variable in your addBankAccount function...As soon as the function ends count goes away...try declaring it at the beginning of main then pass it to your addBankAccount function...you will also have to pass count to your other functions that make use of the count variable...
•
•
Join Date: Feb 2007
Posts: 31
Reputation:
Solved Threads: 0
Ok...I have made those changes and now I have the two errors:
Here is my new code for the driver:
C++ Syntax (Toggle Plain Text)
error C2664: 'find' : cannot convert parameter 2 from 'BankAccount [10]' to 'int []' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast error C2664: 'find' : cannot convert parameter 2 from 'BankAccount [10]' to 'int []' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Here is my new code for the driver:
#include"BankAccount.h" int getChoice(); void addBankAccount(int); void withdrawAccount(int); void depositAccount(int); void updateAccounts(int); void displayAccount(); void displayBalance(); void displayInfo(int); int find(int count, int accts[], int id); double tempRate; double balance; BankAccount accts[10]; int nextID = 100; void main() { int count = 0; int choice; do{ choice = getChoice(); if( choice == 1 ) addBankAccount(count); else if( choice == 2 ) withdrawAccount(count); else if( choice == 3 ) depositAccount(count); else if( choice == 4 ) updateAccounts(count); else if( choice == 5 ) displayAccount(); else if( choice == 6 ) displayBalance(); else if( choice == 7 ) displayInfo(count); if( choice > 8 || choice < 1 ) cout << "ERROR: Please enter valid choice (1-8)." << endl; } while( choice != 8 ); } //This function displays the calculation menu. int getChoice() { int c; cout << "----------------------\n"; cout << "1 - Add a new bank account.\n"; cout << "2 - Withdraw from a specific bank account.\n"; cout << "3 - Deposit to a specific account.\n"; cout << "4 - Update all accounts which will add a fixed interest rate to each account.\n"; cout << "5 - Display one specific bank accout.\n"; cout << "6 - Display the average balance for all of the accounts.\n"; cout << "7 - Display the current information for all accounts.\n"; cout << "8 - Terminate the program.\n"; cout << "----------------------\n"; cout << "Enter number of choice --> "; cin >> c; return c; } //This function adds a bank account for a new member. void addBankAccount(int count) { string temp; cout << "Please enter first name."; cin >> temp; accts[count].setFirstName(temp); cout << "Please enter last name."; cin >> temp; accts[count].setLastName(temp); cout << "Please enter balance."; cin >> balance; accts[count].setBalance(balance); cout << "Please enter interest rate (decimal form)."; cin >> tempRate; accts[count].setInterestRate(tempRate); accts[count].setID(nextID); nextID = nextID + 1; count++; } // This function withdraws an amount from a specific account. void withdrawAccount(int count) { double amt; int id; cout << "Enter ID number."; cin >> id; int slot = find(count, accts, id); cout << "Enter amount to withdraw."; cin >> amt; accts[slot].withdraw(amt); } //This function deposits an amount into a specific account. void depositAccount(int count) { double amt; int id; cout << "Enter ID number."; cin >> id; int slot = find(count, accts, id); cout << "Enter amount to deposit."; cin >> amt; accts[slot].deposit(amt); } //This function updates all accounts using a fixed interest rate. void updateAccounts(int count) { for (int i=0; i<count; i++) accts[i].update(); } //This function displays one bank account. void displayAccount() { int target; cout << "Enter account number."; cin >> target; accts[target].display(); } //This function displays the average balance of all accounts. void displayBalance() { } //This function displays the current information for all accounts. void displayInfo(int count) { for (int i=0; i<count; i++) accts[i].display(); } int find(int count, int accts[], int id) { int index = 0; bool found = false; while ((!found) && (index < count)) if (id == accts[index]) found = true; else index++; if (found) return index; else return -1; }
That is because you have the wrong type in the prototype...you are passing acct which is of type BankAccount...therefore you need to change your prototype and header to something like this:
hope this helps...
C++ Syntax (Toggle Plain Text)
int find(int count, BankAccount accts[], int id);
Last edited by ft3ssgeek; Apr 13th, 2007 at 9:06 pm.
•
•
Join Date: Feb 2007
Posts: 31
Reputation:
Solved Threads: 0
Geez...I have no idea why it's still not working! I made those corrections and now I have 8 errors which all seem to relate to the find function. Is it not correct?:
DRIVER CODE:
C++ Syntax (Toggle Plain Text)
error C2784: 'bool std::operator ==(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const error C2784: 'bool std::operator ==(const _Elem *,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const _Elem *' from 'int' error C2784: 'bool std::operator ==(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'int' error C2784: 'bool std::operator ==(const std::allocator<_Ty> &,const std::allocator<_Other> &) throw()' : could not deduce template argument for 'const std::allocator<_Ty> &' from 'int' error C2784: 'bool std::operator ==(const std::istreambuf_iterator<_Elem,_Traits> &,const std::istreambuf_iterator<_Elem,_Traits> &)' : could not deduce template argument for 'const std::istreambuf_iterator<_Elem,_Traits> &' from 'int' error C2784: 'bool std::operator ==(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'int' error C2784: 'bool std::operator ==(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'int' error C2677: binary '==' : no global operator found which takes type 'BankAccount' (or there is no acceptable conversion)
DRIVER CODE:
#include"BankAccount.h" int getChoice(); void addBankAccount(int); void withdrawAccount(int); void depositAccount(int); void updateAccounts(int); void displayAccount(); void displayBalance(); void displayInfo(int); int find(int count, BankAccount accts[], int id); double tempRate; double balance; BankAccount accts[10]; int nextID = 100; void main() { int count = 0; int choice; do{ choice = getChoice(); if( choice == 1 ) addBankAccount(count); else if( choice == 2 ) withdrawAccount(count); else if( choice == 3 ) depositAccount(count); else if( choice == 4 ) updateAccounts(count); else if( choice == 5 ) displayAccount(); else if( choice == 6 ) displayBalance(); else if( choice == 7 ) displayInfo(count); if( choice > 8 || choice < 1 ) cout << "ERROR: Please enter valid choice (1-8)." << endl; } while( choice != 8 ); } //This function displays the calculation menu. int getChoice() { int c; cout << "----------------------\n"; cout << "1 - Add a new bank account.\n"; cout << "2 - Withdraw from a specific bank account.\n"; cout << "3 - Deposit to a specific account.\n"; cout << "4 - Update all accounts which will add a fixed interest rate to each account.\n"; cout << "5 - Display one specific bank accout.\n"; cout << "6 - Display the average balance for all of the accounts.\n"; cout << "7 - Display the current information for all accounts.\n"; cout << "8 - Terminate the program.\n"; cout << "----------------------\n"; cout << "Enter number of choice --> "; cin >> c; return c; } //This function adds a bank account for a new member. void addBankAccount(int count) { string temp; cout << "Please enter first name."; cin >> temp; accts[count].setFirstName(temp); cout << "Please enter last name."; cin >> temp; accts[count].setLastName(temp); cout << "Please enter balance."; cin >> balance; accts[count].setBalance(balance); cout << "Please enter interest rate (decimal form)."; cin >> tempRate; accts[count].setInterestRate(tempRate); accts[count].setID(nextID); nextID = nextID + 1; count++; } // This function withdraws an amount from a specific account. void withdrawAccount(int count) { double amt; int id; cout << "Enter ID number."; cin >> id; int slot = find(count, accts, id); cout << "Enter amount to withdraw."; cin >> amt; accts[slot].withdraw(amt); } //This function deposits an amount into a specific account. void depositAccount(int count) { double amt; int id; cout << "Enter ID number."; cin >> id; int slot = find(count, accts, id); cout << "Enter amount to deposit."; cin >> amt; accts[slot].deposit(amt); } //This function updates all accounts using a fixed interest rate. void updateAccounts(int count) { for (int i=0; i<count; i++) accts[i].update(); } //This function displays one bank account. void displayAccount() { int target; cout << "Enter account number."; cin >> target; accts[target].display(); } //This function displays the average balance of all accounts. void displayBalance() { } //This function displays the current information for all accounts. void displayInfo(int count) { for (int i=0; i<count; i++) accts[i].display(); } int find(int count, BankAccount accts[], int id) { int index = 0; bool found = false; while ((!found) && (index < count)) if (id == accts[index]) found = true; else index++; if (found) return index; else return -1; }
![]() |
Similar Threads
- Writing to an Access Database (Visual Basic 4 / 5 / 6)
- classes and mehtods needed (VB.NET)
- nvidia drivers (Window and Desktop Managers)
- standard SVGA drivers (Windows NT / 2000 / XP)
- New SB Drivers (PCI and Add-In Cards)
- Summer Classes (Geeks' Lounge)
- S3 savage 4 drivers (Monitors, Displays and Video Cards)
Other Threads in the C++ Forum
- Previous Thread: Print the parallel array index with the largest value?
- Next Thread: dev-c++ and libtiff
| Thread Tools | Search this Thread |
api application array arrays based binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game generator givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






