Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

whats wrong in this?pls check!!!

0 votes
asked Sep 2, 2018 by My passion
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;
}

2 Answers

0 votes
answered Sep 6, 2018 by Leroy (390 points)
Well for starters your codes definitely ambiguous, especially when your dereferencing a pointer as a list, and expecting it with a required assignment.

There are easier ways to tackle your code but I have a feeling based on the stack your using to allocate account balance is messy and unnecessary. Your code should be easy to translate and broken up.

Plus your using a struct, and a struct is public by default and that creates unnecessary problems. A struct should be used when you need public access a class is set to private by default.
0 votes
answered Sep 6, 2018 by anonymous
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...