Saint Louis University |
Computer Science P125
|
Dept. of Math & Computer Science |
Please see the general programming webpage for details about the programming environment for this course, guidelines for programming style, and details on electronic submission of assignments.
For this assignment, you are allowed to work with one other student if you wish (in fact, we suggest that you do so). If any student wishes to have a partner but has not been able to locate one, please let the instructor know so that we can match up partners.
Please make sure you adhere to the policies on academic integrity in this regard.
The goal of this assignment is to read a data set which represents a series of stock prices and to generate a graph of those prices using the EzWindows graphics package.
For example, here is such a graph, provided by the NYTimes website, summarizing the last 23 market days of activity for Google:
Our chart may not be quite as detailed as this picture, but let's see what we can do. See the detailed requirements below for what is expected.
You should read the data from the user using the 'cin' input stream object. However, please use precisely the following format for gathering data.
The first two values in the input are double values which specify the absolute low and high stock values over the range of interest. This pair will allow you to calibrate the vertical axis of your figure.
The next input is a single int which specifies the number of days worth of data which is to follow. This will allow you to calibrate the horizontal axis of your figure as well as to proceed in reading the remaining data.
What follows is data for each individual day, chronologically, with one full day's data per line. Each day is described by five values
The minimum requirements for this assignment will only use the low and high prices for each date, but we ask that your program read all five in any event for consistency in format (the final three will be used for the extra credit).
As an example, here is the raw data which might be used
to regenerate the above figure for Google (except that data for
18-Feb-05 is not included below):
175 220
23
198.66 205.02 200.97 203.90 18-Jan-05
196.71 205.30 204.65 197.30 19-Jan-05
192.00 196.25 192.50 193.92 20-Jan-05
188.12 195.36 194.54 188.28 21-Jan-05
180.32 189.33 188.69 180.72 24-Jan-05
176.29 182.24 181.94 177.12 25-Jan-05
179.15 189.41 179.27 189.24 26-Jan-05
185.20 188.86 188.76 188.08 27-Jan-05
186.34 194.70 190.02 190.34 28-Jan-05
191.72 196.36 193.69 195.62 31-Jan-05
190.63 196.66 194.38 191.90 1-Feb-05
203.66 216.80 215.55 205.96 2-Feb-05
205.81 213.37 205.99 210.86 3-Feb-05
202.60 207.75 206.47 204.36 4-Feb-05
195.51 206.40 205.26 196.03 7-Feb-05
194.53 200.02 196.96 198.64 8-Feb-05
189.46 201.60 200.76 191.58 9-Feb-05
185.25 192.21 191.97 187.98 10-Feb-05
186.07 192.32 186.66 187.40 11-Feb-05
181.00 193.08 182.85 192.99 14-Feb-05
193.08 199.84 193.60 195.23 15-Feb-05
194.30 199.33 194.70 198.41 16-Feb-05
196.81 199.75 197.83 197.90 17-Feb-05
Though we ask that the data be read from the user, it is also convenient to be able to read data from a file as well (especially for such a large example). Later in the course we will discuss the use of files, but for now we offer a quick trick using the Linux operating system. You would normally execute your program by typing the following at a command prompt:
The input, would then be entered by the user with the keyboard. You can instead start your program by typing the following command:stock
where 'GOOGmonth.dat' is an existing text file containing data in the described format (we will even provide you with such a file for the Google example). This command has the effect of "redirecting" the data from the specified file to the executing program, as if someone is transcribing it on the keyboard.stock < GOOGmonth.dat
At minimum, you must diagram the given data as follows:
The vertical axis should be used to reflect stock prices, specifically with higher prices higher on the screen, and lower prices lower on the screen. The horizontal axis should be used to reflect time, with data drawn from left to right chronologically.
At the leftside of the diagram, you must place two text labels designating the high and low range on the price scale of your drawing (e.g. the '220' and '175' in the Google example). >
Each day must be represented as a single blue rectangle, where the top and bottom extent of the rectangle accurately denote the high and low price for that day, respectively. >
Incorporating the other details diagramed in the example from the NYTimes are considered as extra credit.
One of the most challenging aspects of this assignment will be in appropriately mapping data to the graphical coordinate system. In particular, for EzWindows you must specify positions of objects measured in centimeters, and with a Y-axis which is oriented with zero at the top.
For your diagram, the Y-axis must represent stock prices, in the conventional manner with higher numbers drawn higher on the screen. Furthermore, we wish you to scale your vertical axis according to the given range of stock prices, and to scale your horizontal axis to reflect the number of days which are given.
You may pick whatever window size you feel is appropriate, but you must make sure that you can accurate diagram both the weekly and monthly versions of the Google example we are providing.
The most important design issue will be in deciding how you will map the data to the window's coordinate system. You will probably want to think about this on paper for a while before rushing to write code. Moreso, your diagram will presumably depend on the first two lines of input, namely the low/high price range specified by the first line of data which helps you calibrate your vertical axis, and the number of days specified on the next line of input which helps you calibrate your horizontal axis.
You may therefore choose to read that initial input from the user before creating your initial window. Then you should make sure to display the window and draw the two labels to designate the low/high marks on the vertical axis. Finally, each individual rectangle can be drawn immediately upon reading the data for that day.
Important Utility: You may have noticed that the low/high values are likely read into variables of type double. To create a "Label" object in EzWindows you must specify the desired text as a string object. We have not yet seen a way to convert a numeric value into the corresponding text string. For now, I will provide a utility for this purpose. Specifically, the source code contains a subroutine of the form:
string convert(double value)which takes a given value and returns the appropriate string (up to two decimal places).
We are providing the following three files for your use. You may either download from a browser or copy them directly to your current directory on turing with the comand:
cp -Rp ~goldwasser/csp125/programs/stock .
There are three files:
stock.cpp
To get you going, we have set up this file so that it includes
access to a variety of shapes from the EzWindow library.
What's missing is your code for reading and displaying the data!
Makefile
You should simply type make at
the command prompt and then your program will be compiled.
Either syntax errors will be displayed, or else the compilation
will be successful and an executable named stock will
be created which you can run.
GOOGmonth.dat, GOOGweek.dat
These two files contain sample data for Google, which you may
wish to use.
stock.cpp
This is the source code file.
Again, we also ask for you to estimate the amount of time you spent on the assignment, and to let us know of any difficulties you had or other issues you wish to discuss.
If you worked as a pair, please make sure that both names are given and that you discuss how you each contributed to the submitted work.
We have compiled more complete documentation on the EzWindows package for your use. We recommend that documenation as a primary resource.
In addition, you may wish to refer to the recent lab on EzWindows as well as Chapter 3.9 of the text. The text also contains rather detailed documentation in Appendix E.
The assignment is worth 10 points. If you worked as a pair, you will each be given the same grade.
In the previous assignment, you had great artistic license. For this assignment, accuracy in portraying the data is of greatest importance.
If you look at the NY Times diagram, you will see far more details provided. If you can replicate all of the following details, we will give 2 points of extra credit. If you get some of the extras but not all, we may choose to award 1 extra point.
In particular, take note of the following extras:
The horizontal axis is labeled with each date. In particular, it seems to use a convention where it only gives the date, however on the first of each month it instead gives the month. You might acomplish this by using the original form of the date (e.g. 17-Feb-05) and pulling it apart based on the available methods from the string library which we have seen. You'd also need to specially check for the case of the first of the month.
In the required part of the assignment, we asked that you label the specified high and low marks on the vertical axis. Add additional such labels in between.
You will notice that gray lines are drawn throughout the picture to mark the various grid positions. Though we don't have Gray in our box of colors, Black would probably suffice. You should draw the entire grid after reading in the number of days and the low/high price range, but before drawing the individual rectangles for each date (so that those rectangles will be drawn on top of the grid).
With each date, two additional data points are drawn. The "opening" and "closing" price for each day are denoted as horizontal dashes attached to each day's rectangle, with the opening price extending to the left, and the closing price extending to the right.
If you want to draw an additional extra not shown in the NY Times example, calculate metrics such as the "average" closing price and then draw a horizontal red line across the entire picture at the appropriate height for that average price.