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

Automated Teller Machines (ATM) Consider this scenario. Suppose that 8 people in

ID: 3729127 • Letter: A

Question

 Automated Teller Machines (ATM)  Consider this scenario. Suppose that 8 people in the company have access to the Mt. Tabor Pumpkin account. Each person (thread)  can make a deposit (D) followed by an amount in dollars (integer), a withdrawal (W) followed by an amount in dollars (integer) and can check the ballance (B) of the account. Your job is to accurately keep track of the balance in the Mt. Tabor Pumpkin account.  The input for this file will be a series of lines representing the activity of each person's tranactions on the account for a given week.  The file name for input will be trans.txt.After each successful transaction (D,W,B) your program should record the transaction to a  file named activity.txt. Clearly viewing the current account balance can be accessed by more than one user at a time. However, modification to the account, should be protected and only allowed by one person at a time. You may assume that the initial value of the Mt.  Tabor Pumpkin account is 10,000. If negative balance occurs no problem.  Example of input:  B W 100 D 50 D 10 B W 50 B D 100 B B B D 10 D 100 D 100 W 50 W 50 D 10 D 10 D 10 D 5 W 10 B B D 1000 B W 500 B W 100 W 100 W 100 B D 500 D 500 D 500  Example output:  Thread 0 checks balance, balance is : 1000  Thread 3 withdraws 50, balance is : 950  . . .   Name this program atm.cpp in C++ 

Explanation / Answer

#Python COde

#Importing
import threading
import os

balAmnt = 1000 # Intial amount
lock = threading.Lock()

def withdraw( amount ):
global balAmnt # GlobalVariable defining
lock.acquire()
balAmnt = balAmnt - int(amount)
activity.write(threading.current_thread().name + " withdraws Amount is " + amount + ", Remaining Balance is: " + str(balAmnt) + " ")
lock.release()

def depositAmt( amount ):
global balAmnt
lock.acquire()
balAmnt = balAmnt + int(amount)
activity.write(threading.current_thread().name + " deposits " + amount + ", balance is: " + str(balAmnt) + " ")
lock.release()

def balance():
global balAmnt
activity.write(threading.current_thread().name + " has checked Total balance, Updated balance is: " + str(balAmnt) + " ")

def execute( operations ):
op = operations.split()
n = 0
while n < len(op):#It will terminates, then only condition fails
if op[n] == "B":
balance()
n += 1
elif op[n] == "W":
withdraw(op[n+1])
n += 2
else:
depositAmt(op[n+1])
n+=2

if __name__ == "__main__":
trans = open("trans.txt", "r") # Readable only
activity = open("activity.txt", "w")

numOfThreads = 0
d = trans.readline()
while d:
t = threading.Thread(target = execute, kwargs={'operations':d})
t.start()
d = trans.readline()

Python code written.

Please let me if you have any quiries.

If you want I can write in C- prog also.

Comment you want