final-sample - CS201 (Intro. to Computing) Sample Questions...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
CS201 (Intro. to Computing) Sample Questions for the FINAL Exam Those questions do not imply any favorite subject or question type for the questions in the actual exam Please also review recitation questions, samples covered in the class, homeworks and the questions in the book as well Especially review the sample questions distributed for the midterm exams since the final exam might be comprehensive QUESTIONS 1) Write a function that takes an integer parameter and returns true if that parameter is divisible by 7. In the program, input some integers and display the total number of numbers that are divisible by 7 by using the above-declared function. End of input entry is signaled by having CTRL-Z (end of file) or having a non-integer value as input. 2) a) What is the output of the following program? #include <iostream> using namespace std; int thefunction (int a) { static int b = 0; b++; a=a+b; return a; } int main() { int b=0; int i; for (i=1; i <=3; i++) { b=b+thefunction(i); } cout << b << endl; return 0; } © CS201 Team at Sabancı University 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
b) Write a function that takes a matrix of integer as parameter and returns the sum of the elements in the main diagonal of the matrix. You may assume that the matrix is a square one. c) Write a templated function that takes two parameters and returns their maximum. d) Write a templated function that takes a vector as parameter and reverses its content. The reversed vector must return from the function as its single parameter. 3) a) Write a recursive function to find the n th element of the following series. - + = = 0 ) 1 ( ). 1 .( 0 1 ) ( x x f x x x x f b) Suppose you want to read a file and store its content in memory. What would you use, a vector or a built-in array? Why? c) Which search mechanism would you use to find an element in a sorted array, binary or sequential search? Why? Discuss on their complexities. © CS201 Team at Sabancı University 2
Background image of page 2
4) What is the output of the following program. #include <iostream> using namespace std; int x = 9, y = 5; int myfunction () { int y = 0; int a = 5; cout << x << " " << y << " " << a << endl; if (y < x) { int y = a*2; cout << x << " " << y << " " << a << endl; } a++; y++; x++; cout << x << " " << y << " " << a << endl; return a + y + x; } int main() { int a = 10, x = 5; cout << x << " " << y << " " << a << endl; cout << myfunction() << endl; if (x == y) { int a = x + 2*y; y++; cout << x << " " << y << " " << a << endl; } a++; x++; y++; cout << x << " " << y << " " << a << endl; return 0; } © CS201 Team at Sabancı University 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
5) In order to evaluate the multiple choice examination two text files are created.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

final-sample - CS201 (Intro. to Computing) Sample Questions...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online