Assessment Tool

Lecture 3:  Variables, Values, and Types

Content Tested:  Writing a simple program

Lecture Content:

Goals:

Assessment Technique:  Programming Activity

Purpose:

This planning and programming activity serves to emphasize the differences between the problem, algorithm, and programming stages of the programming process as well as encourage students to think about types of variables.

Activity:



We just saw a program to calculate a Celsius temperature given a Fahrenheit temperature.  Your friend from England tells you that it is 30 degrees Celsius in her hometown today.  Your friend tells you the temperature on a weekly basis, so you want to write a C program to do the conversion from Celsius to Fahrenheit.  Before writing the code, remember the important parts of the programming process:  Problem Description, The Algorithm, Writing the Code, and Testing the Code.  Fill in the pieces below.

Problem Description:  Define precisely what your program calculates, the input, and the output.
 
 

The Algorithm:  This stage of the process requires you to think about how you'll solve the problem above (independent of a programming language).  Recall that we used the following formula to calculate Celsius (C) from Fahrenheit (F):  C = (5/9) (F - 32)
 
 
 
 
 
 

The Program:  Write the program in C.  We have provided the template for the program.

#include <stdio.h>

/*  Comments:
 
 
 
 

 */
int main(void){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

    /* terminate the program */
    return 0;
}



Possible C code:
 

#include <stdio.h>

/* This program prompts the user to enter a temperature in Celsius and reports the equivalent temperature in Fahrenheit
*/
int main(void){

    double fahrenheit, celsius;

    /* prompt user for Celsius temperature */
    printf("Enter a Celsius temperature: ");
    scanf("%lf", &celsius);

    /* convert celsius to fahrenheit */
    fahrenheit = 32.0 + (9.0/5.0) * celsius;

    /* print Fahrenheit temperature */
    printf("That equals %f degrees Fahrenheit.", fahrenheit);

    /* terminate the program */
    return 0;
}

Possible mistakes:
Students might use %f instead of %lf in the scanf conversion code.
The calculation for fahrenheit might be wrong.

Possible Uses of Activity: