google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.

Monday, February 23, 2015

Write Cpp program to represent bank account using member function

Define a class to represent a bank account which include following member
data member:-
1)name
2)Account number
3)type of account
4)bal.amt
member function:
a.to assign initial value
b.to deposit an account
c.to withdraw an account
d.to display name,account number and balance

#include<conio.h>
#include<iostream.h>
#include<string.h>
int w_amt;
class bank
{
public:int acc_no,bal;
char type[30],name[30];
public:void assign()
       {
       strcpy(name,"Vijay");
       acc_no=111;
       strcpy(type,"saving");
       bal=12000;
       }
       void deposit()
       {
       int amt;
       cout<<"\n Enter the amount which you want to deposit:-";
       cin>>amt;
       bal=bal+amt;
       }
       void withdraw()
       {
       cout<<"\n Enter how much money you want to withdraw";
       cin>>w_amt;
       }
       void display()
       {
       cout<<"\n Name:-"<<name
       <<"\n Account number:-"<<acc_no
       <<"\n Type of account:-"<<type
       <<"\n Balance amount:-"<<bal;
       }
};
int main()
{
bank b;
clrscr();
b.assign();
b.deposit();
b.withdraw();
if(w_amt>12000)
{
cout<<"You do not have that much balance try again";
}
else
b.bal=b.bal-w_amt;
b.display();
getch();
return 0;
}


==============================================

OUTPUT

Enter the amount which you want to deposit:-1200
Enter how much money you want to withdraw200
Name:-Vijay
Account number:-111
Type of account:-saving
Balance amount:-13000

Cpp program to create class telephone to search no name and city

Create a class telephone containing name,telephone number and city as
data members and write necessary member function for the following
-search the telephone number with given name.
-search the name with given telephone number
-search all customer in a given city.

#include<iostream.h>
#include<conio.h>
#include<string.h>
class telephone
{
public:char name[30],city[30];
       int tno;
public:void get()
       {
       cout<<"enter name:-";
       cin>>name;
       cout<<"\nenter telephone number";
       cin>>tno;
       cout<<"\nenter city name:-";
       cin>>city;
       }
       void search(int tnum)
       {
       cout<<"\ntelephone number of given customer:-"<<tnum;
       }
       void search(char n[30])
       {
       cout<<"\ncustomer name of the given number"<<n;
       }
       void search(char ct[30],int tnum)
       {
       cout<<"\n"<<ct<<"  "<<tnum;
       }
};
int main()
{
int i,tno,check;
char name[30],city[30];
telephone t[3];
clrscr();
for(i=0;i<3;i++)
t[i].get();
cout<<"\nsearch the telephone number of the given name";
cout<<"\nenter customer name:-";
cin>>name;
for(i=0;i<3;i++)
{
check=strcmp(name,t[i].name);
if(check==0)
t[i].search(t[i].tno);
}
cout<<"\n\n\nsearch the name of the given telephone number";
cout<<"\nenter telephone no.:-";
cin>>tno;
for(i=0;i<3;i++)
{
if(tno==t[i].tno)
t[i].search(t[i].name);
}
cout<<"\n\n\nsearch all customer in a given city";
cout<<"\nenter city name:-";
cin>>city;
for(i=0;i<3;i++)
{
check=strcmp(city,t[i].city);
if(check==0)
t[i].search(t[i].name,t[i].tno);
}
getch();
return 0;
}

अच्छे विचार करे विचार

  पहचान की नुमाईश, जरा कम करें... जहाँ भी "मैं" लिखा है, उसे "हम" करें... हमारी "इच्छाओं" से ज़्यादा "सुन...