Assessment Tool
Lecture 3: Variables, Values, and Types
Content Tested: Writing a simple program
Lecture Content:
-
Variables
-
Declarations
-
Identifiers and Reserved Words
-
Types
-
Expressions
-
Assignment Statement
-
Variable Initialization
Goals:
-
Ability to synthesize and integrate information
-
Learn concepts and theories
-
Develop capacity to think for oneself
-
Develop ability to think creatively
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:
-
Have students work in groups to come up with the algorithm and then write
the program as a class (since the students will have little experience
with the syntax).
-
Break students into small groups (2-4 people) and have each group work
on the activity. Encourage one or more groups to present their solution
to the rest of the class (If groups write their code on transparency slides,
showing the class the code is very easy since it eliminates the time for
writing code on the blackboard or on a blank slide on the overhead projector.)
If the instructor sees an error in the program, point it out and ask the
rest of the class how one might fix the error and its type (syntax vs.
semantic).