S08_key1

# S08_key1 - PIC 10B EXAM 1 KEY Check your TA's name Judah(1A...

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

PIC 10B EXAM 1 April 21, 2008 KEY Check your TA's name: Judah (1A) ________ Alvin (1B) ________ You have 50 minutes to complete this exam. No books, notes, or calculators are allowed. Show all work. Incomplete, illegible, or unintelligible answers may receive no credit. There are a total of 50 points on this exam. PAGE POSSIBLE POINTS SCORE 1 14 2 8 3 6 4 16 5 6 TOTAL 50

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

View Full Document
1 1.) [2 points] Using Big O Notation, describe the running time of the code below. You must explain your answer. int N; cin >> N; for (int i=1; i<=N; i++) for (int j=1; j<=i; j++) cout << i << "\n"; The outer loop runs N times. The inner loop runs 1 time, then 2, then 3, up to N. So the total number of integers printed out is 1 + 2 + 3 + 4 + . .. + N = N(N+1)/2 = O(N 2 ) 2.) [12 points] Suppose we have a class Clown that uses dynamic memory. Write the single-line declaration for each function below, as it would appear in the Clown class declaration. a.) The exponent function to raise a Clown object to an integer power, as in: Clown clownCubed = myClown^3; Clown operator^ (int power); b.) The input function to read a Clown object from a specified input stream, as in: cin >> myClown; This function will need access to the private data in the Clown class. friend istream& operator>> (istream& in, const Clown& right);
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 10/23/2011 for the course PIC 10B taught by Professor Wittman during the Winter '08 term at UCLA.

### Page1 / 6

S08_key1 - PIC 10B EXAM 1 KEY Check your TA's name Judah(1A...

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

View Full Document
Ask a homework question - tutors are online