#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; };
#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; }
#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; }
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.
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 ==========
#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; };
#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; }
#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; }
#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; }
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
#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; }
int find(int count, BankAccount accts[], int id);
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)
#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; }
| DaniWeb Message | |
| Cancel Changes | |