Home / Expert Answers / Computer Science / write-a-program-that-reads-account-transactions-from-the-standard-input-stream-and-then-executes-tho-pa198

(Solved): Write a program that reads account transactions from the standard input stream and then executes tho ...



Write a program that reads account transactions from the standard input stream and then executes those transactions. The main source file (that includes a function named main) for this program should be main2.c and your Makefile for this program should produce an executable named main2 Make an array of Account structs to keep track of the accounts. Define a constant (using #define or the const keyword) named MAX_ACCOUNTS that specifies the maximum number of accounts that can be created. Format of input lines Each line of input will have a transaction or a command as the first thing on the line. Items on each input line will be separated by one or more spaces or tabs. Here is a list of account transactions and commands: ■ new For a new transaction, your program should create (or initialize) an account. If the maximum number of accounts has already been created then your program should print an error message and not create an account. To create an account, initialize an Account struct in the array, using the account_init function. Your program should assign an account number to the account and pass that number to account_init. Input lines for new transactions will have the word new, followed by the initial balance of the new account, followed by the first and last names of the account owner. The initial balance will always be an integer. There will always be exactly two names for the account owner. Here is an example of an input line for a new account: new 1000 Hermione Granger The initial balance for the account is $1000. The first name is Hermione and the last name is Granger. Those two names should be combined into one null-terminated string which is passed to account_init. ■ deposit For a deposit transaction, your program should get the account number and the deposit amount from the input line, use the account number to get the address of the correct Account struct, and then call account_deposit. Example: deposit 1 400 ■ withdraw For a withdraw transaction, your program should get the account number and the withdrawal amount from the input line, use the account number to get the address of the correct Account struct, and then call account_withdraw. Example: withdraw 2 100 ■ transfer For a transfer transaction, your program should get two account numbers, a source account, from which money will be taken, and a destination account, to which money will be added. Your program should use those two account numbers to get the addresses of the correct Account structs, and then call account_transfer. Example: transfer 2 1 100 ■ print For the print command your program should call the account_print function for each account that has been created. ■ quit When your program reads the quit command it should print a message and then terminate.



We have an Answer from Expert

View Expert Answer

Expert Answer


We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe