4 Replies - 305 Views - Last Post: 08 August 2012 - 06:00 PM Rate Topic: -----

#1 ducemac  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 08-August 12

Bank class and program

Posted 08 August 2012 - 03:53 PM

Every time i try to make a deposit or withdrawal after creating an account, the account summary still has the original balance that i created the account with. For instance I would create and account and put in all the basic info and start the account off with 100 dollars. Then i would go back to the menu and choose create a transaction to make a deposit or withdrawal. Then when i choose account summary it is still the original balance. Anyone know what im doing wrong? I have the header file and main program below











#include <iostream>
#include <string>
#include "bankAccount.h"
bankAccount createAccount();
void MakeTransaction(bankAccount);
void AccountSummary(bankAccount);
using namespace std;
int main(){

  int choice;
  bankAccount User;
  //count=0;

  do{
    //Bank Menu
    cout<< " Bank Account Menu\n\n";
    cout<< "1.Create a new Account\n";
    cout<< "2.Make transaction\n";
    cout<< "3.Account Summary\n";
    cout<< "4.Quit Program\n\n";
    cout<< "Enter your choice: ";
    cin>>choice;

    switch (choice)
      {
      case 1: User=createAccount();
    break;
      case 2: MakeTransaction(User);
    break;
      case 3: AccountSummary(User);
    break;
    //case 4: exit(1);
    //break;
      }

  }while(choice!=4);


  return 0;
}

bankAccount createAccount(){
  string name,address,dob,phonenum;
  int input,amount;


  cout<<"What is the name of the new customer?"<<endl;
  cin.ignore();
  getline(cin,name);

  cout<<"What is the address of the new customer?"<<endl;
  //cin>>address;
  getline(cin,address);

  cout<<"What is the customers date of birth?"<<endl;
  //cin>>dob;
  getline(cin,dob);

  cout<<"What is the customers phone number?"<<endl;
  //cin>>phonenum;
  getline(cin,phonenum);



  bankAccount user(name,address,dob,phonenum);

  cout<<"Which kind of account does the customer want to create(type in 1-3)?"<<endl;

  cout<< "1.Checking\n";
  cout<< "2.Savings\n";
  cout<< "3.CD";
  cin>>input;

  switch(input){
  case 1: cout<<"How much money would you like to deposit in order to create account?";
    cin>>amount;
    user.setBalance("checkings",amount);
    break;
  case 2:cout<<"How much money would you like to deposit in order to create account?";
    cin>>amount;
    user.setBalance("savings",amount);
    break;
  case 3: cout<<"How much money would you like to deposit in order to create account?";
    cin>>amount;
    user.setBalance("CD",amount);
    break;
  }

  return user;

}

void MakeTransaction(bankAccount user){
  string account,transaction;
  double amount;
  cout<<"Which account would you like to make a transaction in (checkings,savings or CD)?";
  cin>>account;

  cout<<"What transaction would you like to make (deposit or withdrawal)?";
  cin>>transaction;

  cout<<"For how much money would the transaction be?";
  cin>>amount;


  if (account=="checkings")
    user.editCheckings(transaction,amount);

  if (account=="savings")
    user.editSavings(transaction,amount);

  if (account=="CD")
    user.editCD(transaction,amount);
}
void AccountSummary(bankAccount user){
  user.accountSummary();
}








#ifndef BANKACCOUNT_H
#define BANKACCOUNT_H
#include <string>  
using namespace std;

class bankAccount{
         private:
              string name;
              string address;
              string birthdate;
              string phone_number;
              double checkingsBAL;
              double savingsBAL;
              double cdBAL;
              
              
         public: 
              bankAccount(){checkingsBAL=-1.0;savingsBAL=-1.0;cdBAL=-1.0;}  
              bankAccount(string,string,string,string);
              void setBalance (string,double);
              void editCheckings(string,double);
              void editSavings(string,double);
              void editCD(string,double);
              double getBalance(string);
              void accountSummary();
              
};          
             
bankAccount::bankAccount(string NAME, string ADDRESS,string DOB,string PHONE_NUMBER){
     name=NAME;
     address=ADDRESS;
     birthdate=DOB;
     phone_number=PHONE_NUMBER;
     checkingsBAL=-1.0;
     savingsBAL=-1.0;
     cdBAL=-1.0;
     }
void bankAccount::setBalance(string accounttype, double accountBAL){
     if (accounttype=="checkings")
        checkingsBAL=accountBAL; 
     
     if (accounttype=="savings")
        savingsBAL=accountBAL;
     
     if (accounttype=="CD")
        cdBAL=accountBAL;
     }
void bankAccount:: editCheckings(string transaction,double transAmount){
     if (transaction=="deposit")
        checkingsBAL=checkingsBAL+transAmount;
     
     if (transaction=="withdraw")
        checkingsBAL=checkingsBAL+transAmount;
     }
void bankAccount:: editSavings(string transaction,double transAmount){
     if (transaction=="deposit")
        savingsBAL=(savingsBAL+transAmount)*1.05;
     
     if (transaction=="withdraw")
        savingsBAL=savingsBAL+transAmount;
     }
void bankAccount:: editCD(string transaction,double transAmount){
     if (transaction=="deposit")
        cdBAL=(cdBAL+transAmount)*1.1;
     
     if (transaction=="withdraw")
        cdBAL=cdBAL+transAmount;
     }
double bankAccount:: getBalance(string accounttype){
       if (accounttype=="checkings")
         return checkingsBAL;
       
       if (accounttype=="savings")
          return savingsBAL;
       
       if (accounttype=="CD")
          return cdBAL;
}
void bankAccount::accountSummary(){
     cout<<"Here is the Account Summary"<<endl;
     cout<<"NAME: "<<name<<endl;
     cout<<"ADDRESS: "<<address<<endl;
     cout<<"BIRTHDATE: "<<birthdate<<endl;
     cout<<"PHONE NUMBER: "<<phone_number<<endl;
     if (checkingsBAL>=0)
        cout<<"Checking Account Balance: "<<checkingsBAL<<endl;
     else 
          cout<<"There is no checking account for this person"<<endl;
     if (savingsBAL>=0)
        cout<<"Savings Account Balance: "<<savingsBAL<<endl;
     else 
          cout<<"There is no checking account for this person"<<endl;
     if (cdBAL>=0)
        cout<<"CD Account Balance: "<<cdBAL<<endl;
     else 
          cout<<"There is no CD account for this person"<<endl;
}    
     
     
      
# endif
     

     



Is This A Good Question/Topic? 0
  • +

Replies To: Bank class and program

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5669
  • View blog
  • Posts: 22,517
  • Joined: 23-August 08

Re: Bank class and program

Posted 08 August 2012 - 03:59 PM

Reading the function tutorials in my signature might be helpful. Pay particular attention to pass-by-value v. pass-by-reference.
Was This Post Helpful? 1
  • +
  • -

#3 ducemac  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 08-August 12

Re: Bank class and program

Posted 08 August 2012 - 04:31 PM

so u think i should use a reference parameter or a pointer ?
Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is online

  • member icon

Reputation: 3049
  • View blog
  • Posts: 9,289
  • Joined: 25-December 09

Re: Bank class and program

Posted 08 August 2012 - 04:56 PM

That is really a decision you must make. Some people prefer passing using C++ references instead of pointers but it really comes down to a personal decision. I myself prefer to either pass by value, for POD types or pass by reference, const reference when ever possible.

Also note the language used in this board is English, not hodgepodge, please learn to use proper sentences and capitalization. This will make reading your questions much easier.


Jim

This post has been edited by jimblumberg: 08 August 2012 - 04:58 PM

Was This Post Helpful? 1
  • +
  • -

#5 ducemac  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 08-August 12

Re: Bank class and program

Posted 08 August 2012 - 06:00 PM

Thanks guys. I used a reference parameter to pass the object on one of my functions and its working now.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1