0% found this document useful (0 votes)
173 views8 pages

CS 115 Midterm Exam Sample Questions

The document is a sample midterm examination for CS 115 at the University of Regina, consisting of various questions related to computer science concepts, including constructors, sorting algorithms, and array manipulations. It outlines the examination rules, such as being a closed book exam and the need for academic integrity. The exam includes multiple-choice questions, programming tasks, and theoretical explanations, totaling 40 marks.

Uploaded by

doyoci4903
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
173 views8 pages

CS 115 Midterm Exam Sample Questions

The document is a sample midterm examination for CS 115 at the University of Regina, consisting of various questions related to computer science concepts, including constructors, sorting algorithms, and array manipulations. It outlines the examination rules, such as being a closed book exam and the need for academic integrity. The exam includes multiple-choice questions, programming tasks, and theoretical explanations, totaling 40 marks.

Uploaded by

doyoci4903
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DEPARTMENT OF COMPUTER SCIENCE, UNIVERSITY OF REGINA

CS 115 Sample Midterm Examination


Duration: 1 hour, total marks: 40
Sultan Ahmed

Student First Name:

Student Last Name:

Student ID:

Student Signature:

Notes:
1. This is a closed book examination. You are allowed to use a calculator. You are
not allowed to use any materials that have not been approved by instructor.

2. Write your Name and Student ID, and sign this first page. Write your Student ID
on each of the other pages in the top-left corner.

3. You are expected to comply with the policies regarding academic integrity,
which are outlined in the University of Regina Undergraduate calendar. You must
maintain the confidentiality of your examination; do not provide any opportunity
for others to copy any of your work.

4. You should answer each question in the space provided.

5. You must submit this examination booklet and sign the attendance sheet.

6. The instructor reserves the right to assign seating during the exam.
Student ID: CS 115 Sample Midterm Exam

1. [10 marks]

(a) The act of selecting the correct function out of many functions with a same name, is
called__________________.

(b) A constructor must have the same number of parameters as there are member fields in the class.
(True/False?)

(c) A constructor must have the void return type. (True/False?)

(d) The member variables of a class must be of the same type. (True/False?)

(e) How many comparisons are needed to sort an array of length 5 if a selection sort is used and array is
already in the opposite order?

(i) 1 (ii) 5

(iii) 10 (iv) 20

(f) In a selection sort structure, there is/are?

(i) Two separate for loops (ii) Three for loops, all separate

(iii) Two for loops, one nested in the other (iv) A for loop nested inside a while loop

(g) For selection sort, how many steps there will be for a list of 10 elements?

(i) 11 (ii) 9

(iii) 20 (iv) 25

(h) What is the output of the code below if the input array is 12, 34, 56, 29, 78, and the x= 21?

int fun(int arr[], int N, int x)


{
for (int i = 0; i < N; i++)
if (arr[i] == x)
return i;
return -1;
}
(i) 0 (ii) 1

(iii) -1 (iv) None

(i) Can values of different types be stored in a same array? (yes/no)

(j) As parameters, two dimensional arrays are passed either by value or by reference. (True/False?)

Page 2 of 8
Student ID: CS 115 Sample Midterm Exam

2. [5 marks] Consider the following prototype of the C++ function that computes and returns the sum of
all digits in the decimal representation of an integer value m.

int sumOfDigits(int m);


For example, the sum of digits in 1234 is 1 + 2 + 3 + 4 = 10. That means, if the input to the function is
1234, the function returns 10. Similarly, if the input to the function is -1234, the function returns -10.
Implement the function in C++.

Page 3 of 8
Student ID: CS 115 Sample Midterm Exam

3. [5 marks] Explain the idea how a two-dimensional arrays can be simulated by an one-dimensional
array.

Page 4 of 8
Student ID: CS 115 Sample Midterm Exam

4. [5 marks] For the following program code, give the content that will be printed.

#include <iostream>
using namespace std;
int count=3;

class Exam
{
public:
Exam()
{
count++;
cout<<"Constructor1 is called."<<endl;
}

Exam(int x)
{
cout<<"Constructor2 is called."<<endl;
count = count + x;
count--;
}

Exam(float x, float y)
{
cout<<"Constructor3 is called."<<endl;
count = count + 10;
}
};

int main()
{
Exam e1, e2(12), e3(9.3,4.5);
Exam e4(7);
cout<<count;
return 0;
}

Page 5 of 8
Student ID: CS 115 Sample Midterm Exam

5. [5 marks] You are given the following array, on which you will need to perform insertion sort (in
ascending order). Since there are 6 items in the array, the algorithm presented in class will go over 5
iterations. In the following, show the state of the array at the end of each of the five iterations. Do not
skip any steps, even if the array remains unchanged.

Insertion sort

45 2 93 4 0 12

Page 6 of 8
Student ID: CS 115 Sample Midterm Exam

6. [5 marks] The prototype of the binary search function is given below:

int binarySearch( const int a[], unsigned int n, int x);

Here, a[] is an array of n integers. The value x is subject to be searched. The function returns the index
of the value x. If x does not exists in the array, -1 is returned. Implement the function in C++.

Page 7 of 8
Student ID: CS 115 Sample Midterm Exam

7. [5 marks] Write down the output that will be generated by the following program.

class C {

public:

C(){ cout << "CConst "; }

C(const char *s){ cout << s; }

};

class D : public C{

public:

D() : C(), x("X "), y("Y ") { cout << "DConst "; }

private:

C x;

C y;

};

int main() {

D d1;

return 0;

Page 8 of 8

You might also like