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:

  1. The source code of your programs, in text files, named as specified below in Problems 4 and 5.
  2. A text file called README that contains any notes about your programs that you want the graders to know.
  3. 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.


  1. (20 pts) For each variable below, indicate if it is syntactically correct. If it is not, indicate why it is not a valid identifier.

  2. (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;
    }
    
  3. (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().

  4. (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.

  5. (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.