SI 204 Spring 2017 / HWs


This is the archived website of SI 204 from the Spring 2017 semester. Feel free to browse around; you may also find more recent offerings at my teaching page.

Homework 13: EOF

Name: _____________________________________________ Alpha: ___________________

Describe help received: ________________________________________________________

  • Due before class on Friday, February 10
  • This homework contains code to be submitted electronically. Put your code in a folder called hw13 and submit using the 204sub command.
  • This is a written homework - be sure to turn in a hard-copy of your completed assignment before the deadline. Use the codeprint command to print out your code and turn that in as well.

Assignment

  1. Circle one to indicate how you did for the reading assignment from Homework 11 before class on Monday:

    How carefully did you complete the reading? (Circle one)

    Not at all
    Skimmed it
    Read some
    Read all
  2. Circle one to indicate how you did for the reading assignment from Homework 12 before class on Wednesday:

    How carefully did you complete the reading? (Circle one)

    Not at all
    Skimmed it
    Read some
    Read all
  3. Required reading for this homework: Section 5 (Odds & Ends) from the Unit 4 notes,
  4. Given the following code snippet:
    double dog = 8.7;
    int bear = dog + 2;
    double* cat = &dog;
    dog += 3;
    bear += 4;
    *cat += 5;

    Fill in the following table with the type and value of each expression after executing the code above.

    expressiontypevalue
    dog
    bear
    *cat
    XXX

    Fill in the following table with the type only of each expression, and indicate "yes" or "no" whether each one is an "lvalue", meaning it could be used on the left-hand-side of an assignment statement.

    expressiontypeis lvalue?
    &bear
    bear + dog
    cat
    *cat
    *cat + 7
  5. Write a program called sum.c that reads in the name of a text file, then reads that file and adds up all the numbers in that file, reporting their total sum to stdout.

    For example, if numbers.txt consists of:

    1.1
    15
    23.7
    6

    then your program should run as:

    Filename: numbers.txt
    45.8

    Your program must not use si204.h; instead you should include only the standard header file <stdio.h>.