Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Could you please help me with this assignment? The following programming assignm

ID: 3782926 • Letter: C

Question

Could you please help me with this assignment?

The following programming assignment should be completed in C or C++ using the standard socket libraries that come with your operating system

1. Write a server application that represents an online banking utility. Let your server maintain an array of “bank accounts,” which will be objects of the following struct type:

struct bankaccount
{
   int acctnum;

   char password[8];    // max password length is 8 characters

   double balance;
};

You should create a set of 3 or 4 test accounts with made-up values to populate this array.

Your application should use a server socket to listen in to incoming client connections. As soon as a client logs on, it should present the client with the following prompt:

Welcome to [Choose A Name] Bank:

Please enter an account number:

After an account number is received from the client through the socket connection, the server program should check if the corresponding bank account exists. If not, return an error message to the client and close the connection. If the account does exist, then present the client with the following prompt:

Please enter password:

The server program should then wait until the client responds with a password. Once this occurs, the server should validate the password. If the password is incorrect, return an error to the client and close the connection. If the password is correct, then present the client with the following prompt:

Please enter a transaction:

The server program should then expect a command of on the following forms:

Deposit 123.45                This deposits $123.45 into the selected account

Withdraw 98.76                This withdraws $98.76 from the account (if the amount is available)

Balance                       This displays the balance

In the case of a deposit, the server should increment the bank account’s balance field by the deposit amount and then return a message to the client stating the new balance. In the case of a withdrawal, assuming sufficient funds exist, the server should decrement the bank account’s balance field by the withdrawal amount and then return a message to the client stating the new balance. If sufficient funds do not exist to cover the withdrawal amount, then the server should return a message to the client indicating this. In the case of “Balance,” the server should simply respond to the client with the balance of the account. In all cases, the socket should be closed immediately after the transaction is complete.

2. Write a client program in C/C++ that connects to the server you wrote in problem 1. Your client should be able to display and respond to the prompts transmitted by the server. Unless you really want to test your program over a real network, you may assume that the server’s address islocalhost.

Explanation / Answer

#include <iostream.h>

#include <conio.h>

class account

{

char cust_name[20];

int acc_no;

char acc_type[20];

public:

   void get_accinfo()

   {

       cout<<" Enter Customer Name :- ";

       cin>>cust_name;

       cout<<"Enter Account Number :- ";

       cin>>acc_no;

       cout<<"Enter Account Type :- ";

       cin>>acc_type;

   }

   void display_accinfo()

   {

       cout<<" Customer Name :- "<<cust_name;

       cout<<" Account Number :- "<<acc_no;

       cout<<" Account Type :- "<<acc_type;

   }

};

class cur_acct : public account

{

staticfloat balance;

public:

    void disp_currbal()

    {

      cout<<" Balance :- "<<balance;

    }

    void deposit_currbal()

    {

      float deposit;

      cout<<" Enter amount to Deposit :- ";

      cin>>deposit;

      balance = balance + deposit;

    }

    void withdraw_currbal()

    {

      float penalty,withdraw;

      cout<<" Balance :- "<<balance;

      cout<<" Enter amount to be withdraw :-";

      cin>>withdraw;

      balance=balance-withdraw;

      if(balance < 500)

      {

      penalty=(500-balance)/10;

      balance=balance-penalty;

      cout<<" Balance after deducting penalty : "<<balance;

      }

      elseif(withdraw > balance)

      {

      cout<<" You have to take permission for Bank Overdraft Facility ";

      balance=balance+withdraw;

      }

      else

      cout<<" After Withdrawl your Balance revels : "<<balance;

     }

};

class sav_acct : public account

{

staticfloat savbal;

public:

     void disp_savbal()

    {

      cout<<" Balance :- "<<savbal;

    }

    void deposit_savbal()

    {

      float deposit,interest;

      cout<<" Enter amount to Deposit :- ";

      cin>>deposit;

      savbal = savbal + deposit;

      interest=(savbal*2)/100;

      savbal=savbal+interest;

    }

    void withdraw_savbal()

    {

      float withdraw;

      cout<<" Balance :- "<<savbal;

      cout<<" Enter amount to be withdraw :-";

      cin>>withdraw;

      savbal=savbal-withdraw;

      if(withdraw > savbal)

      {

      cout<<" You have to take permission for Bank Overdraft Facility ";

      savbal=savbal+withdraw;

      }

      else

      cout<<" After Withdrawl your Balance revels : "<<savbal;

     }

};

float cur_acct :: balance;

float sav_acct :: savbal;

void main()

{

clrscr();

cur_acct c1;

sav_acct s1;

cout<<" Enter S for saving customer and C for current a/c customer ";

char type;

cin>>type;

int choice;

   if(type=='s' || type=='S')

     {

       s1.get_accinfo();

       while(1)

       {

     clrscr();

     cout<<" Choose Your Choice ";

     cout<<"1)   Deposit ";

     cout<<"2)   Withdraw ";

     cout<<"3)   Display Balance ";

     cout<<"4)   Display with full Details ";

     cout<<"5)   Exit ";

     cout<<"6)   Choose Your choice:-";

     cin>>choice;

     switch(choice)

     {

       case 1 : s1.deposit_savbal();

            getch();

            break;

       case 2 : s1.withdraw_savbal();

            getch();

            break;

       case 3 : s1.disp_savbal();

            getch();

            break;

       case 4 : s1.display_accinfo();

            s1.disp_savbal();

            getch();

            break;

       case 5 : goto end;

       default: cout<<" Entered choice is invalid,"TRY AGAIN"";

     }

       }

     }

    else

     {

       {

       c1.get_accinfo();

       while(1)

       {

     cout<<" Choose Your Choice ";

     cout<<"1)   Deposit ";

     cout<<"2)   Withdraw ";

     cout<<"3)   Display Balance ";

     cout<<"4)   Display with full Details ";

     cout<<"5)   Exit ";

     cout<<"6)   Choose Your choice:-";

     cin>>choice;

     switch(choice)

     {

       case 1 : c1.deposit_currbal();

            getch();

            break;

       case 2 : c1.withdraw_currbal();

            getch();

            break;

       case 3 : c1.disp_currbal();

            getch();

            break;

       case 4 : c1.display_accinfo();

            c1.disp_currbal();

            getch();

            break;

       case 5 : goto end;

       default: cout<<" Entered choice is invalid,"TRY AGAIN"";

     }

       }

     }

end:

}

}