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

Goal of this assignment: To be able to bring together all the leaming from the c

ID: 3836964 • Letter: G

Question

Goal of this assignment: To be able to bring together all the leaming from the course to build something substantial Project: A bank is building a new software in C. Therequirements for this software are the following: There should be 2 types of accounts, an administrator account and a customer account. To start off the administrator account user must be"admin" login), "admin" (password) 2) The login screen should allow both administrator and Customer to login to the system Welcome to Online Banking/ATM System Enter your customer/Admin ID: 12345 OR admin Enter your customer/Admin Password: XXXXX OR admin The administrator shallbe able to login to the system. The system should detect when an administrator has logged in. Once logged in shelhe shall be able to see a menu as shown below Welcome to Online Banking/ATM System Administrator Menu 1) Create Customer account 2) Change Password 3) View Customer Info 4) Change Customer Info 5) Delete Customer account 6) Show Top 5 accounts 7) Show customer accounts alphabetically 8) Exit 1) Administrator shall be able to create a customer account 2) Administrator shall be able to change his/her own password 3) Administrator shall be able to view customer information 4) Administrator shall be able to change/edit a customer information

Explanation / Answer

// banksystem.c

Int is_valid_cust(char id[10], char pwd[10]) {

   // check this id and pwd with stored id, pwd.

   // these id, pwd can be stored when admin creates customer

   // we can add one more file store_cust.c

   // which will maintain an array of structure containing id and pwd

}

display_admin_menu(char id[5], char cust_file[32]) {

   // function to display admin menu option

   // and then call the functions in admin.c

}

display_cust_menu(char id[5], char cust_file[32]) {

   Char ch;

Do {

printf(“ ------------------------------------- “);

   printf(“ Customer Menu “);

   printf(“ ----------------------------------- ”);

   printf(“ a) Change Password”);

   printf(“ b) View Customer Information”);

   printf(“ c) View Balance”);

   printf(” d) Make a deposit”);

   printf(“ e) Transfer Money”);

   printf(“ f) Withdraw Money”);

   printf(“ g) Exit”);

   printf(“ Enter Choice : “);

   printf(“%s”, &ch);

   customer_main(id, ch, cust_file);

   } while(ch != ‘g’);

}

Int main(int argc, char* argv[]) {

// check if the function is called with correct arguments

If (argc !=2 ) {

   printf(“Error in arguments ! ”);

   printf(“Usage : banksystem CustomerData.txt”);

   Return 1;

}

Char cust_file[32] = argv[1];

Char id[5];

Char pwd[10];


printf(“ Welcome to the online Banking/ATM System ”);  

printf(“==================================== ”);

printf(“ Enter your customer/Admin ID : “);

scanf(“%s”, &id);

printf(“ Enter your customer/Admin Password : “);

scanf(“%s”, &pwd);

If ((id == “admin” && pwd == “admin”) || (id == “12345” && pwd == “XXXXX”)) {

   display_admin_menu(id,cust_file);

} else {

   Int valid = is_valid_cust(id,pwd);

   If (valid == 0) {

       printf(“ Invalid Customer ID or password ! ”);

   Return 1;

}

display_cust_menu(id,cust_file);

}

Return 0;

}


// customer.c

// read cust data file and copy data into array of struct

// display menu to customer

// perform according to selected option and update the array

// if exit is selected, dump the array into cust data file

#define MAX_CUST 100

struct cust {

char first_name[8];

char last_name[8];

Char city[10];

Char state[2];

Char phone[7];

Char id[5];

Char pwd[6];

Double bal;

};

void customer_main(char id[5],char ch, char cust_file[32]) {

   // read file line by line and copy it into array of structure cust

   Struct cust arr_cust[MAX_CUST];

FILE *fp,

Char *line = null;

Int len = 0,buff = 0;

Fp = fopen(cust_file, “rw”);

if(fp == NULL) {

printf(“Error in reading input file. ”);

Return;

}

Int cnt = 1, idx = 0;

Char *token;

while((buff = getline(&line, &len, fp)) != -1) {

   token = strtok(line, “:”);

   while(token != null) {

       if(cnt==1)

           strcpy(arr_cust[idx].first_name, token);

       Else if(cnt==2)

           strcpy(arr_cust[idx].last_name, token);

       Else if(cnt==3)

           strcpy(arr_cust[idx].city, token);

       Else if(Cnt==4)

           strcpy(arr_cust[idx].state, token);

       Else if(cnt==5)

           strcpy(arr_cust[idx].phone, token);

       Else if(cnt==6)

           strcpy(arr_cust[idx].id, token);

       Else if(Cnt==7)

strcpy(arr_cust[idx].pwd, token);

Else if(cnt==8)

arr_cust[idx].bal = token;

  

token = strtok(NULL, “:”);

       cnt++;

   }

   idx++;

}

// At this stage, we have dumped cust_file data into arr_cust.

// based on ch, update the arr_cust / output the data.

switch(ch) {

Case ‘a’:

   Char old_pwd[10],new_pwd[10],new_pwd,copy[10];

   printf(“Enter old password : “);

   scanf(“%s”,old_pwd);

   printf(“Enter new password : “);

   scanf(“%s”,new_pwd);

   printf(“Confirm new password : “);

   scanf(“%s”,new_pwd_copy);

   If (strcmp(new_pwd, new_pwd_copy) != 0) {

       printf(“Error : New password does not match. ”);

       Return;

   }

   // search in arr_cust for given id

   for(i=0;i<idx;i++) {

       if(strcmp(arr_cust[i].id, id) == 0) {

           if(strcmp(arr_cust[i].id,old_pwd) != 0) {

               printf(“Error : Old password is incorrect. ”);

               Return;

           }

           strcpy(arr_cust[i].pwd, new_pwd);

           break;

}

}

Break;

Case ‘b’:

   // view customer information

   // search for given id and dump the information

   // search in arr_cust for given id

   for(i=0;i<idx;i++) {

       if(strcmp(arr_cust[i].id, id) == 0) {

           printf(“ First name : %s”,arr_cust[i].first_name);

           printf(“ Last name : %s”,arr_cust[i].last_name);

           printf(“ City : %s”,arr_cust[i].city);

           printf(“ State : %s”,arr_cust[i].state);

           printf(“ Phone : %s”,arr_cust[i].phone);

           printf(“Customer ID : %s”,arr_cust[i].id);

// Should we display pwd ??

           printf(“Password : %s”,arr_cust[i].pwd);

           printf(“Balance : %f”,arr_cust[i].bal);

           Break;

       }

   }

   Break;

Case ‘c’:

   // view balance

   // search in arr_cust for given id

   for(i=0;i<idx;i++) {

       if(strcmp(arr_cust[i].id, id) == 0) {

printf(“Balance : %f”,arr_cust[i].bal);

           Break;

       }

   }

   Break;

Case ‘d’:

   // Make a deposit

Double amt;

   printf(“ Enter the amount to be deposited : “);

   scanf(“%f”,&amt);

   // search in arr_cust for given id

   for(i=0;i<idx;i++) {

       if(strcmp(arr_cust[i].id, id) == 0) {

Arr_cust[i].bal += amt;

           Break;

       }

   }

   Break;

Case ‘e’:

   // Transfer money

   Double amt;

   Char to_id[5];

   Int cnt = 0;

   printf(“ Enter the customer id/account no to which amount should be transferred : “);

   scanf(“%s”,&to_id);

   printf(“ Enter the amount to be transferred : “);

   scanf(“%f”,&amt);

   // search in arr_cust for given id

   for(i=0;i<idx;i++) {

       if(strcmp(arr_cust[i].id, id) == 0) {

           Arr_cust[i].bal = arr_cust[i].bal - amt;

           Cnt++;

       }

       f(strcmp(arr_cust[i].id, to_id) == 0) {

           Arr_cust[i].bal = arr_cust[i].bal + amt;

           Cnt++;

       }

       if(cnt==2)

           Break;

   }

   Break;

Case ‘f’:

   // withdraw money

   Double amt;

   printf(“ Enter the amount : “);

   scanf(“%f”,&amt);

   // search in arr_cust for given id

   for(i=0;i<idx;i++) {

       if(strcmp(arr_cust[i].id, id) == 0) {

           if(arr_cust[i].bal < amt) {

               printf(“Error : Insufficient Balance.”);

               Return;

           }

           Arr_cust[i].bal = arr.cust[i].bal - amt;

           Break;

       }

   }

   Break;

Case ‘g’:

   // Exit

   // copy arr_cust content to file

   // here, we are taking wline string and appending values of each field from

// arr_cust  

   for(i=0;i<idx;i++) {

       Char wline[100];

strcpy(wline,arr_cust[i].first_name);

       strcat(wline,” “);

       strcat(wline,arr_cust[i].last_name);

       strcat(wline,” “);

       strcat(wline,arr_cust[i].city);

       strcat(wline,” “);

       strcat(wline,arr_cust[i].state);

       strcat(wline,” “);

       strcat(wline,arr_cust[i].phone);

       strcat(wline,” “);

       strcat(wline,arr_cust[i].id);

       strcat(wline,” “);

       strcat(wline,arr_cust[i].pwd);

       strcat(wline,” “);

       strcat(wline,arr_cust[i].bal);

       fprintf(fp, “%s”, wline);

   }

   fclose(fp);

   break;

}

return;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote