midterm1_solutions

midterm1_solutions - August 3, 2009 CS 201 (Intro. to...

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

View Full Document Right Arrow Icon
August 3, 2009 CS 201 (Intro. to Computing) MIDTERM I 1 2 3 4 5 6 7 TOTAL Name and Last Name : 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, no mobile phones 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 << " Gulsen Demiroz, 1480, gulsend" << endl; b) (2 points) What is a constructor? Please circle the correct answer. a) A special member function that constructs a numeric value. b) A special member function that cannot modify a data member. c) A special member function that creates objects of a class. d) A special member function that returns a string. c) (2 points) How many bits are used to represent: (i) a long integer variable? 4 bytes = 32 bits (ii) a double variable? 8 bytes = 64 bits
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: 2) a) (9 points) What is the output of the following program? #include <iostream> using namespace std; int CallMe3(int a) { int b = a - 1; cout <<"In CallMe3: a="<<a<<" and b="<<b<<endl; return b; } int CallMe2(int b) { b++; cout<<"In CallMe2: b="<<b<<endl; return b; } int CallMe(int a, int b) { a /= 2; b = CallMe2(a); cout <<"In CallMe: a="<<a<<" b="<<b<<endl; return b; } int main() { int a = 2, b = 6; cout<<"In main: Before: a="<<a<<" and b="<<b<<endl; int c = CallMe(b/2, CallMe2(CallMe3(a+1))); cout<<"In main: After: a="<<a<<" b=" <<b<<" and c="<<c<<endl; return 0; } In main: Before: a=2 and b=6 In CallMe3: a=3 and b=2 In CallMe2: b=3 In CallMe2: b=2 In CallMe: a=1 b=2 In main: After: a=2 b=6 and c=2 b) (7 points) What is the output of the following program piece? int main() { int i, j = 4, k = 1, count = 0; for (i = 0; i < j; i++) { j--; if (i < k) k--; else i--; count++; } cout << i << " " << j << " " << k << " " << count << endl; return 0; } 1 1 0 3
Background image of page 2
NAME, LASTNAME: 3) a) (4 points) Fill in the “Message Displayed” column of the following table below according to the given piece of program. Assume that a , b , and c are integer variables. b) (3 points) What is the value of the following expression?
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

midterm1_solutions - August 3, 2009 CS 201 (Intro. to...

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

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