# 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 04: Expressions and Types

Name: _____________________________________________ Alpha: ___________________

• Due before class on Friday, January 20
• This homework contains code to be submitted electronically. Put your code in a folder called hw04 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 3 before class on Wednesday:

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

Not at all
Skimmed it
2. Assume the following declarations:
int n = 5;
double x = 1.5;
char c = 10*n + 2;

Fill in the following table with the type and value of each expression:

 expression type value n + x n/2 n = x c int(c)
3. Write a program lengths.c that reads in two lengths in the format x' y'' (i.e. x feet y inches) and returns the difference in length between the two in the same format. You may assume that the first is always larger than the second!

A typical run of your program should look like this (user input shown in green):

roche@ubuntu$./lengths Enter two lengths in feet and inches (larger first!) 32' 6" 15' 11" Difference is 16' 7" Submit the file lengths.c using 204sub command. In addition, use the codeprint command to make a PDF of your file, print it out on paper, and include that with what you turn in (stapled together). • Hint 1: First work on getting your program simply read the four measurement values, then work on getting it to print out the difference in inches, then work on getting the difference in feet and inches. • Hint 2: The string constant "'" works just fine, but to get the character constant of the apostrophe you must write '\'', which uses the backslash as an escape character. • Hint 3: For ideas on how to chop a length in inches into feet and inches, look at the Minutes and Seconds program, which has to deal with the similar problem of chopping a time in seconds up into minutes and seconds. 4. Write a program that reads in a 3-letter word in lowercase and prints out the same word with the first letter capitalized. A typical run of your program should look like: $./capitalize
Input word : cat
Capitalized: Cat

Submit the file capitalize.c using 204sub command. In addition, use the codeprint command to make a PDF of your file, print it out on paper, and include that with what you turn in (stapled together).