{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

midterm1__SOLUTIONS

midterm1__SOLUTIONS - CS 201(Intro to Computing MIDTERM I 1...

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

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, [email protected]" << 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.

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

View Full Document
NAME, LASTNAME: a) 3 = m; b) n = 3; c) m + n = 3; d) 3 = m + n;
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

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

View Full Document
NAME, LASTNAME: 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 . num=3 num=10 num=0 Output Yes Yes Yes c) (3 points) What is the value of the following expression?
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern