Beruflich Dokumente
Kultur Dokumente
Student #: _____________________
Signature: _______________________
Hamelin
Timorabadi
Instructions:
-> All communication devices must be turned off and left in bags at the
front of the room.
-> The test has a duration of 120 minutes. Stop writing and put down your
pen when instructed.
-> Calculators and other aids may not be used.
-> Have your photo ID visible at all times during the examination.
Total
33
CPS118 Final Exam Fall 2007 - 1
Question 1 (5 marks):
Describe what is being declared by each of the following
statements:
a) char name[30];
_________________________________________
b) int mix[100];
_________________________________________
_________________________________________
e) char mnt[5][20];
_________________________________________
Question 2 (5 marks):
Given the declarations below, write what is displayed after each
operation is completed.
int a=2, b=3, c=4, d;
double z=10.0, y=-10.0, x=50.0, w=-1.0, v;
a)
b)
c)
d)
e)
v = (a % b) + y;
printf (%5.2f, v);
___________
d = a + b * c 10;
printf (%d, d);
___________
d = (a + b) * (c 10);
printf (%d, d);
___________
v = c / 10 b - z;
printf (%5.1f, v);
___________
d = a + b * c % 13 + x;
printf (%d, d);
___________
Question 3 (6 marks):
In space provided below, write the output of the following
program as it appears on standard output (screen).
#include <stdio.h>
typedef
{
int
int
int
}date;
struct date
month;
day;
year;
date
func (date x, date *y)
{
++x.month; ++x.day; --x.year;
y->year = y->year + 1;
return (x);
}
int
main (void)
{
date a, b;
a.month=2; a.year=2000; a.day=12;
b.month=3; b.year=2002; b.day=21;
a = func (a, &b);
printf (%d/%d/%d\n, a.month, a.day, a.year);
printf (%d/%d/%d\n, b.month, b.day, b.year);
return (0);
}
______________________________
______________________________
Question 4 (6 marks):
Complete the following function that takes in a string and
reverses it (ex: ryerson becomes nosreyr).
void
reverse (char before[], char after[])
{
Question 5 (6 marks):
Complete the following function that takes in a double value
representing a temperature in degrees. The function will
"return" a string containing the words "ICE" if temperature is
below zero, "WATER" if temperature is 0 to 100 degrees (i.e.
0<= temperature <= 100), and "STEAM" if temperature is above
100 degrees. The string must be send back to the main program,
not printed out in the function.
void
h2o (
{
Question 6 (5 marks):
Write a complete C program that asks a user for the name of a
city and prints out the first three letters all in uppercase.
For example, if the user enters Toronto, the output would be
TOR.
Note: the toupper function from the ctype.h library transforms
a lowercase character into an uppercase charecter.