The objective of this lab is several fold:
You will be using a file that contains stock transactions of the type found in transactions. Each line of the file contains a transaction type, a stock symbol, the number of shares bought or sold, the price per share, the date of the transaction in month, day, year format, and the first and last names of the individual. The first and last names will be separated by a pipe character (|) which has at least one space both before and after it. Both first and last names can consist of an arbitary number of words. For example:
Bobbi Sue | Van der ZandenYou may assume that the input is error free. In other words, you will not be required to perform error checking in this lab.
Write an include file, transactions.h, that contains a class declaration for a single stock transaction. Use this include file for all of your programs. The transaction class will be used as a record so you can declare the fields public if you wish.
Write a program called avg.c that prints the total cost of each transaction and then prints the average cost of all the transactions. Read the input from stdin. Each transaction should have its own line of output and each line of output should list the stock symbol, the quantity, the amount, and the total transaction cost. The total transaction cost should be rounded to two decimal places and should have the format xxxxxx.xx. In other words the total transaction cost should occupy a minimum of 9 character spaces. The format of a line should be:
xxxx xxxx xxx.xx xxxxxx.xx
The x's denote the minimum number of characters that each field should contain. The stock symbols should be left-justified and the remaining fields should be right-justified. The final line should have a blank line between it and the preceding transactions and should have the format:
average transaction cost = $xxxxxx.xxYour program may use a counter to count the number of transactions.
Write a program named name.c that prints each name in the file on a separate line using the format:
lastname, firstnameThe firstname may include a middle name or initial. No name should be printed more than once. You should maintain a C++ STL list to keep track of the names your program has printed thus far. Read the input from stdin.
Write a program named sort_date that sorts the transactions in ascending order according to the date of the transaction. Earlier years should precede later years. The transactions should be printed out in the same format in which they were read. You should use a STL list to keep track of the transactions and should sort this list based on each transaction's date. The user should provide the filename as a command line argument. You should print out an error message if the user fails to provide a command line argument.
Write a program that sorts the transactions in alphabetical order by stock name. For each stock you should first print a line that contains the stock's name and the average transaction cost for that stock. The line number is the line that the transaction occurred upon in the original input file. You should then print the transactions for that stock using the following format:
line_number mm/dd/yyyy quantity price name
The precise format for your output should be:
xxxx average transaction = $xxxxxx.xx
xx xx/xx/xxxx xxxx xxx.xx xxxxxxxxxxxxxxxxxxxx
xx xx/xx/xxxx xxxx xxx.xx xxxxxxxxxxxxxxxxxxxx
....
xxxx average transaction = $xxxxxx.xx
xx xx/xx/xxxx xxxx xxx.xx xxxxxxxxxxxxxxxxxxxx
xx xx/xx/xxxx xxxx xxx.xx xxxxxxxxxxxxxxxxxxxx
....
There should be a blank line between each set of stock transactions.
You must use a STL list to hold the stocks and each stock must hold a STL list containing its transactions. You will lose points if you use only one list.
The user should provide the filename as a command line argument. You should print out an error message if the user fails to provide a command line argument.
You should prepare a makefile that permits the TAs to individually or collectively create executables for each of the programs in this lab. The following link, makefiles, prepared by Professor James Plank provides excellent guidance on how to create a makefile. The TAs will also provide a lecture on makefiles during lab hours on Monday.
You should submit the following files: