Sie sind auf Seite 1von 6

Ryerson University

Faculty of Enginering, Architecture & Science


CPS118 - Introductory Programming for Scientists
Final Exam
Fall 2007
Duration: 120 minutes
Last Name: _____________________

First Name: ______________________

Student #: _____________________

Signature: _______________________

Please circle your instructor's name:


Ding

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.

Do not open the test until instructed


FOR OFFICE USE ONLY:

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];

_________________________________________

c) double mat[10][10]; _________________________________________


d) #define N 1.32

_________________________________________

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);

___________

CPS118 Final Exam Fall 2007 - 2

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);
}

______________________________
______________________________

CPS118 Final Exam Fall 2007 - 3

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[])
{

CPS118 Final Exam Fall 2007 - 4

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 (
{

CPS118 Final Exam Fall 2007 - 5

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.

CPS118 Final Exam Fall 2007 - 6

Das könnte Ihnen auch gefallen