0% found this document useful (0 votes)
69 views7 pages

Programming Language Assignment #2: Structures

This document defines a C++ program that models bank accounts using structures. It defines a bank account structure with fields for customer name, bank name, branch, and balance. It includes functions to create accounts, credit and debit balances, check balances, and display account information. The main program uses a switch menu to allow users to select these options and stores account data in a file.

Uploaded by

Mehdi Naqvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views7 pages

Programming Language Assignment #2: Structures

This document defines a C++ program that models bank accounts using structures. It defines a bank account structure with fields for customer name, bank name, branch, and balance. It includes functions to create accounts, credit and debit balances, check balances, and display account information. The main program uses a switch menu to allow users to select these options and stores account data in a file.

Uploaded by

Mehdi Naqvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

PROGRAMMING LANGUAGE

ASSIGNMENT #2
Structures

Danyal Khan
160401030
EE-15-A
9th April 2019

Define a structure definition for a bank account with the following data members:
Customer Name, Bank Name, Branch of the bank, Balance
Add the following member functions to the structure:
Function components:
 Credit Process (To credit the balance with some amount)
 Debit Process (To debit the balance with some amount)
 Balance Process (to display balance)
 Create Account(to get name, bank name, branch name, amount to be deposited)
 Account information (to display name, bank, branch, balance)

Use a switch selector to create menu for the following processes:


1. selection for Create Account
2. selection for Credit Process
3. selection for Debit Process
4. selection for Balance Enquiry
5. selection for Account information
6. selection for Exit Menu

Use a do while loop to continuously running the program until user select option 6
which then stops execution of the program.
Data should be kept on file so that data it is readily be available for any transaction in
future.

#include<iostream>

#include<string.h>

#include<conio.h>

#include<fstream>

using namespace std;

struct bank{

string customer,bank,branch;

float balance;

void account_create(string,string,string,float)

{
cout<<"Enter Customer name : ";

cin.ignore();

getline(cin,customer);

cout<<"Enter bank name : ";

getline(cin,bank);

cout<<"Enter branch name : ";

getline(cin,branch);

cout<<"Enter initial balance : ";

cin>>balance;

void creditprocess()

int i;

cout<<"Enter the amount to be credit : ";

cin>>i;

balance=balance+i;

void debitprocess()

int i;

cout<<"Enter amount to be debited : ";

cin>>i;

if(i>balance)

cout<<"Transaction cannot be processed.";

getch();

else

balance=balance-i;

void inquiry()
{

cout<<"Account balance : "<<balance;

void accountinfo()

cout<<"Customer name : "<<customer<<endl;

cout<<"Bank name : "<<bank<<endl;

cout<<"Branch name : "<<branch<<endl;

cout<<"Balance : "<<balance;

};

int main()

bank x[100];

int k;

int y=0;

int z;

do{

system("CLS");

cout<<"Enter 1 to create new account"<<endl;

cout<<"Enter 2 to credit account"<<endl;

cout<<"Enter 3 to debit account"<<endl;

cout<<"Enter 4 for balnce inquiry"<<endl;

cout<<"Enter 5 for account info"<<endl;

cout<<"Enter 6 to exit"<<endl;

cin>>z;

switch(z)

case 1:

x[y].account_create(x[y].customer,x[y].bank,x[y].branch,x[y].balance);

y++;
break;

case 2:

cout<<"Total account : "<<y<<endl;

cout<<"Enter the account which is to be credited : ";

cin>>k;

if(k<=y)

x[k-1].creditprocess();

else

cout<<"Account does not exist";

getch();

break;

case 3:

cout<<"Total account : "<<y<<endl;

cout<<"Enter the account which is to be debited : ";

cin>>k;

if(k<=y)

x[k-1].debitprocess();

else

cout<<"Account does not exist";

getch();

break;

case 4:

cout<<"Total account : "<<y<<endl;

cout<<"Enter the account whose balance is to be inquired : ";

cin>>k;

if(k<=y)

x[k-1].inquiry();
else

cout<<"Account does not exist";

getch();

break;

case 5:

cout<<"Total account : "<<y<<endl;

cout<<"Enter the account whose info is required : ";

cin>>k;

if(k<=y)

x[k-1].accountinfo();

else

cout<<"Account does not exist";

getch();

break;

case 6:

ofstream file;

file.open("danyal.txt");

for(int i=0;i<y;i++)

file<<"Customer name : "<<x[i].customer<<endl;

file<<"Bank name : "<<x[i].bank<<endl;

file<<"Branch name : "<<x[i].branch<<endl;

file<<"Account Balance : "<<x[i].balance<<endl<<endl;

return 0;

while (1);

You might also like