Answered step by step
Verified Expert Solution
Link Copied!

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 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 1400
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 2100
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 21100
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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning ASP.NET 2.0 And Databases

Authors: John Kauffman, Bradley Millington

1st Edition

0471781347, 978-0471781349

More Books

Students also viewed these Databases questions