For this assignment you are to write an application that will maintain a collection of stocks (which we will call a Portfolio). The following UML diagram shows the three main classes that will be needed for this project.
Here are some clarifying comments about these classes.
A Stock object will hold basic information about an individual stock.
A Portfolio object has the responsibility for maintaining a list of Stock pointers. Its member functions should be defined in a consistent manner.
It should not be possible for any Stock to be in the list more than once. For example, if a Verizon Stock is in the list and the user attempts to add() it to the list again (or buy() more shares), the add() function (or the buy() function) should silently adjust the m_SharesHeld and m_CurrentPrice members of the existing list item instead of adding another item to the list.
The sell() function should not permit the sale of more shares than the Portfolio actually holds. Your program should do something sensible and reasonable in such a case.
I have specified a class, PortfolioFile, that handles the job of saving Portfolio data to a file and loading a Portfolio object from a data file. I have assumed here that you will save yourself some labor by using the two file opening functions in the qstd namespace from our utils library. The best way to do this is to install that library by following the instructions in sections 7.2 to 7.4 of our book. I also assume that you will exploit the toString() functions and the split() and join() conversions between QString and QStringList.
Don't repeat code. When I wrote this program I started with the earlier version of the UML diagram and discovered that I could eliminate repeated code by factoring out lines from a few functions and adding a few new ones (e.g., in Portfolio, I added safeClear(), which deletes each pointer and then clears the list, and findStock(), which searches the list for a Stock and returns its pointer - or 0 if the Stock is not in the list.).
You may want or need to add additional member functions to these classes. I have not written this yet but I think that the class definitions suggested by the diagram are sufficient.
When your classes are completely written, you need to write client code to give a good test of your classes.
I suggest that you use a menu with options like:
(1) Load data from a file.
(2) Add Stocks to the Portfolio.
(3) Buy Stocks.
(4) Sell Stocks.
(5) Display Portfolio.
(6) Save data to a file.
(7) Exit.
Make sure that you supply me with a good data file when you send me your tarball so that I can test your program without having to do too much data entry.
Submitting Your Homework . For this assignment you are to follow the procedure outlined below. Please read these instructions carefully.
First create a directory named hw03 which will contain all of the source code and data for this program and nothing else.
Design, code, compile, and thoroughly test the program.
Make sure that your program files each begin with a substantial comment section that includes:
your name
program name
a brief description of the contents of the file
the date of your last modification to the file
Make sure that your source code does not contain any lines that are longer than 79 characters.
Each function should have a comment section that briefly explains what the function does and how to use it.
When you are ready to submit your work, cd to your hw03 directory and prepare a script file as follows:
script hw03script // open the script file cat firstfile // list each of your program file(s) cat secondfile...(etc.) // into the script. (see note below) make // compile your program ./a.out // give a good demo of your program exit // close the script file
[Note: If you have pairs of files such as: thing.h and thing.cpp ALWAYS list the .h file first and then the .cpp file.]
Prepare a gzipped tarball that contains your script file and also all of your source code files and data files so that I can build and run your program. To do this, first delete all backup files and all binary files from each program directory. Then, from the hw03 directory, issue the following command:
tar -czf yourname-hw03.tar.gz *
This command will create a compressed archive containing all files in the directory as well as any subdirectories, so make sure that you delete all backup~ files and binary files that may have been produced while you were editing and debugging your program.
Finally: Mail your tarball as an attachment to:
ezust@mcs.suffolk.edu
Make sure that you have a Subject: line that says: HW03
DO NOT DELETE YOUR SCRIPT FILE UNTIL I HAVE GRADED AND RETURNED IT TO YOU.