Sunday, June 10, 2012

CS 110 COMPUTER PROGRAMMING LAB - Basic C Programs


//Program to Implement a Bank Account Class.

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

void menu();

class bank
{
private:

unsigned long int accno;
char name[20];
char type[15];
float balance;

public:
void insert();
void deposit();
void withdraw();
void view();
void exit1();

};

void bank::insert()
{
cout<<"\n Enter Account no:\t";
cin>>accno;
cout<<"\n Enter User Name:\t";
gets(name);
cout<<"\n Enter Account Type:\t";
gets(type);
cout<<"\n Enter Net Balance:\t";
cin>>balance;
menu();
}

void bank::view()
{
cout<<"\n Account no:\t"<<accno;
cout<<"\n User Name:\t";
puts(name);
cout<<"\n Account Type:\t";
puts(type);
cout<<"\n Net Amount:\t"<<balance;
menu();
}

void bank::deposit()
{
int deposit;
cout<<"\n Enter deposit amount";
cin>>deposit;
balance+= deposit;
menu;
}

void bank::withdraw()
{
int draw;
cout<<"\n Enter the amount to withdraw:\t";
cin>>draw;
if(draw>balance)
{
cout<<"\n Sorry! Your Balance is less than the draw amount.";
cout<<"\n Please change your draw amount.";
}
else
balance-=draw;
menu();
}

void bank::exit1()
{
char ch;
cout<<"\n Do you really want to exit (Y/N)?";
if(ch=='y'||ch=='Y')
{
cout<<"\nThank You For Using Bank Master";
getch();
exit(0);
}
else
menu();
}


void main()
{
clrscr();
menu();
getch();
}

void menu()
{
clrscr();
int n;
bank ac1;
cout<<"\n\t\t WELCOME TO BANK MASTER 2.0";
cout<<"\n 1.Insert Amount \t 2.Withdraw Amount \t 3.View Status \t 4.Exit ";
cout<<"\n\n Enter Your Choice:\t";
cin>>n;
switch(n)
{
case 1:ac1.insert();break;
case 2:ac1.withdraw();break;
case 3:ac1.view();break;
case 4:ac1.exit1();

default:{
cout<<"\n Invalid case...Please retry..";
menu();
}
}
}


0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More