Question

Write a C program to make an ATM Management System. Use string functions and file handling...

Write a C program to make an ATM Management System. Use string functions and file handling in your code. Your program should verify a user by already defined PIN Code and perform deposit/withdraw/check account balance

Edit: it is a console program

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the required program

#include<stdio.h>
struct user{
   int id; // this is 10 digit number as user id you can change to string or increase the length

// i'm assuming an integer because most atm uses a card number to remember the user although you can change to
   //string if needed
   int pin; // this is 4 digit pin for that user already saved in the record
   int bal; //this will store current balance
};

int main()
{
   FILE* f;
   f=fopen("atm.txt","r"); //atm.txt file contains the data
   int c;
   int n;
   fscanf(f,"%d",&n); //first integer how many records the file has
   struct user users[n];
   for(int i=0;i<n;i++)
   {
       fscanf(f,"%d%d%d",&users[i].id,&users[i].pin,&users[i].bal);
   }
   do{
       printf("\n\nWelcome to ATM management\n");
       printf("1. To do some transaction or to check balance\n");
       printf("2. To quit the program\n");
       scanf("%d",&c);
       switch(c)
       {
           case 1:{
               int userid,pin,amount,index=-1;
               printf("\nEnter your user details with 10 digit id: ");
               scanf("%d",&userid);
               for(int i=0;i<n;i++) //check entered userid exist or not
               {
                   if(userid==users[i].id)
                   {
                  
                       index=i;
                       break;
                   }
               }
               if(index==-1)
               {
                   printf("\nNo user exist with the given id\n\n");
                   break;
               }
               printf("\nEnter the pin for the account: ");
               scanf("%d",&pin);
               if(pin!=users[index].pin)
               {
                   printf("\nEntered pin is not correct\n\n");
                   break;
               }

               printf("\n1. Deposit money");
               printf("\n2. Withdraw money");
               printf("\n3. Check balance\n");
               int choice;
               scanf("%d",&choice);
               switch(choice)
               {
                   case 1:{
                       int amt;
                       printf("\nenter the amount you want to Deposit: ");
                       scanf("%d",&amt);
                       users[index].bal+=amt;
                       printf("\nupdated balance is: %d",users[index].bal);
                       break;
                   }
                   case 2:{
                       int amt;
                       printf("\nenter the amount you want to Withdraw: ");
                       scanf("%d",&amt);
                       if(users[index].bal<amt){ //when user try to withdraw more than balance
                           printf("\nyou don't heave sufficient balance\n");
                           break;
                       }
                       users[index].bal-=amt;
                       printf("\nupdated balance is: %d",users[index].bal);
                       break;
                   }
                   case 3:{
                       printf("\nthe balance in your account is: %d",users[index].bal);
                       break;
                   }
                   default:printf("\nwrong choice");
               }
               break;
           }
           case 2:{
               fclose(f);
               f=fopen("atm.txt","w"); //open file in write mode
               fprintf(f, "%d\n",n );
               for(int i=0;i<n;i++)
               {
                   fprintf(f, "%d %d %d\n",users[i].id,users[i].pin,users[i].bal );
               }
               fclose(f);
               break;
           }
           default:{
               printf("\nwrong choice please enter correct choice\n\n");
               break;
           }
       }
   }while(c!=2);
}

a file atm.txt

is used to store the data of the users

first line of the file contains the number of users stored i.e. n

and for the next n lines each line contain a user detail as the userid pin and balance

here is the ss of the file

here is the ss of the output

I hope this will help you so please give positive ratings :)))

Add a comment
Know the answer?
Add Answer to:
Write a C program to make an ATM Management System. Use string functions and file handling...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Write a Java program to count all words in a string. User inputs a string...

    1. Write a Java program to count all words in a string. User inputs a string sentence and your program should count the number of words in that string. Test Data: Input the string: The quick brown fox jumps over the lazy dog. Expected Output: Number of words in the string: 9 2. Write a class called ATMTransaction. This class has a variable balance and account number. It has three methods, checkBalance, deposit and withdraws along with constructors getters and...

  • write a code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

  • C++ Read and do as instructed on please (C++Program *** use only condition statements, loops, functions,...

    C++ Read and do as instructed on please (C++Program *** use only condition statements, loops, functions, files, and arrays. Do NOT use material such as classes. Make sure to add comments** You are to write an ATM Program. The ATM should allow the user to do the following: 1. Create account 2. Log in 3. Exit When they press 1, they are asked for first name (capital first letter). Then it should ask for password. The computer should give the...

  • Question 3.1 Draw the class diagram for the ATM program in Question 2.1. Please find attached...

    Question 3.1 Draw the class diagram for the ATM program in Question 2.1. Please find attached the scenario in the photos. this is for programming logic and design Scenario A local bank intends to install a new automated teller machine (ATM) to allow users (i.e., bank customers) to perform basic financial transactions (see below figure). Each user can have only one account at the bank. ATM users should be able to do the following; View their account balance. Withdraw cash...

  • C++ program Write a C++ program to manage a hospital system, the system mainly uses file...

    C++ program Write a C++ program to manage a hospital system, the system mainly uses file handling to perform basic operations like how to add, edit, search, and delete record. Write the following functions: 1. hospital_menu: This function will display the following menu and prompt the user to enter her/his option. The system will keep showing the menu repeatedly until the user selects option 'e' from the menu. Arkansas Children Hospital a. Add new patient record b. Search record c....

  • answer in c++ code. use comments when writing the code to know what's your thinking. there is three pictures with information Write a C++ console program that defines and utilizes a cl...

    answer in c++ code. use comments when writing the code to know what's your thinking. there is three pictures with information Write a C++ console program that defines and utilizes a class named ATM. This program will demonstrate a composition relationship among classes because an ATM can contain many Accounts. You will need to reuse/modify the Account class you created in Assignment 10. The default constructor for the ATM class should initialize a private vector of 10 accounts, each with...

  • PYTHON The provided code in the ATM program is incomplete. Complete the run method of the...

    PYTHON The provided code in the ATM program is incomplete. Complete the run method of the ATM class. The program should display a message that the police will be called after a user has had three successive failures. The program should also shut down the bank when this happens. [comment]: <> (The ATM program allows a user an indefinite number of attempts to log in. Fix the program so that it displays a message that the police will be called...

  • Write a program called problem4.cpp to implement an automatic teller machine (ATM) following the BankAccount class...

    Write a program called problem4.cpp to implement an automatic teller machine (ATM) following the BankAccount class the we implemented in class. Your main program should initialize a list of accounts with the following values and store them in an array Account 101 → balance = 100, interest = 10% Account 201 → balance = 50, interest = 20% Account 108 → balance = 200, interest = 11% Account 302 → balance = 10, interest = 5% Account 204 → balance...

  • Use Dec-C++ compiler Problem 13, Chapter 8 Programming Exercises 8.3 8.3. Write a program CHECKBOOK that...

    Use Dec-C++ compiler Problem 13, Chapter 8 Programming Exercises 8.3 8.3. Write a program CHECKBOOK that prompts the user for an amount and either + or -. If the user enters +, then balance, an extern variable, is incremented by the amount. If the user enters -, then balance is decremented by the amount. Two functions, deposit and withdraw, perform the updating operations.

  • On Dev C++ Write a C++ program that read customer name and saving account balance. Then...

    On Dev C++ Write a C++ program that read customer name and saving account balance. Then it display the following messages to the user: "Press #1 to make a deposit." "Press #2 to make withdraw." If the user presses "1", then read the amount of the deposit, apply it to the balance and display the new account balance. If the user presses "2", then read the amount to withdraw, apply it to the balance and display the new account balance....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT