midterm1__SOLUTIONS

midterm1__SOLUTIONS - November 22, 2008 CS 201 (Intro. to...

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

View Full Document Right Arrow Icon
November 22, 2008 CS 201 (Intro. to Computing) MIDTERM I 1 2 3 4 5 6 7 TOTAL Name and Last Name : Cscan 201oğlu ID : SUNet Username : Notes: a) Please answer the questions only in the provided space after each question. b) Duration is 100 minutes. c) Closed-book, closed-notes, no calculators and computers. One A4 size cheat- note is allowed. d) There must be eight pages (including this one). Please check it out! QUESTIONS 1) a) (1 point) Write the cout statement (not the whole program; just one statement) that displays your first name, last name, your ID number and your SU email address on the screen. cout << "Cscan 201oglu, 00000, noname@su.sabanciuniv.edu" << endl; b) (2 points) What does the function return type of void mean? Please circle the correct answer. a) The function returns a numeric value. b) The function does not return any value. c) The function can return any value. d) The function returns a string. c) (2 points) One of the statements below is syntactically correct, but the others are wrong. Which one is the correct one? Assume that the variables m and n are defined as int variables.
Background image of page 1

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

View Full DocumentRight Arrow Icon
NAME, LASTNAME: a) 3 = m; b) n = 3; c) m + n = 3; d) 3 = m + n;
Background image of page 2
NAME, LASTNAME: 2) a) (9 points) What is the output of the following program? #include <iostream> using namespace std; int doSomethingElse(int y) { y++; return y; } int doSomething(int x, int y) { int k; x *= 2; k = y + 2; y = doSomethingElse(x); cout <<"In doSomething: x="<<x<<" y="<<y<<" and k="<<k<<endl; return y; } int main() { int x = 1, y = 8; cout << "In main: Before: x=" << x << " and y=" << y << endl; int z = doSomething(x+1, y); cout <<"In main: After: x="<<x<<" y=" <<y<<" and z="<<z<<endl; return 0; } b) (7 points) What is the output of the following program piece? int i, j = 5, k = 0, count = 0; for (i = 1; i < j; i++) { j--; if (i % 2 != 0) k++; else i--; count++; } cout << i << " " << j << " " << k << " " << count << endl; In main: Before: x=1 and y=8 In doSomething: x=4 y=5 and k=10 In main: After: x=1 y=8 and z=5 2 2 1 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
3) a) (6 points) What is the output of the following program piece? string s="ANA"; string t="5"; int i; for (i=5; i>=1; i--) { s = s.substr(0, s.length()/2); s = s + s; t = t + t; } cout << s << endl; cout << t.length() << endl; b) (3 points) In the following piece of code, num is an integer variable. Fill in the table below to specify the output for different values of num .
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.

This note was uploaded on 03/16/2012 for the course FENS 101 taught by Professor Selçukerdem during the Fall '12 term at Sabancı University.

Page1 / 10

midterm1__SOLUTIONS - November 22, 2008 CS 201 (Intro. to...

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