Reminder

  • If you haven't done so already, please fill out the COS 126 student survey. It will only take a minute. Otherwise your name will not get entered in our database, and you will not receive a grade in this course.

  • Goals

    The goal of this "assignment" is to make sure that you can

  • Read data from stdin.

  • Use loops (for, while).

  • Use branches (if, else).

  • Unix tip of the week

    The shell is the program that interprets your Unix commands. The shell tcsh has many nice features that will make using Unix easier. If you are a new Unix user, change your shell with the following command

    chsh
    
    You will be instructed to enter your Unix password. Then it will prompt you to enter your new shell. Carefully type
    /usr/princeton/bin/tcsh
    
    This will enable the following features:

  • The backspace key will work properly.

  • Use the up-arrow key to recall previous commands.

  • Use the Tab key to complete filenames. For example, instead of typing "gcc alongfilename.c", simply type "gcc alo<Tab>" and the shell will automatically complete the filename for you.

  • Part 0  (preparation)
  • Copy the following files from /u/cs126/files/stock/ to an empty directory:
    stock10.txt   stock1000.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
    

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

  • Your compiler may give you the following warning message:
    file.c:7: warning: missing return value
    
    It is safe to disregard this compiler warning (and this one only). The C standard, which was instituted in the late 1980s, requires that we say "int main(void)", but not everyone pays attention to that. Some say that death and destruction will ensue unless everyone uses the standard; others prefer a more laissez-faire attitude that saves programmers from typing useless jargon. The new C standard (C99) will require the extra jargon, so you might as well get used to it.

  • Part 1   (plot)

  • To print the right number of *'s you will probably want to use a 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.

  • The correct output appears in the on-line version of the assignment. It differs slightly from the version in the Spring 2000 course packet.

  • 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 Deitel-Deitel Section 3.6.

    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.

  • The final line of output for stock1000.txt is:
    1000   103.500       0.00     109.46   11329.18
    
    Here is the complete output.

  • Submission
  • Use the following submit command:
    /u/cs126/bin/submit 1 plot.c pattern.c invest.c readme
    
    Do not use different file names. All your files should include your name and precept number.

  • The readme file should contain:

  • Your name and precept number.

  • A high level description of your program and your approach to solving it. There is no need to regurgitate the statement of the assignment.

  • Describe any problems you encountered in completing the assignment. List whatever outside help (if any) that you received.

  • Enrichment Links

  • You can also test your code on real data from NASDAQ.



  • Kevin Wayne