exam1PracticeSolns

exam1PracticeSolns - PIC 10A October 24, 2005 First Midterm...

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

View Full Document Right Arrow Icon
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

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

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

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

View Full DocumentRight Arrow Icon
Background image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: PIC 10A October 24, 2005 First Midterm NAME (Print!) and UK) Number: Check one: Salomone (12:00 pm): m Wang: W Saiomone (1:00 pm): W Baiabanov: T___m Problem Points Score 1 10 W 2 5 Jr 3 5 I { 4 s l 5 10 I 6 15 i‘ Total 50 2 Problem : Answer the following five true-false question. Your re— sponses Should be the ENTIRE WORD TRUE OR THE EN»— TIRE WORD FALSE. You will N 0T receive credit for the letters T and F: (a) The statements in a While loop must always be separated by { and r > . 3; ester-l effigy lags. Answer: I- 1 (b) You can get into an infinite for loop. :6“? ‘ is Answer: (c) You can declare a variable named douole. Answer: (d) v1, v2, v3 are int variables, v1=4,v2=5,v3m6. Then, what is the value of the following boolean statement: !((v1<zv2)|l!(true &&(v1!=v3))) was?” “’1'” 3 i _/w 2935/ Answer: (e) v1, v2, v3 are int variables, v135,v2m6,v324. Then, what is the value of the following boolean statement: <«M9m !((v1<2v2) I I !(t1__"ue &&(v1!=v3))) v?” WE - Answer: Problem 2: You compfie the program: #include <iostreazn> A g £- :mwfiusing namespace std; g gig-gagfiéiéfifgyéfi? int main(){ int m=2, 1123; cout << pow(m,n); return 0 } and it returns the error error C2593: ’operator <<’ is ambiguous error (33861: ’pow’: identifier not found, even with argument-dependent lockup In the space provided, say Why the compiler returned that message. On the original code, indicate how you would fix it to make it compiie. t v' a _ f. a! V ‘ ... g E “1 2 7 E W ,N - - ‘2 “a r '- g V . I“ P i“ :7 at} fi‘ igé‘dfié .5 fig; {egg/1 iv :2 {kw 3r :4ng m E g "fifiiefééfj ’- é Probiem 3: The following program compiies and runs. #include <iostream> using namespace std; int main(){ bool doorIsBpenEfalse; bool seeResidentz true; if EoprIsOpenr‘g ,, if {EeeResidént} cout << "Bel 0, may I come in In"; else cont <<“Knock! Knock! Anyone there?"; return 0 ; } In the space provided below, say what it does and explain why it daes it. ‘ [x 1 ‘1 km 7 f :1 5 i ) é? ii; if i g ibgg {Pi}; :2; a}? A? $9???» igaééééffi? i 557 gig}; {fax} 5 Problem 4: The following switch statemezlt sorts people according to which Eecture they’re in: switch(1ecture){ 1 : Gout <<”1ecture 1”; break; 2: cont <<”Lecture 2”; break; default: Gout <<“Are you taking PIC 10A?“; } Wrrite coéo that does the same thing, but with a if —else statements instead. Problem 5: You run the following program: #include <iostream> using namespace std; int main(){ int b=3; double c=3; for (int i=0; i<5; i++){ cout << iZb; cout<< i/c; cout<<i/b; } return 0; } In the Spaxle,p‘rmridedrbglow3 write what the pgogmm prinfis tOjCI'efin. ‘ fé ~H‘ 4,2 . é §J§§QEK< {E’} gfififigwé cigwcii é? ixaffiééadfiww§§}{£&fin '1’ Probiem 6 (15 pts): Write a program that separately takes in your height in inches and in feet. It outputs you your height in inches and in meters (there are 39 inches per meter). You program must have the two functions Whose deciarations are int convert'folnchesfint feet, int inches) ; and double convertToMeters(int inches) ;. You should reprompt the user until he enters a. nonnegative num— ber of feet and inches. 9 {f ‘1 '3 .é {eke-ii: :fi BE???» I; § E 5 if; ' 5’? fifia é; x\ W Q Jew , a :3, v: M *5; if“ air . fry. :2 g; E ( a. a gig; wk 3?; gig/{fie} v, MW ...
View Full Document

This note was uploaded on 02/22/2010 for the course PIC PIC 10A taught by Professor Shockran during the Fall '03 term at UCLA.

Page1 / 8

exam1PracticeSolns - PIC 10A October 24, 2005 First Midterm...

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

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