FINAL December 2016, Questions and Answers FINAL December 2016, Questions and Answers
FINAL December 2016, Questions and Answers FINAL December 2016, Questions and Answers
Concordia University
Department of Electrical and Computer Engineering
FINAL EXAMINATION QUESTIONS
COEN 243 2016 Sections D,U – Programming Methodologies
Instructions:
- Closed book and no calculators allowed.
- Clearly state all reasonable assumptions.
- Handwriting must be legible.
- Questions sheet must be signed and handed in
- Answers must be written in the answer sheets provided.
I am aware of the university regulations concerning cheating and plagiarism: [ ] yes, [ ] no.
Consistent with the code of ethics of my (future) profession, I will not cheat during this
examination:
Part 1 Multiple Choice Answer (55 marks, 3 marks each Q1-Q20, 5 marks each Q21-Q23)
Q1. The data type bool:
a. Can take on values true and false.
b. Can take on any expression as a value.
c. Can take on values -1, 0 or 1.
d. Can only be used in a selection statement.
Q2. Which of the following statements initializes the unsigned int variable counter to 10?
a. unsigned int counter = 10;
b. unsigned int counter = {10};
c. unsigned int counter{10};
d. All of the above.
Q4. Which of the following is a parameterized stream manipulator used to format output?
a. setw
b. right
c. left
d. fixed
Q6. Consider the following code, assuming that x is an int with an initial value of 12
if(x = 6) {
cout << x;
}
a. 6
b. 12
c. Nothing.
d. A syntax error is produced.
Q7. Converting from type ________ to type ________ will result in the loss of data.
a. bool, char.
b. float, double.
c. int, char.
d. short, long.
Q10. Which of the following is not a correct way to initialize the array named n?
a. array<int, 5> n{0, 7, 0, 3, 8};
b. array<int, 5> n{0, 7, 0, 3, 8, 2};
c. array<int, 5> n{7};
d. array<int, 5> n{9, 1, 9};
a. The program will make a copy of the value of the argument and use it in the function and
delete it when the function is finished.
b. The program will only use global variables to access any reference arguments.
c. The program will use the address of the argument to read and write data.
d. The program will make a new address for the argument to read and write the data for the
function and will let the main program refer to the old address after the function is finished.
Q13. Assuming that t is an array and tPtr is a pointer to that array, which expression refers to
the address of element 3 of the array?
a. *(tPtr + 3)
b. tPtr[3]
c. &t[3]
d. *(t + 3)
Q14. The first step performed by the binary search algorithm at each iteration is to:
a. Compare the search key with the lowest element in the current set of data.
b. Compare the search key with the middle element in the current set of data.
c. Compare the search key with the highest element in the current set of data.
d. Count the number of elements in the current set of data.
is:
(a) 2 5 5 6
(b) 2 6 5 6
(c) 2 6 5 5
(d) 0 0 0 0
(e) 2 6 6 7
int keith = 5;
int* const keef = &keith;
*keef = 70;
cout << keith << endl;
return 0;
}
(a) 5
(b) 70
(c) No output is produced as the program does not compile
(d) 0
(e) 5 70
(a) 70
5
(b) 70 5
(c) No output is produced as the program does not even compile.
(d) 5
70
(e) 5 70
a) 1 2 3 4 5
b) 1 1 1... and on forever
c) 2 3 4 5 6
d) 1 2 3 4
e) 2 3 4 5
a) 55
b) 66
c) 101
d) 87
A) .3
B) 0
C) .275229
D) 3.3
E) None of these
The next three questions are based on the program below (5 marks each)
#include <iostream>
#include <array>
int main(){
int array[ARRAY_SIZE];
std::array<int, ARRAY_SIZE> arrTemplate{10, 130, 23,45,33, 89, 55};
insertion_sort(arrTemplate, ARRAY_SIZE, compare);
print_array(arrTemplate);
return 0;
}
Q23. Suppose we output the intermediate state of the array by changing one line of the
insertion_sort() as
The program runs on the main() function and insertion_sort() is called. What’s the output when i
equals to 2?
a) 130 10 23 45 33 89 55
b) 130 23 10 45 33 89 55
c) 130 45 23 10 33 89 55
d) 130 45 33 23 10 89 55
e) None of the above
Part II Answer all three questions in this section (20 marks, 10 marks each)
Q24. What is the output of this code: (show your work step by step)
int mystery(int n)
{
if (n == 0)
return 0;
else if (n == 1)
return 1;
else
return mystery (n-1) + mystery (n-2);
}
int main()
{
cout<<mystery(6);
}
int main()
{
char word[]="mississippi";
char* wptr;
char s ='p';
char t ='t';
wptr = fun(word, s, t);
cout<<wptr;
return 0;
}
mississitti
void F ( _________________________________ ) {
k1++;
k2 = k2+2;
}
int main () {
int n1=3, n2=5;
F(n2,n1);
cout<<n1<<endl;
cout<<n2<<endl;
}
Q27. Write a program that asks the user to type 10 integers of an array and an integer value V.
The program must search if the value V exists in the array and must remove the first occurrence
of V, shifting each following element left and adding a zero at the end of the array. The program
must then write the final array. (Marks 20)
int main()
{
int array[10];
int input, ctr=0, move;
for (int x=0; x<10; x++)
{
cout<<"Enter a number on index ["<<x<<"]: "; cin>>array[x];
}
int v;
cout<<"Enter the value of 'v': "; cin>>v;
10
{
array[z]=array[move];
move++;
}
array[9]=0;
for (int d=0; d<10; d++)
{
cout<<array[d]<<", ";
}
}
return 0;
}
11