This preview shows pages 1–5. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full 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 ﬁrst, 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 ﬁnished the exam. Finally, all problems have the same weight, but they may not have the same difﬁculty. I suggest that
you do the easiest ones ﬁrst. Scores
#1 _ __
#2 2.9.
#3 7/5 #4 2.1?"
Total ES; . Last Namenrﬁrst 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> ﬁt yu[mlfpl_i0_ﬂ_._n 7 7 using namespace std; 1 a
intu=3; alli’f/‘jHr ' int Sum(int x, int y); I ‘ Eggs _ (MC QiL‘VA QL (:
void Outputlnteger 0; ﬂ\ (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/ﬂ , w r 4
using namespace std; ‘ A6 f g
! ' ' , x
int u = 4; W \IOI { N O SL’L’m éﬁw‘ﬁ“! 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 roundoff errors affect the result.) (a) .
illoa’r 765+ (Mr N) Z 5wm10£ '58: «(Dr (1me if! ' it" n +> J . .
3%?” + 3 ?/ 3am ¥= pow(ml.6)j'
rah/rm 3mm)“ ﬂ
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 ﬂoat components declared by the following C++ Statements: 0 O ‘Vz’m I
int n; ’7’4’
ﬂoat x“ 00]; : I ; m
k" ’f '. Give the deﬁnition 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 deﬁnition of Maximum(), that is, write the
deﬁnition 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? Xﬁp‘ﬂ) £10me mmxr—W‘ﬂ} 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 deﬁnition 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 deﬁnition 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.
 Spring '08
 Shafer

Click to edit the document details