CSC 111: Fundamentals of Programming
with Engineering Applications
Midterm Exam #1
Sections: A01 (CRN: 10737), A03 (CRN: 10738)
Date: Monday, October 6th, 2025
Instructors: Anthony Estey
Duration: 50 minutes
Students must check the number of pages in this examination paper before beginning
to write, and report any discrepancy immediately.
•
•
•
•
•
•
•
•
We will not answer questions during the exam. If you feel there is an error or ambiguity,
write your assumption and answer the question based on that assumption.
Answer all questions on this exam paper.
The exam is closed book. No books, notes or electronic devices are permitted.
The marks assigned to each question and to each part of a question are printed in bold
within square brackets (for example: [5 marks]). Partial marks are available.
There are eight (8) pages in this document, including this cover page.
Clearly indicate only one answer to be graded. Questions with more than one answer will
be given a zero grade.
It is strongly recommended that you read the entire exam through from beginning to end
before beginning to answer the questions.
Please have your ID card available on the desk or with you when you hand in the exam.
Part 1: Expression Evaluation [8 marks]
1. Consider the following syntactically correct C declarations below:
int a = 3;
int b = 8;
int c = 15;
double x = 15.0;
Complete the table by providing the value produced by each of the following syntactically
correct expressions. An example is provided for you in the top row.
Expression
Result
a + b
11
b%a
2
b - a
5
b > a
1
b != a
1
c/a
5
c%a
0
c - a
12
x - a
12.0
(This space is intentionally left blank. Use it for your memory trace if you wish)
Part 2: Memory Tracing [16 marks]
2. What is the output of the syntactically correct C program below?
#include <stdio.h>
int add(int a, int b) {
int c = a + b;
return c;
}
void multiply(int a, int b) {
int c = a * b;
}
int main(void) {
int a = 2;
int b = 3;
int c = 4;
add(a, b);
printf("%d %d %d\n", a, b, c);
a = add(a, b);
printf("%d %d %d\n", a, b, c);
b = add(a, c);
printf("%d %d %d\n", a, b, c);
multiply(a, b);
printf("%d %d %d\n", a, b, c);
return 0;
}
Write your answer in this box. [8 marks]
2 3 4
5 3 4
5 9 4
5 9 4
3. What is the output of the syntactically correct C program below?
#include <stdio.h>
int main(void) {
int i;
int j;
int k;
j = 5;
k = 10;
for (i = 1; i < 5; i++) {
if (i < j) {
j--;
} else {
k--;
}
k += j;
printf("%d %d %d\n", i, j, k);
}
return 0;
}
Write your answer in this box. [8 marks]
1 4 14
2 3 17
3 3 19
4 3 21
Part 3: Fill in the blanks [11 marks]
4. Assume you have two variables, battery_level and limit. Complete the code below to
output “Low Battery!” if the current value of battery_level is below the limit.
battery_level < limit
if (
) {
printf("Low battery!\n");
}
5. Complete the for loop in the code below so that it outputs: "1 2 3 go!".
int i;
i = 1; i <= 3; i++
for (
) {
printf("%d ", i);
}
printf("go!\n");
6. The code below attempts to do you a defined constant to convert from miles and to
kilometers, and then output the result rounded to 2 decimal places. There are 1.6 kilometers
per mile. Define a constant and then complete the printf statement.
#define KM_PER_MILE 1.6
void convert_miles_to_km(double miles) {
double km;
km = KM_PER_MILE * miles;
printf("
%.2f
km\n", km);
}
7. Complete the code so that it uses an accumulator to sum all numbers from start to end and
returns the final sum. For example, if start is 2 and end is 6, it returns 20 (2+3+4+5+6).
int sum;
int i;
sum = 0;
for (i = start; i <= end; i++) {
sum += i;
}
return
sum;
Part 5: Function Design [20 marks]
Over the next few questions, you will provide different steps of the function design process.
8. Design a function to calculate and return the distance traveled by an object. The function
takes two floating-point values: a velocity in meters/second and the time it traveled at that
velocity in seconds.
Write the function prototype in the space provided below: [4 marks]
double get_distance_traveled (double velocity, double time);
Write the function documentation in the space provided below: [3 marks]
/**
* @brief Calculates and returns the distance traveled by an object
*
given its velocity and time traveled
* @param velocity the speed in m/s as a double
* @param time the number of seconds traveled as a double
* @return the distance in meters the object traveled as a double
*/
9. Provide a full function design for a function named calculate that takes two integers and
returns two times the larger of the two minus the smaller of the two.
Examples:
- calculate(8,5) and calculate(5,8) both return 11, since 2(8) − 5 = 11.
- calculate(4,4) returns 4, since 2(4) − 4 = 4.
- calculate(3,15) and calculate(15,3) both return 27, since 2(15) − 3 = 27.
Write the function definition in the space provided below: [8 marks]
/**
* @brief Returns two times the largest input value minus the other
* @param a the first integer to use in the calculation
* @param b the second integer to use in the calculation
* @return two times the largest value minus the other as an integer
*/
int calculate(int a, int b) {
int result;
if (a >= b) {
result = (2*a)-b;
} else {
result = (2*b)-a;
}
return result;
}
10. You have been asked to design a function to calculate bus fare for passengers based on their
provided age. The cheapest fare is for youth who are under 18. The second cheapest is for
seniors who are 65 or over. The standard fare is for everyone in between. What age values
would you pass to the function to comprehensively test it?
List the values you would pass to the function to test it in the box below.
Write your answer in this box. [5 marks]
cheapest
standard fare
18
2nd cheapest
65
We want to make sure we test all three fare age ranges, and also
the boundary conditions (18 and 65). That means at least 5 tests,
but I would probably test around each boundary condition, and
test with the following values:
17, 18, 19, 64, 65, 66 (although 19 and 64 test the same range)
… Left blank for scratch work…
Question
Value
Part 1: Expression Evaluation
8
Part 2: Memory Tracing
16
Part 3: Fill in the blanks
11
Part 4: Function Design
20
Total
55
END OF EXAM
Mark