Thread: Bank_project

  1. #1
    Registered User thriller500's Avatar
    Join Date
    Oct 2011
    Posts
    25

    Bank_project

    header_cpp_file :
    Code:
    #include "bank_class.h"
    #include<iostream>
    #include<string>
    using namespace std;
    bank_class::bank_class()
    {
        balance=0;
    
    
    }
    void bank_class::deposit(int j)
    {
    
    
     balance=balance+j;
    
    
    }
    int bank_class::withdraw(int k)
    {   if(k>balance)
        {
            cout<<"Insufficient funds"<<endl;
            return 0;
        }
        balance=balance-k;
        return 0;
    }
    void bank_class::getName(string x)
    {
        name=x;
    }
    void bank_class::assign_acc_no(int l)
    {
        acc_number=l;
    
    
    }
    void bank_class::show()
    {
        cout<<"name : "<<name<<endl;
        cout<<"acc_number : "<<acc_number<<endl;
        cout<<"balance : "<<balance<<endl;
    
    
    }
    header_file:

    Code:
    #ifndef BANK_CLASS_H
    #define BANK_CLASS_H
    #include<iostream>
    #include<string>
    using namespace std;
    
    
    class bank_class
    {
        public:
            bank_class();
            void deposit(int);
            int withdraw(int);
            void getName(
    string);
            void assign_acc_no(int);
            void show();
        private:
            string name;
            int acc_number;
            int balance;
    
    
    };
    
    
    #endif // BANK_CLASS_H


    main_cpp :


    Code:
    #include<iostream>
    #include<string>
    #include "bank_class.h"
    using namespace std;
    int main()
    {   int i=1,j=0,l=0;
        string acc_name;
        bank_class x[100];
       while(i==1)
        {
        cout<<"Do you want to create a Account then \n1)press 1\nIF NOT\n press 0"<<endl;
        cin>>i;
        if(i==0)
        {
            cout<<"Bye";
            return 0;
        }
        if(i==1)
        {
    
    
            cout<<"Please enter your name"<<endl;
            cin>>acc_name;
            x[j].getName(acc_name);
            x[j].assign_acc_no(j);
    
    
            j++;
            x[j].show();
        }
        x[0].show();
    }
    }


    Code:
    x[j].show();
    name is not being displayed....

    Code:
    x[j].assign_acc_no(j);
    void bank_class::assign_acc_no(int l)
    {
        acc_number=l;
    
    
    }
    After first iteration,its giving junk values........
    Attached Images Attached Images Bank_project-screenshot-2012-06-08-15-52-22-jpg 

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    You increment j first and then call display. You're trying to display a different bank_account than what you just filled.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User thriller500's Avatar
    Join Date
    Oct 2011
    Posts
    25
    Quote Originally Posted by CornedBee View Post
    You increment j first and then call display. You're trying to display a different bank_account than what you just filled.
    thanks

Popular pages Recent additions subscribe to a feed