I want to write cpp program for bank operations using singly linked lists
#include<iostream>
using namespace std;
struct node
{
int cust_id;
int acc_id;
string name;
float bal;
struct node *next;
};
struct day
{
int date;
int mon;
int year;
};
struct trans
{
int acc_id;
string trans_type;
float amt;
struct day day;
struct trans *next;
};
struct list
{
int count;
struct node *head;
};
struct list1
{
int count;
struct trans *head;
};
void cre_acc (struct list **list,struct list1 ** list1)
{
*list=(struct list *)malloc(sizeof(struct list));
*list1=(struct list1 *)malloc(sizeof(struct list1));
struct node *node=(struct node*)malloc(sizeof(struct node));
struct trans *trans=(struct trans*)malloc(sizeof(struct trans));
struct day *day;
int cust_i,acc_i;
float ba;
string nam;
cout<<"enter the details of cust";
cin>>cust_i>>acc_i>>nam>>ba;
(*list)->count=1;
(*list)->head=node;
node->cust_id=cust_i;
(node)->acc_id=acc_i;
(node)->bal=ba;
(node)->name=nam;
(*list1)->count=0;
(*list1)->head=trans;
(trans)->acc_id=acc_i;
(trans)->trans_type="NULL";
(trans)->amt=0;
int dat,mo,ye;
cout<<"enter date ,month and year";
cin>>dat>>mo>>ye;
trans->day.date=dat;
trans->day.mon=mo;
trans->day.year=ye;
cout<<"account created";
}
void deposit(struct list *list,struct list1 *list1)
{
if(list==NULL)
{
cout<<"list doesn't exists";
}
else
{
struct trans *trans=(struct trans*)malloc(sizeof(struct trans));
struct day *day;
struct node *node;
int am,dat,mo,yr;
cout<<"enter amount to deposit and time";
cin>>am>>dat>>mo>>yr;
(node)->bal=(node)->bal+am;
(trans)->trans_type="deposit";
(trans)->amt=am;
(trans)->day.date=dat;
(trans)->day.mon=mo;
(trans)->day.year=yr;
cout<<"amount deposited";
(trans)=trans->next;
}
}
void withdra(struct list *list,struct list1 *list1)
{
if(list==NULL)
{
cout<<"list doesn't exists";
}
else
{
struct trans *trans=(struct trans*)malloc(sizeof(struct trans));
struct day *day;
struct node *node;
int am,dat,mo,yr;
cout<<"enter amount to be withdrawn and time";
cin>>am>>dat>>mo>>yr;
(node)->bal=(node)->bal-am;
(trans)->trans_type="withdraw";
(trans)->amt=am;
(trans)->day.date=dat;
(trans)->day.mon=mo;
(trans)->day.year=yr;
cout<<"amount withdrawn";
(trans)=trans->next;
}
}
void statement (struct list *list ,struct list1 *list1)
{ struct trans *trans=(struct trans*)malloc(sizeof(struct trans));
struct day *day;
struct node *node;
cout<<"\ncustomer id:"<<(node)->cust_id<<"\n account id"<<(node)->acc_id<<"\ncustomer name"<<(node)->name<< "\nbalance"<<(node)->bal;
struct trans *temp=list1->head;
cout<<"\nlist elements";
while(temp!=NULL)
{
cout<<"transaction type"<<temp->trans_type<<"\namount"<<temp->amt<<"\n date:"<<temp->day.date<<"-"<<temp->day.mon<<"-"<<temp->day.year;
temp=temp->next;
}
}
int main()
{
struct list *list;
struct list1 *list1;
int choice;
do
{
cout<<"enter ur choice 1.create account 2.deposit 3.withdraw 4.statement 5.exit";
cin>>choice;
switch(choice)
{
case 1:cre_acc (&list,&list1);
break;
case 2:deposit(list,list1);
break;
case 3:withdra(list,list1);
break;
case 4:statement(list,list1);
break;
default:
cout<<"enter valid option";
}
}while(choice!=5);
return 0;
}