Tuesday, 27 November 2012

bank program using classes


#include<iostream>
using namespace std;
#include<conio.h>
#include<string.h>
class bankaccount
{
char m_name[20];
int m_accno;
char m_type[10];
double m_balance;
char m_pswd[10];
public:
void initial_val()
{
cout<<"\n\nName of the depositer: ";
cin>>m_name;
cout<<"\nAccount No. : ";
cin>>m_accno;
cout<<"\nType of the account (saving/current): ";
cin>>m_type;
cout<<"\nBalance amount in the account : Rs ";
cin>>m_balance;
cout<<"\nPassword: ";
cin>>m_pswd;
}
void deposit()
{
double m;
cout<<"\nAmount to be deposited: Rs ";
cin>>m;
m_balance=m_balance+m;
cout<<"\nYour current balance is: Rs "<<m_balance;
cout<<"\n\n";
}
void withdraw()
{
double n;
char a[10];
cout<<"\nEnter password: ";
cin>>a;
if(strcmp(m_pswd,a)==0)
{
cout<<"\nAmount to be withdrawn: Rs ";
cin>>n;
if(m_balance<=n)
{
cout<<"Balance amount is less ==> amount cannot be withdrawn\n";
}
else
{
m_balance=m_balance-n;
cout<<"\nYour current balance is: Rs "<<m_balance;
cout<<"\n\n";
}
}
else
{
cout<<"\nINVALID PASSWORD !!!\n";
}
}
void display()
{
char b[10];
cout<<"\nEnter password: ";
cin>>b;
if(strcmp(m_pswd,b)==0)
{
cout<<"\n\n\nName of the depositer: "<<m_name;
cout<<"\n\nBalance amount in the account : "<<m_balance;
cout<<"\n\n";
}
else
{
cout<<"\nINVALID PASSWORD !!!\n";
}
}
};

void main()
{
bankaccount b;
int i,c;
cout<<"\n* This is your bank account *\n";
cout<<"\n Enter details";
b.initial_val();
while(1)
{
cout<<"\n1. Deposit\n"<<"2.Withdraw\n"<<"3.Display\n"<<"4. Exit\n";
cout<<"\nEnter your choice: ";
cin>>c;
switch(c)
{
case 1:b.deposit();
break;
case 2:b.withdraw();
break;
case 3:b.display();
break;
case 4:exit(0);
default:cout<<"\n**INVALID**";
break;
}
}
getch();
}

Output:
 Enter details
Name of the depositer: GAUTAM
Account No. : 4546
Type of the account (saving/current): saving
Balance amount in the account : Rs 60000
Password: xyz
1. Deposit
2.Withdraw
3.Display
4. Exit
Enter your choice: 1
Amount to be deposited: Rs 8000
Your current balance is: Rs 68000
1. Deposit
2.Withdraw
3.Display
4. Exit

Enter your choice: 2
Enter password: xyz
Amount to be withdrawn: Rs 56000
Your current balance is: Rs 12000
1. Deposit
2.Withdraw
3.Display
4. Exit
Enter your choice:

2 comments:

  1. #include
    #include
    #include

    #define MAX 5

    int top = -1;
    int stack_arr[MAX];


    void push()
    {
    int pushed_item;
    if(top == (MAX-1))
    printf("Stack Overflow\n");
    else
    {
    printf("Enter the item to be pushed in stack : ");
    scanf("%d",&pushed_item);
    top=top+1;
    stack_arr[top] = pushed_item;
    }
    }/*End of push()*/

    void pop()
    {
    if(top == -1)
    printf("Stack Underflow\n");
    else
    {
    printf("Popped element is : %d\n",stack_arr[top]);
    top=top-1;
    }
    }/*End of pop()*/

    void display()
    {
    int i;
    if(top == -1)
    printf("Stack is empty\n");
    else
    {
    printf("Stack elements :\n");
    for(i = top; i >=0; i--)
    printf("%d\n", stack_arr[i] );
    }
    }/*End of display()*/

    void main()
    {
    int choice;
    while(1)
    {
    printf("1.Push\n");
    printf("2.Pop\n");
    printf("3.Display\n");
    printf("4.Quit\n");
    printf("Enter your choice : ");
    scanf("%d",&choice);
    switch(choice)
    {
    case 1 :
    push();
    break;
    case 2:
    pop();
    break;
    case 3:
    display();
    break;
    case 4:

    default:
    printf("Wrong choice\n");
    }/*End of switch*/
    }/*End of while*/
    }/*End of main()*/

    ReplyDelete
  2. FILE
    Aim: Write a program to find the average of data in a file and print to another file.
    Algorithm
    1. Declare two pointers of structure FILE for input and output files
    2. Use fopen() to read contents of a input file using read “r” mode
    3. Use fopen() to write results to output file using write “w” mode
    4. Use fscanf() to read data from the input file
    5. Find the average of numbers in input file
    6. Use fprintf() to write the results to output file
    7. Use fclose() to close both FILE pointers
    FUNCTION
    Aim: Write a function to compute sum of integers.
    Input two numbers that represent a range of integers and display the sum of the integers that lies in that range.
    Algorithm
    1. Prompt user and read the first number
    2. Prompt user and read the second number
    3. Calculate the sum of integers in the range smaller...larger by adding in turn each integer in that range
    4. Display the sum
    5. Find the average of data in a file and print to another file.



    #include
    #include
    void main()
    {
    FILE *f1,*f2;
    int s,sum=0,i;
    float avg=0,n;
    printf("How many numbers u want?");
    scanf("%f",&n);
    f1=fopen("nos.txt","w");
    while(i<n)
    {
    printf("Enter %d number",i+1);
    scanf("%d",&s);
    fprintf(f1,"%d \n",s);
    }
    fclose(f1);
    f1=fopen("nos.txt","r");
    f2=fopen("avg.txt","w");
    for(sum=0,i=0;i<n && !feof(f1);i++)
    {
    fscanf(f1,"%d",&s);
    sum=sum+s;
    }
    avg=sum/n;
    fprintf(f2,"%f",avg);
    fclose(f1);
    fclose(f2);
    f2=fopen("avg.txt","r");
    fscanf(f2,"%f",&avg);
    printf("The average of data is %6.2f",avg);
    fclose(f2);
    getch();
    }

    ReplyDelete