- تاريخ التسجيل
- 14 سبتمبر 2012
- المشاركات
- 2,834
- المجموعة
- ذكر
- الدفعة الدراسية
- 2012
- الكلية
- كلية تقنية المعلومات
- التخصص
- CS - متقاعد
Write the definition of a class named BankAccount which includes data members and the prototype of the function members as described below:
The data members of the class BankAccount are: AccountNumber (long), Name (string), and Balance (float).
The class BankAccount contains the following member functions:
[*=left]Set and get functions for all the data members.
[*=left] Withdraw which is used to withdraw a certain amount X from the Account. It should check that the balance in the account is at least equal to X (i.e. X or more) before it allows the withdrawal and reduce the Balance by X.
[*=left]Deposit which is used to Deposit a certain amount Y into the Account. It should of course increase the Balance by Y.
[*=left]IsAccountEmpty which returns true if the Balance is less than or equal to zero.Otherwise it returns false.
[*=left]DisplayAccountDetails that prints (on the screen) all the information about the Account.
Write a main program to declare MyAccount as an object of type BankAccount.
[*=left]Call function Set to set MyAccount with your name and account number and 100BD in balance.
[*=left]Deposit 500BD in MyAccount
[*=left]Print your account details
[*=left]Withdraw 150BD from MyAccount
[*=left]print your account details again.
تفضلوا ..

كود:
#include <iostream>
#include <string>
using namespace std;
class BankAccount
{
long AccountNumber;
string Name;
float Balance ;
public:
void Set (long ,string ,float);
void get (long &,string &,float &);
void Withdraw (float);
void Deposit (float);
bool IsAccountEmpty ();
void DisplayAccountDetails ();
};
void BankAccount::Set (long a,string n,float b)
{
AccountNumber=a;
Name=n;
Balance=b;
}
void BankAccount::get (long &a,string &n,float &b)
{
a=AccountNumber;
n=Name=n;
b=Balance;
}
void BankAccount::Withdraw (float x)
{
if (x<=Balance)
Balance-=x;
}
void BankAccount::Deposit (float y)
{
Balance+=y;
}
bool BankAccount::IsAccountEmpty ()
{
if (Balance<=0)
return true;
else return false;
}
void BankAccount::DisplayAccountDetails ()
{
cout<<"AccountNumber : "<<AccountNumber<<endl;
cout<<"Name : "<<Name<<endl;
cout<<"Balance : "<<Balance<<endl;
}
void main()
{
long AccountNumber;
string Name;
float Balance ;
cout<<"Enter AccountNumber : ";
cin>>AccountNumber;
cout<<"Enter Name : ";
cin>>Name;
cout<<"Enter Balance : ";
cin>>Balance;
BankAccount MyAccount;
MyAccount.Set(AccountNumber,Name,Balance);
cout<<"\n\n <]--------------------------------------------------[>\n\n";
MyAccount.Deposit(500);
MyAccount.DisplayAccountDetails();
cout<<"\n\n <]==================================================[>\n\n";
MyAccount.Withdraw(150);
MyAccount.DisplayAccountDetails();
}






