CSCE 150A (Fall 2009) Homework 1
Assigned Monday, September 14
Due Monday, September 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 4 and 5.
- A 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 that require a writeup (Problems
1–3).
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!
See
"Help on Creating PDF Files"
for more on building PDF files.
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.
- (20 pts)
For each variable below, indicate if it is syntactically
correct. If it is not, indicate why it is not a valid
identifier.
- BabyImA*
- Supercalifragilisticexpialidocious
- family guy
- r2d2
- huskers#1
- 30Rock
- StEwIe
- int
- Bo's
- x,y
- (20 pts)
There are four errors in the program below.
Identify and fix all four problems.
/* This program reads a number
* and outputs its square
#include<stdio.h>
int main(void)
{
double a = 0.0, b = 0.0;
printf("Please enter a number: ")
scanf("%lf", a);
b = a * a;
printf("The square of %d is %f\n",a,b);
return 0;
}
- (20 pts) Indicate if each of the following are valid C
declaration/assignment statements or not. For each one,
answer valid or invalid. Assume each statement
is the first one of function main().
- int char = 10;
- int Peter = 120
- double first = second = 1.0;
- double x = (double) '\n';
- double pi = 3.14159;
- char myChar = "a";
- char 'z';
- integer Lois;
- double x, tmp = 1.0, z;
- double f(x) = 2*x;
- (15 pts) Write a complete program in a single source file called
kelvin.c that prompts the user for a temperature in
degrees Fahrenheit (f), reads in this value from standard input,
converts the value to degrees Kelvin (k) and writes the result
to standard output, with an appropriate message. To convert from f to
k, use the formula
k = 273 + (f – 32) / 1.8.
- (25 pts)
Write a complete program in a single source file called calculator.c
that prompts the user for the price of two items purchased,
computes the total of the sale, computes the sales tax (at a rate of
7%), and finally computes the total of the sale and the tax, rounded to the
nearest cent. The program
should read from standard input and write to standard output, and use
appropriate prompts. Below is an example interaction between the program and
user.
2-ITEM SALES CALCULATOR
Enter price of item 1 --> 23.45
Enter price of item 2 --> 16.90
Your total without tax is $40.35.
At 7% tax rate, your total is $43.17.
Back
Last modified 16 August 2011; please report problems to
sscott.