CSE202Lab9

CSE202Lab9 - CSE202
Lab
9
–
Vectors



Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE202
Lab
9
–
Vectors

 Introduction:
The
purpose
of
this
lab
is
to
familiarize
you
with
accessing
and
 manipulating
vectors
as
well
as
using
vectors
as
function
arguments.

 Synopsis:
You
will
a
program
that
first
loads
a
vector
with
5,000,000
(5
million)
 random
integers
and
secondly
adopts
a
function
to
search
for
a
value
in
the
vector,
 returning
the
number
of
occurrences
of
the
search
term
found.
 Instructions:

 1. Inside
your
main
function
(don’t
forget
the
necessary
includes!)
create
a
 vector
object
that
will
hold
integers.
You
needn’t
use
the
constructor
that
 pre‐allocates
memory,
but
if
you
do,
pre‐allocate
space
for
all
5x106
elements.
 
 2. Use
a
loop
to
fill
the
vector
with
5x106
random
numbers.
Make
sure
you
use
 the
push_back()
method
to
store
the
values
in
the
vector.

 
 3. Write
a
function
called
findInt
with
the
following
prototype:
 a. int findInt(vector<int>& list, int term); b. Implement
this
function.
It
needs
to
loop
through
each
element
of
the
 vector,
count
how
many
times
term
is
found
within
the
vector,
and
 return
that
number
back
to
the
function
caller.
 
 4. In
a
do‐while
loop,
ask
the
user
for
the
search
term
and
receive
it.
 
 5. Call
the
findInt
function
with
the
search
term
and
output
the
value
the
 function
returns
–
this
is
the
number
of
occurrences
of
term
in
your
vector.


 
 6. Repeat
this
process
until
the
user
enters
‐1
as
the
search
term,
use
this
in
the
 do‐while
Boolean
expression
to
exit
the
loop.
 
 Question:
Why
do
you
think
the
function
used
the
vector
through
pass‐by‐reference
 vs.
pass‐by‐value?
 ...
View Full Document

This note was uploaded on 10/18/2009 for the course CSE 201 taught by Professor All during the Spring '09 term at Ohio State.

Ask a homework question - tutors are online