MTRN2500 has two possible prerequisite courses: COMP1531 and COMP2521. COMP1511 is also a relevant course that is not technically a prerequisite; note that it is a prerequisite of COMP1531/COMP2521 and is a requirement of the mechatronics (MTRNAH) engineering major.
Revision questions specifically related to C (taught in COMP1511) are also included — however, most C-specific concepts will be revisited in the course (albeit at a faster pace and in context of learning C++).
Programming Fundamentals
- Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.
Sample output:
1
2
Fizz
4
Buzz
...
No answers here :)
- Complete the following function which returns the sum of all the elements squared in a given array. The function should have the following signature (choose the language you are most comfortable with):
// C
int sumSquares(int arr[], int length);
// JavaScript/TypeScript
function sumSquares(arr: number[]): number;
# Python
def sumSquares(arr: List[int]) -> int:
// C++
int sumSquares(std::vector<int> arr);
No answers here :)
- Write a function that returns the third largest element in an array/list of integers. You may assume that the array/list has at least 3 elements. The function should have the following signature (choose the language you are most comfortable with):
// C
int thirdLargest(int arr[], int length);
// JavaScript/TypeScript
function thirdLargest(arr: number[]): number;
# Python
def thirdLargest(arr: List[int]) -> int:
// C++
int thirdLargest(std::vector<int> arr);
No answers here :)
C
- What steps are required in order to run a C program.
No answers here :)
- Which of these variables have valid names?
int V3RX;
int var;
int 3var;
int _3;
int __var;
No answers here :)
- What is a pointer? What is a memory address?
No answers here :)
- Complete the following function:
void swap(int *a, int *b) {
// TODO: implement a function that swaps the values at addresses a and b
}
No answers here :)
- What is the difference between stack and heap memory? How would you allocate memory on the stack or heap?
No answers here :)
- What is an array? How would you declare an array on the stack and on the heap?
No answers here :)
- What is a struct?
No answers here :)
- What is a linked list?
No answers here :)
- What is ASCII?
No answers here :)
- Identify code which has bad style. Explain how this could be improved.
#include <stdio.h>
#define CONST 10
int main(){
int VAR=3 *CONST;
printf("%d\n", VAR);
VAR = 4;
printf("%d\n", VAR);
}
No answers here :)
-
Usually array indexing would be done like
arr[i]. Explain why this code works as well?
int arr[4] = {42, 52, 62, 72};
for (int i = 0; i < 4; i++) {
printf("%d\n", i[arr]);
}
No answers here :)
- What is the difference between a compiler warning and error?
No answers here :)
Git Commands
- Create a git repository.
No answers here :)
- Clone an existing git repository.
No answers here :)
- Show the status of the repository.
No answers here :)
- Stage changes for commit.
No answers here :)
- Commit changes.
No answers here :)
- Checkout to a branch
No answers here :)
- Merge a branch into the current branch.
No answers here :)
- Push changes to a remote repository (e.g. GitHub or GitLab)
No answers here :)
- Amend the last commit message.
No answers here :)
- Check the changes that have been made but not yet committed.
No answers here :)
- Show the commit history.
No answers here :)
- Reset to a previous commit.
No answers here :)
- Reset the git history to a previous commit but keep the current code.
No answers here :)