ee312_test1_spring2001

ee312_test1_spring2001 - Last Naxnc"_First mksst...

Info iconThis preview shows pages 1–5. 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
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Last Naxnc"_First mksst EE312» Test 1 Spring 2001. TEST INSTRUCTIONS You will lose points if the following directions are not followed. (1) All books, notes and electronic aids must be at the side of the room or in a closed bag before the exam starts. It is considered cheating to have open notes, an open book or an electronic aid by your side during the exam. (2) Put your name, last name first, and your social security number in the space provided on each sheet. (3) Your work for each problem must be on the same sheet as the problem. You may use both the front and the back of each sheet for your answer. (4) No questions about exam content are allowed during the exam. If a problem is ambiguous or contains a typographical error, choose the most reasonable interpretation, make it clear what your interpretation is, and proceed. (5) If a question asks for a numerical answer, you are expected to give the reasoning behind your answer. (6) It is your responsibility to make sure that you have a problem for each number on the front sheet. Ask the proctor for another exam if a problem is missing. (7) No one is allowed to leave the room until they have finished the exam. Finally, all problems have the same weight, but they may not have the same difficulty. I suggest that you do the easiest ones first. Scores #1 _ __ #2 2.9. #3 7/5 #4 2.1?" Total ES; . Last Namenrfirst Name Problem 1. Give the output for the following programs. If the program has a syntax error, give the output as 'syntax error'. #include <iostream> using namespace std; int u = 3; int Sum(int x, int y); void OutputInteger (); int main () { (gun: 1,n=2,_u.=5; ‘ ‘ ,. cout << "The value of Sum equals " << Sum(m, n) << '\n'; A ole gut-“£4 cout << "The value of u is: " << u << '\n'; / i H r, n i OutputIntegerO; } cl Mum/f int Sum(int x, int y) { int u = 7; return x + y + u; } "_ ‘ _MSW,()void Outputlnteger () { cout << "The value of u is: " << u << '\n'; } H\ t #include <iostream> fit yu[mlfpl_i0_fl_._n 7 7 using namespace std; 1 a- intu=3; alli’f/‘jH-r ' int Sum(int x, int y); I ‘ Eggs _ (MC QiL‘VA QL (:- void Outputlnteger 0; fl\ (E, V {M i .1: ‘ ’ J} int main () { 0k " cout << "The value of Sum equals " << Sum(m, n) << '\n'; "‘,' 'r‘ cout << "The value of u is: " << u << '\n'; a? / ‘ OutputIntegerO; } {Imam ‘1 f: y <intSum(intx,inty){intw=x+y+u;u=7;retumw;} u'zq'a 2 ,3 I" I, , :7: Zvoid OutputInteger () { cout << "The value of u is: " << u << '\n'; } 1W L i a i v“: ._\L..»(, -._._.______.___ ____________________ -- “Hr/M » ---* ""’ ' H ' I #include <iostream> “TV/fl , w r 4 using namespace std; ‘ A6 f g ! ' ' , x int u = 4; W \IOI { N O SL’L’m éfiw‘fi“! int Sum(int x, int y); i ' f, N 3"” « f, . “i, void Out utInte er (int u); 1 .I’ I, ’. J ""3 Vi L ‘ y p g r 1‘] (1/,M L1” C I. ' Y " ' ? intmajn(){ V but 04’ 1 Nil v intm=l,n=2; ‘1 Valli] ‘ L I I u = 5; .‘ _ I cout << "The value of Sum equals " << Sum(m, n) << '\n‘; v - - cout << "The value of u is: " << u << '\n'; Outputlntegergu); } 4 r int Sum(int x, int y) { int w = x + y + u; u = 7; return w;} void OutputInte‘ger (int u) { cout << "The value of u is: " << u << '\n'; } Problem 2. (a) Write a function Test() that will return the value of the sum .... *7 ’ _ 1‘” i 1 , i‘ m/ 20 I with the call x 0 cout << Testgn) << endl; (b) What is the approximate value returned by Test() for large n? ’ (Assume n is not so large that round-off errors affect the result.) (a) . illoa’r 765+ (Mr N) Z 5wm10£ '58: «(Dr (1me if! ' it" n +> J . . 3%?” + 3 ?/ 3am ¥= pow(m-l.6)j' rah/rm 3mm)“ fl L J 1 mm '"l (b) The afwaxmw ; w W5)?” 65' ii: 51*“- i. g a Last N amQFirst Natal—SW” Problem 3. Suppose x is an array with 72 float components declared by the following C++ Statements: 0 O ‘Vz’m I int n; ’7’4’ float x“ 00]; : I ; m k" ’f '. Give the definition of the function MaximumO that returns the Went; x[O],...,x[n—1] with the call ' cout << Maximum(n, x) << endl; Be sure to use the Principle of Least Privile e in the definition of Maximum(), that is, write the definition of Maximum() so it can't change any of its parameters that don't need to be changed. MJ’L‘W w, Word Maximum(COM? 'WV NONE“? @955? Xfip‘fl) £10me mmxr—W‘fl} 10w (m it = Oyt‘ihvlf) ix*'*’> H1[max/— «mt MAX“: ’XUJ} raw/n We Last Na ‘ First NamelSSN (0i) QM ba (4'5 *7 Problem 4. (a rite the definition of the function GradeO that takes an int value score and With the call: cout << Grade(score) << endl; ‘ The formula used for the classical letter grade is: / A for 90 5 score 5 100 B for 894. W 99 .. , _;> , A . Cfor7OSscore<80 I "‘3 0“ +6“ ‘9“: k D for 60 S score < 70 F for score < 60 (b) Rewrite the definition of Grade() assuming the call looks like the following: char x- H, 6 “fl .5 1 ’ ‘ v" f ‘ v’ : Grade(score, x); . I: N MM 4 Mi {Mg } L 5,2,: M ( COUt << X << T 1 1'5 V a :4, fa; :1‘: """"""""""""""""""""" m f “‘2 , #3; “Z; 09) \Ioidl C’vma’e (W a;>c,haro+ 9) E [WWW >= 0'0 44 %C0re4i £00) ,\ / . Q’AJ €196 {Haw/e. >=go) ...
View Full Document

This note was uploaded on 02/09/2010 for the course EE 312 taught by Professor Shafer during the Spring '08 term at University of Texas at Austin.

Page1 / 5

ee312_test1_spring2001 - Last Naxnc&amp;quot;_First mksst...

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

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