Member Avatar for HASHMI007
//plz run .an accrued .Processor fault error.plz help me 

/*

Bank taransection Program.cpp : Defines the entry point for the console application.
*/

#include "stdafx.h"
#include<iostream>
#include<string.h>
#include<string>
#include<process.h>
#include<conio.h>

using namespace std;
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:
	double  accno;
		static double  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;
	system("cls");
	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;
			b.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;
}

And did you have a question to go with your code?

Does it bake cookies or cakes?

Sorry, I guess that was it in the first comment.

There are a couple obvious problems in your "case 1" for creating a new account. You don't check the value of i, so you'll get an error if you try to add an account if i >= 10. Also, you increment the value of i first, so you have an account a[0] which you never use.

In your newaccount() method, you increment the instance member accno (which may or may not be initialized to zero -- if it is, then your accno will always be 1, otherwise it will be some arbitrary value), and ignore your static class-member (which I think you intended to provide successive new account numbers).

Your transfermoney() method also has problems -- first of all, you add the money to the destination account before you determine whether the source account has sufficient funds. Also, instead of copying the destination account into the method, and then copying back via assignment, consider passing a pointer to the destination account, and modifying it directly as needed in the method.

In case 5, where did the "b" variable come from?

Member Avatar for HASHMI007

ok thnkx .. i try...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.