Can you solve this question with explanation You are suppose

Can you solve this question with explanation?
You are supposed to implement a C++ program that mimics some of the processes in a bank. The customers are lined up in a queue and wait their turn in order to perform the following actions: withdraw money, deposit money, lend their money at interest (you can assign a default value), etc. These operations should be processed through a menu. Therefore, we should be able to choose the operations and enter the data which will be processed by the rest of your code. Arn example can be seen below: 1. Withdraw Money 2. Deposit Money 3. Lend Money at Interest 4 At the end of each operation, each customer will receive a bill showing the list of their activities. This list should include the most recent activity at the top and the least recent activity at the bottom. In order to perform this operation, you will use a stack which will reverse the activities from latest to the oldest. An example can be seen below: Customer Name: ABCDE Customer Surname: ABCDE Customer ID: 123456 Account Movements/Statements: 14.15 the customer withdraws 15 dollars from account 14.00 the customer lends money at interest 13.55-the customer deposits 50 dollars into account

Solution

#include<stdio.h>

void takeCustomerDetails();
int askTransactionType();
int customerExists(int customerId);
void printRecipt(int customerIndex);

struct customer
{
   char name[100];
   char surName[100];
   int id;
   int transaction_type[100];
   double transaction_amount[100];
   int lastTransaction;
};

int current_index = 0,customer_index=0;
struct customer customers[100];

main()
{
   int type;
   float money;
   int lastTransaction;
   while(true)
   {
       takeCustomerDetails();
       type = askTransactionType();
       if(type == 4)
       {
           break;
       }
       printf(\"Enter amount : \");
       scanf(\"%f\",&money);
       lastTransaction = customers[customer_index].lastTransaction;
       customers[customer_index].transaction_type[lastTransaction] = type;
       customers[customer_index].transaction_amount[lastTransaction] = money;
       customers[customer_index].lastTransaction++;
       printf(\"--------------------------------------------------\ \");
       printRecipt(customer_index);
       printf(\"--------------------------------------------------\ \");
   }
}

void printRecipt(int customerIndex){
   customer currentCustomer = customers[customerIndex];
   for(int count=currentCustomer.lastTransaction-1;count>=0;count--)
   {
       if(currentCustomer.transaction_type[count] == 1)
       {
           printf(\"the customer withdraws %f dollars from account\ \",currentCustomer.transaction_amount[count]);
       }
       else if(currentCustomer.transaction_type[count] == 2)
       {
           printf(\"the customer deposits %f dollars from account\ \",currentCustomer.transaction_amount[count]);
       }
       else if(currentCustomer.transaction_type[count] == 3)
       {
           printf(\"the customer lends %f dollars from account\ \",currentCustomer.transaction_amount[count]);
       }
      
   }
}

void takeCustomerDetails()
{
   printf(\"Enter customer id : \");
   int custId;
   scanf(\"%d\",&custId);
   customer_index = customerExists(custId);
   if(customer_index == -1)
   {
       customers[current_index].id = custId;
       printf(\"Enter customer name : \");
       scanf(\"%s\",customers[current_index].name);
       printf(\"Enter surname: \");
       scanf(\"%s\",customers[current_index].surName);
       customer_index = current_index++;
   }  
}

int customerExists(int customerId)
{
   int i,size=sizeof(customers)/sizeof(customers[0]);
   for(i=0;i<sizeof(customers)/sizeof(customers[0]);i++)
   {
       if(customers[i].id == customerId)
       {
           return i;
       }
   }
   return -1;
}

int askTransactionType(){
   printf(\"1. Withdraw money\ \");
   printf(\"2. Deposit money\ \");
   printf(\"3. Lend money at interest\ \");
   printf(\"4. Exit\ \");
   int option;
   scanf(\"%d\",&option);
   return option;
}

Can you solve this question with explanation? You are supposed to implement a C++ program that mimics some of the processes in a bank. The customers are lined u
Can you solve this question with explanation? You are supposed to implement a C++ program that mimics some of the processes in a bank. The customers are lined u

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site