1,105,290 Community Members

Bank Account C++ Program

Member Avatar
veiLrn
Newbie Poster
2 posts since Feb 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi, I'm new on this forum, but a friend directed me here to seek further assistance with a program I am trying to create. I have to create a program that can manage 10 bank accounts, one of which uses appropriate type definition to store the name, account number, balance of bank account, and so forth. It also has to be an array that records the details of the 10 bank accounts, in addition it also must have functions and procedures to update the bank accounts array.

The program has to allow the user to deposit or withdraw credit from accounts, and to be able to see the balance of a certain account. And if an account is set to zero, this would close the account. Other then that, I am also trying to make it so that if the user selects an incorrect choice, they must be told or offered a different option, if they deposit or withdraw, they have to enter a figure and the relevant account number, all of which gets displayed on screen.

I've created some code but have been busy with work and family quite alot recently which has forced me to neglect learning C++ (I have difficulty remembering topics and functions). At which point I gave it to my friend to try and assist me with the issue, but has in turn given me code that doesn't work with the program I use to create C++ programs with (Net beans). I would very much appreciate any other examples of bank account programs just so I can see exactly how such a program should operate and how it should work to perfect my own.

And yes, the program in question is just for personal use only, just to educate myself more on C++ .

Any assistance would be appreciated, thanks.

W.S.

:)

#include<iostream.h>
#include<string.h>
#include<process.h>

class details
{
	public:
		char *name;
		int age;
		char branch[50];
		char city[40];
		void getdetails()
		{
			name=new char[20];
			cout<<endl<<endl<<"**********Customer Details*********** "<<endl;
			cout<<"          -------- -------            "<<endl;
			cout<<"Enter Name: ";
			cin>>name;
			cout<<"Enter Age: ";
			cin>>age;
			cout<<"Enter Branch: ";
			cin>>branch;
			cout<<"Enter City: ";
			cin>>city;
			cout<<"______________________________________"<<endl<<endl;
		}
};

class bank
{

	public:
		static int accnumber;
		long balance;
		details d;
		void getdata();
		bank transfermoney(bank);
		void deposit();
		void withdrawal();
		void newaccount();
		void viewaccdetails();
};
int bank::accno=0;

void main()
{
	char ch;
	static int i=0;
	bank *a[10];
	int x,amt,k,j;
	clrscr();
	do
	{
	cout<<endl<<endl<<"************MENU************"<<endl;
	cout<<"            ----            "<<endl;
	cout<<"1.Create new account\n2.Deposit\n3.Withdraw\n4.Transfer credits\n5.View account details\n\n";
	cout<<"Enter choice no.: ";
	cin>>x;
	switch(x)
	{
		case 1:
		{
			i++;
			a[i]=new bank;
			a[i]->newaccount();
			break;
		}
		case 2:
		{
			cout<<"Enter account no.: ";
			cin>>k;
			a[k]->deposit();
			break;
		}
		case 3:
		{
			cout<<"Enter account no.: ";
			cin>>k;
			a[k]->withdrawal();
			break;
		}
		case 4:
		{
			cout<<"Enter the source and destination account nos.: ";
			cin>>k>>j;
			*a[j]=a[k]->transfermoney(*a[j]);
			break;
		}
		case 5:
		{
			cout<<"Enter account no.: ";
			cin>>k;
			a[k]->viewaccdetails();
			break;
		}
	}cout<<"\nDo you wish to continue[Press 'Y' to continue or 'N' to exit menu]: ";
	cin>>ch;
}while(ch=='y'||ch=='Y');

}

bank bank::transfermoney(bank a)
{
	long amt;
	cout<<"Enter amount to be transferred: ";
	cin>>amt;
	a.balance=a.balance+amt;
	if(balance<amt)
	{
		cout<<"\nInsufficient balance! Operation Cannot be performed!"<<endl<<endl;
	}
	else
	{
		balance=balance-amt;
	}
	return a;
}
void bank::withdrawal()
{
	long amtdrawn;
	cout<<"Enter amount to be withdrawn: ";
	cin>>amtdrawn;
	if(balance<amtdrawn)
		cout<<"\nInsufficient balance! Operation Cannot be performed!"<<endl<<endl;
	else
		balance=balance-amtdrawn;

}
void bank::deposit()
{
	long dep;
	cout<<"Enter amount to be deposited: ";
	cin>>dep;
	balance+=dep;
}
void bank::newaccount()
{
	accno++;
	d.getdetails();
	balance=0;
}
void bank::viewaccdetails()
{
	cout<<endl<<endl<<"*********ASSIGNMENT BANK ACCOUNT DETAILS*********"<<endl;
	cout<<"         --- ---- ------- -------         "<<endl;
	cout<<"Account no.: "<<accno<<endl;
	cout<<"Name: "<<d.name<<endl;
	cout<<"Branch: "<<d.branch<<endl;
	cout<<"City: "<<d.city<<endl;
	cout<<"Current Balance: "<<balance<<endl;
	cout<<"_________________________________________"<<endl;
}
Member Avatar
jkoske
Newbie Poster
23 posts since Feb 2011
Reputation Points: -1 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

hmm that sounds more like a class assignment... anyways, why doesn't the code work on netbeans? are you getting a compiler error?

Member Avatar
Narue
Bad Cop
12,139 posts since Sep 2004
Reputation Points: 5,693 [?]
Q&As Helped to Solve: 1,537 [?]
Skill Endorsements: 80 [?]
Team Colleague
 
0
 

I see several problems, but the most likely one you're encountering is this:

int bank::accno=0;

accno doesn't exist in the class. The only static data member is called accnumber, so I can only assume the mixup is a brain fart. Make sure all identifiers match up and it should work better.

Member Avatar
ninjatalon
Junior Poster in Training
84 posts since Feb 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 5 [?]
Skill Endorsements: 0 [?]
 
0
 

You're are also calling accno++ inside your newaccount() function.

You're including string.h but not using it string types.

I believe (correct me if i'm wrong) static variables will be the same value for all instances of a class.

It's not a good habit making all your variables public in your class. You should've used structures.

Member Avatar
Narue
Bad Cop
12,139 posts since Sep 2004
Reputation Points: 5,693 [?]
Q&As Helped to Solve: 1,537 [?]
Skill Endorsements: 80 [?]
Team Colleague
 
0
 

You're are also calling accno++ inside your newaccount() function.

What's wrong with that?

You're including string.h but not using it string types.

Technically not a problem.

I believe (correct me if i'm wrong) static variables will be the same value for all instances of a class.

Static data members are shared between objects. While I would question the naming of acctno, it's not being used incorrectly in the posted code.

It's not a good habit making all your variables public in your class. You should've used structures.

In which case all of the data members would still be public. That improves matters how?

Member Avatar
ninjatalon
Junior Poster in Training
84 posts since Feb 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 5 [?]
Skill Endorsements: 0 [?]
 
0
 

What's wrong with that?


Technically not a problem.


Static data members are shared between objects. While I would question the naming of acctno, it's not being used incorrectly in the posted code.


In which case all of the data members would still be public. That improves matters how?

Problem with accno++ is that there is no such accno variable in class, there is a accnumber though. (accno is being called in viewaccdetails also)

Including a header that is not needed is just bad practice. Of course there's no error but still bad practice.

Static data members only keeps one copy of data, so if the last value inputed is 5 then by default all will be 5.

So when the user runs viewaccdetails() every account number will have the same value.

Member Avatar
veiLrn
Newbie Poster
2 posts since Feb 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi there! Sorry for the late reply.

I included the accno into the public class;

class details
{
	public:
		char *name;
		int age;
                int accno;
                char branch[50];
		char city[40];
		void getdetails()
		{
			name=new char[20];
			cout<<endl<<endl<<"**********Customer Details*********** "<<endl;
			cout<<"          -------- -------            "<<endl;
			cout<<"Enter Name: ";
			cin>>name;
			cout<<"Enter Age: ";
			cin>>age;
			cout<<"Enter Account Number: ";
			cin>>accno;
                        cout<<"Enter Branch: ";
			cin>>branch;
			cout<<"Enter City: ";
			cin>>city;
			cout<<"______________________________________"<<endl<<endl;
		}
};

Yeah, there are quite a few numerous errors on it at the moment and it's becoming mind boggling for me to understand, since I'm rather novice when it comes to C++ coding, I'm still learning and to be honest I think my friend included code that is too advance for me to understand, where as I simply wanted a straight forward code to use just so I can get the program to run, then add more advance features later.

At this stage, I think it would be necessary for me to just start from scratch, and have some sort of guide line I can follow, and understand. He gave me this website too; http://www.exforsys.com/tutorials/c-plus-plus.html but... I dont even know where to start, let alone know what to do at this stage. Overall, Im having a rather stressful experience, and because of that, Im most probably over looking things. Like I said before, any assistance would be greatly appreciated.

C++ Dummie.

:)


Edit: I will be going to sleep for now, since my mind is completely melted by all of this, hopefully there will be some really useful and handy replies tommorow, again, much appreciated in advance! :)

Member Avatar
HASHMI007
Junior Poster in Training
60 posts since Feb 2011
Reputation Points: -24 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
-3
 

Ey, i nead your Whole program if dnt mind ap poast kr skty o.i nead some information
i m very thnkxfull...........

Member Avatar
piyush3dxyz
Newbie Poster
6 posts since Apr 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

hey i got it....The error is easy to correct in this program....in 5 minutes i correct all the errors..
And thax to coder for sharing this program Piyush3dxyz@gmail.com

#include<iostream.h>
#include<string.h>
#include<process.h>

class details
{
    public:
        char *name;
        int age;
                int accno;
                char branch[50];
        char city[40];
        void getdetails()
        {
            name=new char[20];
            cout<<endl<<endl<<"**********Customer Details*********** "<<endl;
            cout<<"          -------- -------            "<<endl;
            cout<<"Enter Name: ";
            cin>>name;
            cout<<"Enter Age: ";
            cin>>age;
            cout<<"Enter Account Number: ";
            cin>>accno;
                        cout<<"Enter Branch: ";
            cin>>branch;
            cout<<"Enter City: ";
            cin>>city;
            cout<<"______________________________________"<<endl<<endl;
        }
};

class bank
{

    public:
        static int accnumber;
        long balance;
        details d;
        void getdata();
        bank transfermoney(bank);
        void deposit();
        void withdrawal();
        void newaccount();
        void viewaccdetails();
};
int bank::accnumber=0;

int main()
{
    char ch;
    static int i=0;
    bank *a[10];
    int x,amt,k,j;

    do
    {
    cout<<endl<<endl<<"************MENU************"<<endl;
    cout<<"            ----            "<<endl;
    cout<<"1.Create new account\n2.Deposit\n3.Withdraw\n4.Transfer credits\n5.View account details\n\n";
    cout<<"Enter choice no.: ";
    cin>>x;
    switch(x)
    {
        case 1:
        {
            i++;
            a[i]=new bank;
            a[i]->newaccount();
            break;
        }
        case 2:
        {
            cout<<"Enter account no.: ";
            cin>>k;
            a[k]->deposit();
            break;
        }
        case 3:
        {
            cout<<"Enter account no.: ";
            cin>>k;
            a[k]->withdrawal();
            break;
        }
        case 4:
        {
            cout<<"Enter the source and destination account nos.: ";
            cin>>k>>j;
            *a[j]=a[k]->transfermoney(*a[j]);
            break;
        }
        case 5:
        {
            cout<<"Enter account no.: ";
            cin>>k;
            a[k]->viewaccdetails();
            break;
        }
    }cout<<"\nDo you wish to continue[Press 'Y' to continue or 'N' to exit menu]: ";
    cin>>ch;
}while(ch=='y'||ch=='Y');

}

bank bank::transfermoney(bank a)
{
    long amt;
    cout<<"Enter amount to be transferred: ";
    cin>>amt;
    a.balance=a.balance+amt;
    if(balance<amt)
    {
        cout<<"\nInsufficient balance! Operation Cannot be performed!"<<endl<<endl;
    }
    else
    {
        balance=balance-amt;
    }
    return a;
}
void bank::withdrawal()
{
    int amtdrawn;
    cout<<"Enter amount to be withdrawn: ";
    cin>>amtdrawn;
    if(balance<=amtdrawn)
        cout<<"\nInsufficient balance! Operation Cannot be performed!"<<endl<<endl;
    else
        balance=balance-amtdrawn;

}
void bank::deposit()
{
    int dep;
    cout<<"Enter amount to be deposited: ";
    cin>>dep;
    balance+=dep;
}
void bank::newaccount()
{
    accnumber++;
    d.getdetails();
    balance=0;
}
void bank::viewaccdetails()
{
    cout<<endl<<endl<<"*********ASSIGNMENT BANK ACCOUNT DETAILS*********"<<endl;
    cout<<"         --- ---- ------- -------         "<<endl;
    cout<<"Account no.: "<<accnumber<<endl;
    cout<<"Name: "<<d.name<<endl;
    cout<<"Branch: "<<d.branch<<endl;
    cout<<"City: "<<d.city<<endl;
    cout<<"Current Balance: "<<balance<<endl;
    cout<<"_________________________________________"<<endl;
}
Member Avatar
HASHMI007
Junior Poster in Training
60 posts since Feb 2011
Reputation Points: -24 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

I do Same program by mine own logic andy how thnkxx

Member Avatar
HASHMI007
Junior Poster in Training
60 posts since Feb 2011
Reputation Points: -24 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

The was the post when i was in 1st semeter of Programmer I m completely Done My degree Now I m Software Engineer and I m CEO HITC ... Dude Programming Is Easy if you By self and Its difficult when copy cat some other Person program...

Member Avatar
reminisce.josh
Newbie Poster
1 post since Jan 2014
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi guys i need some assistance i know how to write to/add, read in/retrieve, modify/update and delete/erase data from files but in Text mode. I need an example code of how to perform those four operations in Binary mode.
Thanks in advance.

You
Post:
Start New Discussion
View similar articles that have also been tagged: