SYSC2006 Sample Midterm 2023
SYSC2006 Sample Midterm 2023
SECTION A-B-C
PAPER VERSION
Instructions:
• Do NOT draw or write on the bar codes at the top/bottom of the exam pages.
• This is a closed-book exam.
• Calculators are NOT permitted.
• All electronic devices (tablets, laptop computers, cell phones, smart watches, headphones, etc.)
must be placed under your chair or left in your backpack or purse. You are not allowed to have
any electronic device on your person.
• This exam is 100 minutes long.
• The exam is worth 20 marks in total.
• Attempt all questions.
• Use the pages labeled “rough work” for rough work. The “rough work” pages will not be
graded.
• You are not allowed to remove any pages from your exam. It is an academic offense to remove
any pages of the exam from the exam room.
• Do not ask questions unless you believe that you have found a typo.
• Record your answers to the MCQs on the bubble sheet at the end of the exam. Answers
recorded on the question paper will not be graded.
Be sure you are writing this exam in your assigned room. Not writing in your assigned room will
result in a 5-mark penalty.
Be sure that you have clearly written your name and student number on the first page. Not including
your name or student number on this paper will result in a 5-mark penalty.
Be sure that you have clearly filled the bubbles for your student number on the first page. Not
filling in the bubbles or incorrectly filling in the bubbles will result in a 5-mark penalty.
All rights reserved: No part of this document may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, electronic, mechanical, photocopying, recording, or
otherwise, without prior written permission from the instructor.
SECTION 1 – Multiple choice (…/4.5)
This section contains 16 multiple-choice questions. Each question has one correct answer. Record your
answers on the Bubble sheet at the end of the exam using the answer spaces 001-016. For each
question, fill in (shade) the circle (A, B, C, D, or E) that corresponds to the correct answer. Answers
recorded on the question paper will not be graded.
• Fill in (shade) the answers firmly and neatly, preferably with a dark pencil.
• Completely erase any changed answers
• Do NOT tear the bubble sheet.
int z = x - *py;
A. It assigns 2 to z.
B. It assigns -8 to z.
C. It assigns an unknown value (that is, a value we cannot determine) to z.
D. It causes a compilation error.
typedef struct {
int id;
int year;
char GPA;
} student_t;
...
A. 1111111
B. The entire struct stored in the variable student_carleton.
C. The address (location in memory) of the variable student_carleton.
D. The address (location in memory) of member id in the variable student_carleton.
Q3. Given the following code snippet, what is the returned value of the function f when it is called
in main?
int main(void){
int y = 7;
double x= 1.5;
int z = f(x, y);
return 0;
}
Select the correct statement:
A. Function f returns 7
B. Function f returns 8.5
C. Function f returns 8
D. Function f returns 9
E. This program terminates with a run-time error because the function cannot add an int and a double.
Q4. What value will x contain after this code fragment is executed?
int *px, x;
x = 5;
px = &x;
x = x + 3;
x = (*px) + 1;
A. 9
B. 8
C. 7
D. 6
E. 5
Q5. What is the size of my_array after the preprocessing step of compilation?
int main() {
int my_array[2 * SIZE];
return 0;
}
A. 10
B. 7
C. 40
D. 28
Q6. This question deals with a function that is intended to return the maximum of the first n integers
in an array.
Q7. This question deals with a function that is intended to return the maximum of the first n integers
in an array.
Q8. This question deals with a function that is intended to return the maximum of the first n integers
in an array.
int find_max_v3(int *arr, int size) {
int max = *(arr+1);
for (int *p = arr+1; p < arr+size; p++) {
if (*p > max) {
max = *p;
}
}
return max;
}
A. This function returns the correct result.
B. This function returns an incorrect result.
C. This function causes a compilation error.
D. This function may cause the program to terminate with a run-time error.
Q9. This function is intended to return the maximum of the first n integers in an array recursively.
Q1. What is the value stored in the variable result just before the return statement in main
function? Just enter the number, for example, 12334.
int main() {
int a = 8;
int b = 2;
int result = do_this(a,&b);
return 0;
}
Q2. What is the output of this program? You need to type the exact output for marks.
int main(void){
int x = 10;
int y = *f(f(&x));
printf("%d %d\n", x, y);
return 0;
}
int main(void){
char a[] = "FUN";
mystery('F', 'A', a);
return 0; //LINE B
}
(a) [3.5 marks] Draw a memory diagram similar to one that would be produced by the C Tutor
immediately after Line A has been executed for the second time, that is, immediately before
the statement, return mystery(original, replace, word+1); is executed for the second
time.
Stack Heap
b) [1 mark] Draw a memory diagram similar to one that would be produced by the C Tutor
immediately before the statement at Line B has been executed, that is, immediately before the
main function returns.
Stack Heap
SECTION 4 – Programming Question (…/10)
The Problem
You decide to create a software to help students keep track of their progress throughout their university
studies and calculate their CGPA.
For each student, you need to store Name, ID, CGPA, Year the student is in, and Number of courses
the student has taken.
Sample Output
Implementation Requirements
• Assume you have a folder that contains the following files:
o data_structures.h – defines the data structure you must use to record the data of each student.
o functions.h – contains the declarations of the functions you must implement. Refer to the
comment at the top of each function for more details on what is the expectation of each of these
functions.
▪ IMPORTANT:
- The function prototypes and names must be used exactly as in the provided file. All these
functions must be used in your solution.
- You are allowed to create extra functions as long as they complement the required ones,
not replace them. New function declarations must go inside functions.h
o functions.c – contains the definitions (implementations) of the functions listed in functions.h.
o main.c – contains the main function of your program. There should not be any functions
declared or defined in this file other than main() function.
▪ IMPORTANT: Refer to the comments in the provided “main.c” for the explanation of
what to implement in the main() function.
• Your solution should go in the provided four files. You are not allowed to create extra files.
• You are not allowed to modify any of the functions’ declarations/prototypes. The code you are not
allowed to modify is highlighted with “/********** DON'T MODIFY **********/”.
• You have to write the program in C language (not C++). Do not use any C++ elements. Examples
of C++ elements:
▪ #include <iostream>
▪ using namespace std;
▪ …
• Global variables are forbidden.
• Your constants must be defined using the #define preprocessor directive.
• All .h files must have appropriate header guards.
• You have to properly assign data types based on what is needed (for example, you should use a
float if your variable contains a decimal point).
• You should add comments to your code where needed.
• Do not use anything that we have not discussed up to this point in the material. You are only
allowed to use what you learned from Lecture 1 to Lecture 12. No use of dynamic memory
allocation.
• Make sure that your solution adheres to the implementation requirements. If you fail to follow the
implementation requirements, you will lose marks.
• At 8.50 p.m., you need to stop writing and return this exam paper to the instructor/TA. The time
from 8.50 p.m. until 9 p.m. is for the students who are writing on their laptops to zip their files and
submit. (this timing may be different if you are a PMC student).
File data_structures.h
File functions.h
/*
Updates the student’s data as follows:
- Calculate the new CGPA by averaging the grade in all new courses
taken by the student (function’s input parameter). Use the following
for each grade letter’s number of points A:4, B:3, C:2, D:1, F:0.
Then, update the student's CGPA by taking the average of the
previous CGPA and the newly calculated one
- For each new course where the course grade is not F, increase the
number of courses taken by 1
- Update field year based on the number of courses taken.
- The function must be implemented using a "for" loop. Solutions with
a "while" loop will receive a zero for this function.
*/
void update_student_data(student_t *student_details,
char *courses_grades, int num_courses);
/*
Return the year the student is in based on the number of courses they
have taken
- 1st year (up to 10 courses)
- 2nd year (from 10 (included) up to 20 courses)
- 3rd year (from 20 (included) up to 30 courses)
- 4th year (30 or more courses)
*/
/*
Output a student's details in a table format.
- You must use the dereferencing notation for accessing the members of
the structure.
- You are not allowed to use (->) operator Solutions this operator
Will receive a zero for this function.
- Refer to the sample output for more details
*/
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
File functions.c
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
Continue your solution here
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
File main.c
/********* main.c ********
// Includes go here
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
int main()
{
/* DON'T MODIFY THESE VALUES*/
char student1_grades[] = {'A', 'C', 'D', 'B', 'F', 'A'};
char student1_name[] = "Optimus Prime";
int student1_id = 1234567890;
int student1_courses_taken_so_far = 7;
char student2_grades[] = {'C', 'A', 'A', 'B', 'C', 'A', 'C', 'B', 'D', 'A'};
char student2_name[] = "Bumblebee";
int student2_id = 1234567891;
int student2_courses_taken_so_far = 11;
/* DON'T MODIFY THESE VALUES*/
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
// 3- For each student, set each the number of courses taken using the
// values above and update the year accordingly.
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
}
Rough Work