Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program that reads account transactions from the standard input stream and then executes those transactions. The main source file ( that includes a
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 mainc and your Makefile for this program should produce an executable named main
Make an array of Account structs to keep track of the accounts. Define a constant using #define or the const keyword named MAXACCOUNTS 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 accountinit function. Your program should assign an account number to the account and pass that number to accountinit.
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 Hermione Granger
The initial balance for the account is $ The first name is Hermione and the last name is Granger. Those two names should be combined into one nullterminated string which is passed to accountinit.
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 accountdeposit.
Example:
deposit
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 accountwithdraw.
Example:
withdraw
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 accounttransfer.
Example:
transfer
print
For the print command your program should call the accountprint function for each account that has been created.
quit
When your program reads the quit command it should print a message and then terminate.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started