This lab will give you practice using linked lists and unions. Files that you will need:
ice cream is nice but chocolate ice cream is dandythen the command:
<UNIX> linenum brad cream nice ice Niceshould produce the output:
cream 1 3 nice 1 ice 1 2 NiceThe words on the command line may be duplicated (e.g., ice may appear twice) but it is okay to only print that word once in your output. My executable will duplicate the output for that word, which is also acceptable.
I have provided one test file in the lab4 directory, linenum_test1 to test your program. However, you should test your program for boundary-type conditions and command line issues, such as:
Write a program called broker that reads stock and option transactions from a file, groups them by customer, and then prints out a report showing the total dollar amount of transactions for each customer and a list of that customer's transactions, printed in the order in which they were read. The customers will be printed in descending order based on the total value of their transactions.
The input will consist of records of two types:
stock ticker_symbol num_shares price_per_share dividend_amt customer_namestock is a keyword that identifies the type of transaction. ticker_symbol is a 3-5 character string that is used by traders as a shorthand symbol for the stock's name, num_shares is an integer expressing the number of shares involved in the transaction, and price_per_share is a floating point number denoting the price paid for each share. The dividend_amt is the amount of dividends the company pays on each share of stock. Finally the customer's name is a character string consisting of one or more words. The fields library will represent these words as separate fields so you will have to concatenate them together and put a single space between each word. A sample stock line might be:
stock ibm 200 83.50 2.50 Brad Vander Zanden
option ticker_symbol num_options price_per_share strike_price expiration_date customer_nameoption option is a keyword indicating the transaction type. ticker_symbol is a character string of 3-5 characters representing the option's trading symbol. num_options is an integer denoting the number of options purchased and price_per_share is a floating point number denoting the price paid for each share covered by an option. Since each option represents 100 shares the total transaction cost is determined by the following equation:
total transaction cost = price_per_share * 100 * num_optionsThe strike price is a floating point number and the expiration date has the format mm yyyy where mm is an integer between 1 and 12 and yyyy is a year. Finally the customer name is similar to the customer name for a stock. A sample input line for an option might appear as follows:
option oibm 3 5.50 85 12 2004 Brad Vander ZandenThis line says that Brad Vander Zanden has bought 3 calls on ibm at $5.50 a share. The call gives the customer the right to purchase the stock at $85.00 a share until December, 2004.
Your program should create a dlist that contains customer records. Each customer record will contain the customer's name, the customer's total transaction costs and a dlist that consists of all of the customer's transactions. You will need to define two structs, one for a customer record and one for a transaction record. A transaction record needs to store two types of transactions, stock transactions and option transactions. Stock and option transactions share some common information but each transaction also has some unique fields. Hence you will need to employ a union within your transaction struct that can represent the alternative information required for each type of transaction. Your solution must employ a union.
Once you have read all the transactions and organized them by customer, you should create a new dlist that will contain the customers sorted in descending order by total transaction cost. You will need to iterate through your initial customer list and add each customer to your new dlist using insertion sort.
The final thing you need to do is print the report. Each customer should start with a line that lists the customer's name and total transaction costs. The customer's name should be left justified in a field of 20 characters and the total transaction costs should be right-justified in a field that allows two decimal points. The customer line should be followed by indented lines that list the customer's transactions, one per line. Transaction lines should be indented by 4 spaces. Stock transaction lines should have fields in the following order and should be separated by one space:
dividend total = num_shares * dividend_amt
Submit two source files named linenum.c and broker.c respectively and a header file named broker.h.