{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Computer Science 61B - Fall 1996 - Canny - Midterm 1

Computer Science 61B - Fall 1996 - Canny - Midterm 1 -...

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

View Full Document Right Arrow Icon
<!--CS61b, Midterm #1, Fall 1996)--> Problem #1 (10 points) The program below has a series of print statements. Each one has a comment line after it with a letter in parenttheses like lis :// (A) Next to each letter, write the output that you expect to see from that statement when the program runs. All these statements are part of one program, so you should answer the questions in order. int a[ ] = {5, 6, 7, 8}; int &b = a[0]; int &c = b; c = 0; cout << a[0] << "," << b << "," << c << endl; \\ (A) _____________________________________ int d = a[1]; int * e = & a[2]; d = 0; * e = 0; cout << a[1] << "," << a[2] << "," << d << "," << *e << endl; \\ (B) _____________________________________ int * f = & a[3]; f = e; *f = 20; cout << a[2] << "," << a[3] << "," << *e << "," << *f << endl; \\ (C) _____________________________________ Problem #2 file:///C|/Documents%20and%20Settings/Jason%20Raft...0-%20Fall%201996%20-%20Canny%20-%20Midterm%201.htm (1 of 5)1/27/2007 5:40:36 PM
Image of page 1

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

View Full Document Right Arrow Icon
<!--CS61b, Midterm #1, Fall 1996)--> (10 points) Here is a for statement from a recent piece of CS61B code: int prod = 1; for (int i = 1; i<=n; i++) { prod *= i; // "Loop invariant" } Which of the following would be a suitable loop invariant to replace the " Loop invariant " in the comment above? (a) prod *= i; (b) prod = i! (i factorial) (c) i = i + 1 (d) i++ Your answer ____________________ (4 points) Now consider the following piece of code: int sum = 1; for (int i = 0; i < n; i++) { sum += sum; // "Loop invariant" } write down a loop invariant to replace the "Loop invariant" comment: Your answer __________________________ (6 points) Problem #3 file:///C|/Documents%20and%20Settings/Jason%20Raft...0-%20Fall%201996%20-%20Canny%20-%20Midterm%201.htm (2 of 5)1/27/2007 5:40:36 PM
Image of page 2
<!--CS61b, Midterm #1, Fall 1996)--> (10 points) Write a function named "remvowel" that removes vowels from a string argument (producing C++-like names). Your function should not return a value, but should modify the string passed to it so that there are no vowels (none of 'a', 'e', 'i', 'o', 'u'). You should structure your solution
Image of page 3

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern