Name: ________________________________

Honor Code Acknowledgment: _____________________________


CPS 6, Summer 1999                 Random Quiz 7

Due: Monday, June 14, 1999                 9 points


Problem 1: Only want the Evens (4 pts)

Write a function named SumUpEven that given an integer vector and the number of elements in the vector, returns the sum of the even integers in the array.

For example, consider the vector called scores:

SumUpEven(scores,7) returns 22 (the sum of the even numbers 8 + 4 + 10).

The header for SumUpEven is below.

int SumUpEven (const Vector <int> & scores, int number)
// precondition: number is the number of integers in the array scores,
//               stored in locations 0, 1, 2, ... , number-1
// postcondition: returns the sum of the even integers in the Vector
//                
{













Problem 2: Fewer numbers (1 pt)

Using the array scores above, what does SumUpEven(scores,5) return?

Problem 3: DoubleUp (4 pts)

Write a function named DoubleUp that given a vector of strings, doubles the size of the Vector, creating a second copy of each item, immediately to the right of it.

For example, consider the vector called fruit:

DoubleUp(fruit,3) modifies the vector fruit to look like:

The header for DoubleUp is below.

void DoubleUp (Vector <string> & fruit, int & number)
// precondition: number is the number of strings in the array fruit
// postcondition: modifies the array fruit to have two copies of each
//                original item (adjacent to each other),
//                the "number" of items is doubled
{