CSCE 150A (Fall 2009) Homework 3
Assigned Monday, October 12
Due Wednesday, October 21
Total points: 100
When you hand in your results from this homework,
you should submit the following:
- The source code of your programs, in text files, named as specified
below in Problems 3–5.
- An optional
text file called README that contains any notes about your
programs that you want the graders to know.
- A single .pdf file with your writeup of the results for
all
homework problems.
Only pdf will be accepted, and you should
only submit one pdf
file, with the name username.pdf, where username is
your username on cse.
We will not accept any hard copy submissions of your
homework!
- Every problem requres a writeup in this homework. For Problems
3–5, you need to decompose each problem just like you did in the
previous homework.
Put your name in all your files, and submit everything by the
due date and time using the
web-based handin program.
On this homework, you must work on your own and submit your own results written
in your own words.
- (15 pts)
Consider the following variables:
int a = 10, b = 5, c = 15, flag = 0;
Evaluate the following expressions given the values above. Indicate which
parts of each expression (if any) are not evaluated due to short-circuiting.
- a == c – b || !flag
- c != –c || flag && c <= (b * a)
- !(a % c) && b >= 5
- (a > 10) || c < a + b
- !!a == 10 && c >= 15 || b
- (15 pts) Convert each of the following from English statements to
proper C statements.
- x is less than y and y is less
than z
- x is greater than y and x is less
than or equal to z
- x is false and y is not equal to z,
or z is not equal to 20
- x is equal to y or x is equal to 24
- x is less than or equal to y and
y is less than or equal to z
- (15 pts)
Write a program in file gas.c
that reports the contents of a compressed gas cylinder based on
the first letter of the cylinder's color. The program input is a character
representing the observed color of the cylinder: 'Y' or 'y' for yellow, 'O' or
'o' for orange, and so on. Cylinder colors and associated contents are as
follows:
orange | ammonia |
brown | carbon monoxide |
yellow | hydrogen |
green | oxygen |
Your program should respond to input of a letter other than the first
letters of the given colors with the message:
Contents unknown
- (25 pts)
A music store needs a program to implement its music teacher's discount policy.
The program in file music.c
is to prompt the user to enter the purchase total and to indicate
whether the purchaser is a teacher. The store plans to give each customer a
printed receipt, so your program is to create a nicely formatted file called
receipt.txt. Music teachers receive a 10% discount on their sheet
music purchases unless the purchase total is $100 or higher. in that case, the
discount is 12%. The discount calculation occurs before addition of the 7%
sales tax. Your program should
use functions to display instructions to the user and to compute the discount,
if any. Here is a sample output, for a teacher.
Total purchases | $122.00 |
Teacher's discount (12%) | 14.64 |
Discounted total | 107.36 |
Sales tax (7%) | 7.52 |
Total | 114.88 |
Here is a sample output, for a nonteacher.
Total purchases | $24.90 |
Sales tax (7%) | 1.74 |
Total | 26.64 |
- (30 pts)
Write a program in file bread.c
to control a bread machine. Allow the user to input the type of
bread as 'W' for white and 'S' for sweet. Ask the user if the loaf size is
double and if the baking is manual. The following table details the time chart
for the machine for each bread type. Display a statement for each step. If the
loaf size is double, increase the baking time by 50 percent. If baking is
manual, stop after the loaf-shaping cycle and instruct the user to remove the
dough for manual baking. Use functions to display instructions to the user and
to compute the baking time.
Operation | White Bread | Sweet Bread |
Primary kneading | 15 mins | 20 mins |
Primary rising | 60 mins | 60 mins |
Secondary kneading | 18 mins | 33 mins |
Secondary rising | 20 mins | 30 mins |
Loaf shaping | 2 seconds | 2 seconds |
Final rising | 75 mins | 75 mins |
Baking | 45 mins | 35 mins |
Cooling | 30 mins | 30 mins |