Art Show | Course Home | Homework | Labs | Programming | Schedule & Lecture Notes | Submit

Saint Louis University

Computer Science P125
Introduction to Computer Science

Michael Goldwasser

Spring 2005

Dept. of Math & Computer Science

Programming Assignment 03

Stock Price Graph

Due: Wednesday, 2 March 2005, 8pm
Friday, 4 March 2005, 8pm

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.

Collaboration Policy

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.


Contents:


Overview

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.


Data Format

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 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:

stock
The input, would then be entered by the user with the keyboard. You can instead start your program by typing the following command:
stock < GOOGmonth.dat
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.


Minimum Requirements

At minimum, you must diagram the given data as follows:

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.


Our Advice

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).


Files You Will Need

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:


Files to Submit


Brief Documention on EzWindows

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.


Grading Standards

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.


Extra Credit (up to 2 points)

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:

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.


Michael Goldwasser
CS-P125, Spring 2005
Last modified: Friday, 04 March 2005
Art Show | Course Home | Homework | Labs | Programming | Schedule & Lecture Notes | Submit