"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Tuesday, March 23, 2010

Declare a class to represent fixed-deposit account of 10 customers with the following data members: Name of the depositor, Account Number, Time Period ( 1 or 3 or 5 yrs), Amount. The class also contains following member functions : (A) To initialise data members. , (B) For withdrawal of money (after half or the time period has passed ). , (C) To display the data members. Write a program to handle 10 account holders. Make necessary changes in the class definition - if required.


#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>

class account
{
private:

char name[20];
long acno;
int time;
double amount;

public :
void get_data( char nm[], long n, double am)
{
strcpy(name, nm);
acno = n;
time  = 1;
cout<< "\n Enter Duration ( for 3 yrs / 5 yrs) ..... \n else duration will be considered as 1 yr. ";
int t;
cin>> t;
if(t == 3 || t == 5)
  time = t;
amount = am;
}

void withdrw()
{
cout<< "\n Enter the time period,that has passed after creating new fixed-deposit A/c :"
int a;
cin>>a;
cout<< "\n The amount to be drawn :";
double d;
cin>>d;

if(a > = time/2)
   {
    if(d <= amount) 
         amount = amount - d;
     else
         cout<<"\n Balance is less in your account.Abort !";
    }
else
         cout<<"\n Money can not be withdrawn. For details contact helpline.";
}
void display()
{
cout<< "A/C No." << "\t" << "Name " << "\t\t" << "Amount" << "\n\n";
cout << acno << "\t" << name << "\t\t" << amount << "\n\n";
}

void display_time()
{
cout<< "\n A/c Duration = " << time << "yrs";
}

};

void main()
{
account customer[10];
char ch= 'y';

char nam[20];
long acn;
double amt;

/* Input 10 customer's details  */
for(int i = 0; i < 10 ; i++)
{
cout<< "\n Do you want to create a new account. Minimum duration is 1 yr":
cout<< "Enter (y /n) :";
cin >> ch;

if(tolower(ch) ! = 'y')
          { i--;
            continue;
          }
cout<< "\n Enter name :";
gets(nam) ;
cout<< "\n Enter A/c No. ";
cin>> acn;
cout<< "\n Enter amount ";
cin>> amt;

customer[i].get_data(nam, acn, amt);
}

/* Display 10 customer's details */
for(i = 0; i<10; i++)
{
customer[i].display();
}

/* withdraw money */
cout<< "\n************** Do you Withdraw Money ........\n";
cout<< "\n You can withdraw money only when, after creating your A/c ,half of the time period has passed . ";
cout<< "\n Enter A/c No.";
cin>>acn;
for(i = 0 ; i <10 ; i++)
{
if (acn == customer[i].acno)
      customer[i].withdrw();
}

 
/* Display 10 customer's details */
for(i = 0; i<10; i++)
{
customer[i].display();
}

getch();
}

No comments:

Post a Comment

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.