Part 0  (preparation)
  • Copy the following files from /u/cs126/files/stock/ to an empty directory:
    readme         stock1000.txt     stock11.txt     stock15.txt     
    stock9.txt     stock25.txt       buy.txt         sell.txt
    
    You may do this with the following command:
    mkdir stock                        # make a new directory
    chmod 700 stock                    # set permissions
    cd stock                           # move to that directory
    cp /u/cs126/files/stock/* .        # copy all files to current directory
    
    Do not type the human annotations in the right column, but be sure to leave a space between the * and the . in the last command.

  • Carefully follow the instructions for Part 0 in the assignment.

  • Part 1   (plot)

  • To print the right number of *'s you will probably want to use a while or for loop. This does not require any advanced techniques that haven't been covered (e.g., calling a "round" function or "casting"). Instead, design your for loop directly so that it will get the number of *'s correct.

  • Remember that you can create variables to help you keep track of information. For example, it will probably be useful to have a variable that keeps track of how many asterisks you've printed. (Don't forget to reset this variable to 0 for each stock price.)

  • Check your program carefully by creating some simple data files. In the beginning, you may even want to test your program on files that contain only a single value (so that you have just one line of asterisks to count.) To create a test data file, you can use emacs.

  • Part 2    (detect a pattern)

  • Dilbert's rule applies only after 3 consecutive strict increases or decreases - if the price remains the same, Dilbert's rule will not apply for at least 3 more periods.

  • This will be the most difficult part of the assignment, and you'll probably end up using nested if-else statements. Make sure you understand how to do this before beginning, e.g., carefully read the relevant sections in the King textbook.

    Before you attempt to write any C code, first think out the logic of your program and write pseudocode. Which extra variables will you need in order to keep track of the stock's current trend?  one solution

  • Don't accidentally use "if (x = 1)" when you mean "if (x == 1)". The former assigns the value of 1 to variable x; the latter evaluates to true if x already has the value 1.

  • Part 3    (invest)

  • Your output formatting does not have to exactly match the one given in the course packet, but the output should be neatly aligned using printf().

  • One common bug to watch out for is the one that results in 'value' being set to 0. As long as the price is never 0 (which it won't be), you should never lose all of Dilbert's money. The trick to solving this problem is to think about why the value was set to 0. What did Dilbert do at that moment? buy? sell?



  • Written by Lisa Worthington and Kevin Wayne