python
You are to write a program that reads in lines of input using scanf or cin, and file redirection, process the data, and then outthe results using printf or cout. This means you can use C or C++ or any other style I/O as is your personal preference.
  1. Each line of th named “transactione data file begins with an ‘e’, ‘c’, or ‘t’.
  2. Lines beginning with ‘e’ will have an integer employee ID and an employee name.
  3. Lines beginning with ‘c’ will have an integer customer ID, customer name, and a floating point account balance.
  4. Lines beginning with a ‘t’ will have a customer ID, employee ID, a ‘w’ or ‘d’ representing withdrawal or deposit,and a floating point transaction amount.
  5. Lines beginning with an ‘e’ and ‘c’ may be intermingled, but all ‘e’ and ‘c’ lines will come before lines beginning with ‘t’.
  6. There will be at most 50 employees and 50 customers, and an unknown number of transactions. Names will be at most 15 characters long.

An example data file is shown below:

e 5 Elden
c 3 Felipe 55342.51415
e 3 Leonardo
e 1 Yong
c 9 Alessandra 8114.541862
c 6 Marnie 15287.78233
e 8 Kourtney
c 2 Lou 95053.44742
c 5 Numbers 51245.66138
e 4 Jarvis
e 9 Marlen
e 10 Florance
c 1 Devon 56442.27875
e 2 Elliott
c 8 Justina 73723.84849
c 10 Reyna 82946.53205
e 6 Antonetta
e 7 Florene
c 4 Merrill 98281.82784
c 7 Marlana 33252.21805
t 1 8 w 4924.86
t 9 6 d 3220.42
t 6 1 w 127.62
t 9 8 w 5566.7
t 9 8 d 5414.55
t 5 7 w 9422.35
t 9 10 d 1382.07
t 4 7 d 6131.07
t 8 2 w 2362.22
t 8 10 d 5834.48
t 5 4 w 5150.73
t 6 2 d 3795.96
t 1 9 w 3919.45
t 5 2 w 5037.31
t 3 9 w 8129.21
t 8 6 d 1235.67
t 2 4 d 6901.28
t 8 10 d 5599.44
t 6 9 d 1936.16
t 7 9 d 7363.98

Your program should read in the employee and customer information and update the customer account balance depending on the transaction. For example, t 1 8 w 4924.86 means to update the balance for customer 1 by withdrawing 4924.86 from Devon’s account balance of 56442.27875. For each transaction, output customer name, the employee name, a plus sign for deposit or a minus sign for withdrawal, the transaction amount, and the new balance after the transaction with two decimal places (truncate values; do not worry about rounding). For example, the output for the example transaction above would appear as (include the line of digits):

123456789012345678901234567890123456789012345678901234567890
        Devon Kourtney -$4924.86 $ 51517.42

For the above the data file, your output would be:

123456789012345678901234567890123456789012345678901234567890
Devon Kourtney -$4924.86 $ 51517.42
Alessandra Antonetta +$3220.42 $ 11334.96
Marnie Yong -$ 127.62 $ 15160.16
Alessandra Kourtney -$5566.70 $ 5768.26
Alessandra Kourtney +$5414.55 $ 11182.81
Numbers Florene -$9422.35 $ 41823.31
Alessandra Florance +$1382.07 $ 12564.88
Merrill Florene +$6131.07 $104412.90
Justina Elliott -$2362.22 $ 71361.63
Justina Florance +$5834.48 $ 77196.11
Numbers Jarvis -$5150.73 $ 36672.58
Marnie Elliott +$3795.96 $ 18956.12
Devon Marlen -$3919.45 $ 47597.97
Numbers Elliott -$5037.31 $ 31635.27
Felipe Marlen -$8129.21 $ 47213.30
Justina Antonetta +$1235.67 $ 78431.78
Lou Jarvis +$6901.28 $101954.73
Justina Florance +$5599.44 $ 84031.22
Marnie Marlen +$1936.16 $ 20892.28
Marlana Marlen +$7363.98 $ 40616.20

You should create data structures to hold the data for each employee and for the customers, including their current balance. Then create arrays of these structures. You will need counters to keep track of the next available space in each array, as well as to use for loop control when searching for information. The arrays may be fixed size base on the limits provided above. When you receive a ‘t” command you can get the employee name and customer name and balance from the arrays. Be sure to update the customer balance to complete the transaction processing. You will output the iformation as described above.

When you have completed and tested your program on the your system, submit upload it to the assignment as Lab1_2. Be sure to include all the files needed to compile, link and run your program if you created more than a single program file.

Answer in Python program : Miss Anusha Panta from trinity international college Nepal

class Node:
    def __init__(self, key, value):
        self.key = key
        self.value = value
        self.next = None


class HashMap:
    def __init__(self):
        self.store = [None for _ in range(16)]

    def get(self, key):
        index = hash(key) & 15
        if self.store[index] is None:
            return None
        n = self.store[index]
        while True:
            if n.key == key:
                return n.value
            else:
                if n.next:
                    n = n.next
                else:
                    return None

    def put(self, key, value):
        nd = Node(key, value)
        index = hash(key) & 15
        n = self.store[index]
        if n is None:
            self.store[index] = nd
        else:
            if n.key == key:
                n.value = value
            else:
                while n.next:
                    if n.key == key:
                        n.value = value
                        return
                    else:
                        n = n.next
                n.next = nd


file = open("file.txt", "r")
em = HashMap()
cus = HashMap()
bal = HashMap()

# while True:
#     data = file.readline()
for data in file:
    if len(data) == 0:
        pass

    if data.startswith('e'):
        employee_data = data.split()
        # employee = {'e_id': employee_data[1], 'e_name': employee_data[2]}
        # print(employee['e_id'], employee['e_name'])
        em.put(employee_data[1], employee_data[2])

    if data.startswith('c'):
        customer_data = data.split()
        # customer = {'c_id': customer_data[1], 'c_name': customer_data[2], 'c_balance': customer_data[3]}
        # print(customer['c_id'], customer['c_name'], customer['c_balance'])
        # print(customer[5])
        cus.put(customer_data[1], customer_data[2])
        bal.put(customer_data[1], customer_data[3])

    if data.startswith('t'):
        transaction_data = data.split()
        # transaction = {'c_id': transaction_data[1], 'e_id': transaction_data[2], 'amount': transaction_data[4]}
        tc_id = transaction_data[1]
        te_id = transaction_data[2]
        amount = float(transaction_data[4])

        if transaction_data[3] == 'w':
            c_name = cus.get(tc_id)
            e_name = em.get(te_id)
            balance = float(bal.get(tc_id))
            remaining_balance = float(balance - amount)
            print(f'{c_name} {e_name} -${amount} ${remaining_balance}')
        else:
            c_name = cus.get(tc_id)
            e_name = em.get(te_id)
            balance = float(bal.get(tc_id))
            remaining_balance = float(balance + amount)
            print(f'{c_name} {e_name} +${amount} ${remaining_balance}')
Facebook Comments