Anda di halaman 1dari 4

## CS 013 - Introductory Computer Science Winter - 2013

Midtem Exam 1 - Wednesday 1/30
Each multiPle-choice question is worth 1 point. Onl-'s bubble in one
best urrr*". r", o,r"rtiorr.
1. Given the following array declaration, what is the value of a [ 1 ] ?
int a[] : {1,2,3,4,5,6,j,g,9};
a.2 b.3 c. a d. s e.6 t. 7
2' Given the arcay a declared in the previous question, the following statement will always cause a
runtime error.
cout << a[9] << endl;
a. TRUE b. FALSE

3' Given the vector v declared below, the following cout statement will always
cause a runtime error.
vector(int> v(9,1);
cout << vl9l << endl;
A. TRUE b. FALSE

4' Given the vector v declared in the previous question, the following cout statement
will always
cause a runtime error.
cout (( v. at ( 9 ) (( endl ,.

a. TRUE b. FALSE

I 12] ?

## int ai3l t3l : {1,2,3,4,5,6,-1 ,g,9};

a.2 b.3 c.4 d.5 e.6 f.7
6. Given the following irrray declaration, what is the value of a
[ 2) lr|?
int a[] [2] : {1,2,3,4,5,6,1,9,91;
a.2b.3c.4d.5e.6f.]
7. How many rows does the array in the previous question have?

L.1b.2c.4d.5e.Gf.g
8. What would be output by the following code fragement?

## char s[80] : "Heflo There",.

cout << strfen(s) << endf;
a.ob.10c.11d.t2e.igf.80
9' What is the size of the array s (not the length of the c-style string) after the following
declaration?
char s[] : "Heflo",'
a.0b.4c.5d.6e.if.8

Page I of4
10. Which of the following expressions will always be true if a vector v stores at least 1 value?
a- v.sizeO :: 1 c. v-emPtYo
b' v.at(O) >: 0 d. lv.ern,t'o
11. Given the following declaration of the struct Time and a variable t of type Time, which statement
has a syntax error (assume the 4 statements are within the main function)?

struct Time {
int hour;
int minute;
t;
int main0 {
Time t;
)
a. cout << t.hour << endf;
b. t.hour : 10;
C. t.minute : 30;
d. cout (( t << endl-;
{2. Given the following declaration of the class Point and a variable p of type Point which statement
has a syntax error (assume the 4 statements are within the main function)?

cl-ass Point {
private:
doubfe xcoord;
double ycoord;
public:
Point ( ) ;
Point (doubl-e, doub]e) ;
doubl-e getXO const;
doub]e getYO const;
void move (doub]e, double) ;
);
int maino {
Point p;
)
A. doub1ex:p.xcoord;
b. Point p2 : Point (1.4 , 2.0);
c. p.move (1.5, 2-4);
d. cout (( p.qetXO << endl-;

PageZ of 4

13. (5 points) Write the definition for the function f ind declared below?

## /* Returns the integer index value of the first instance of c within

.- the c-style string s.
* Returns -1 if c is not encountered in Lhe c-styIe string.
*/
int find ( const char s_! , char c ) ;
i
i,,- ri tv -, i...,, i
i.. -n,.-1.
t.
tcr "(L,til(iq;'iPrjlltii :'"u '- i:
't
t' ,' -t);1'- ' ,:''
;l' /
,/\
--:
j.- '- I : . "
-!- .. i
:
.;

Page 3 of4
UrCd le L Pe
snah
14. (5 points) Write a function named cof_averages that passes ina2d(two-dimensional) array
of ints with NROWS number of rows and NCOLS number of columns (assume NROWS and
NCOLS are global constants) andasingle-dimensional array of doubles of size NCOLS. The
-void.' the ld array with the column averages. The function should have a return Epe of
. _fUgcIgo{lls
(/
'
\.-*--"" _--
For example, if the 2dxray had the values:
1t_221L2
2223222
3318432
1111111
2222222
then the function should populate the ld array with the following averages:

## The first 1.8 is the average of the first column of values:

(l +2+ 3 + 1 +2:9 and 9 /5 : 1.8)

Recall, you can convert an expression exp's type from int to double like this:
s tatic_cast.(double> ( exp )

t ,/,
\
\,ie"
v- Q
-ol

yw6iu *rr I
t a
r:rtl,*CIMeY<lqPS -(
g
L =\$(*rsr)
iIucbtg ,{ {t}
{or ( urrt*\$nrcJ ifit'J-- }
lnt s L4rll *'ei l qIOUU t* {i{b( t {4 qt t

## {or ( Uflsigncqi cil{ I < ua's \$S 5{ tj

5r..
i ;*j I
"'} 7 ,/ lt
it.tt4'+' ctrr fs*4:K:, L ;l L.:l
(}vcrftg fl ' 5t6rt'lc -cdL+ ddct{blC >(\$ilrn ) /NRO ws i
?
/t

tf {rr luet ag e ,
}.y\$ \-=
3 '/ -c:(
,3

Page 4 of4