# Concepts and Ideas

Concepts and Ideas

COMPUTER APPLICATIONS DIVISION

Assignment

C0227 C++ PROGRAMMING

STL Vector

For this assignment, you will be starting with an example program that demonstrates the

use of a STL vector. In addition to this, you may need to look up how to generate random numbers.

Your end project will enter 100 random numbers (range 0-9) into the vector. Then, ask for a number to search for, and count how many there are in your group. When you complete the assignment, I want you to answer a couple questions about random numbers. Here are the details.

Start with the STL_Vector example. Use the rand function to generate random numbers

between 0 and 9. If you need help generating random numbers see:

http://www.cplusplus.com/reference/cstdlib/rand/. Set up a for loop that puts 100 of these random

number into a STL Vector. Change the printVector function in the example to print out all of the contents of your vector. Now you can see the contents of the vector which is the 100 random numbers you generated.

Write a second function called countElements. The definition will be:

int countElements( const std::vector<unsigned int& MyVector, unsigned int SearchValue );

You will pass into countElements your vector (by reference), and the number you are looking for.

Your function will use a for loop with an iterator (like the one used in printVector) to compare each Vector element to the SearchValue. Count up the number of matches and return the total count.

You have an example executable program to mimic.

Questions to Answer in your ReadMe.txt file.

Are your numbers truly random? Run your program a number of times. Do you get the same numbers each time you run it? If not, can you make them random?

Put your findings in your ReadMe.txt file.

COMPUTER APPLICATIONS DIVISION

Assignment

C0227 C++ PROGRAMMING

STL Vector

For this assignment, you will be starting with an example program that demonstrates the

use of a STL vector. In addition to this, you may need to look up how to generate random numbers.

Your end project will enter 100 random numbers (range 0-9) into the vector. Then, ask for a number to search for, and count how many there are in your group. When you complete the assignment, I want you to answer a couple questions about random numbers. Here are the details.

Start with the STL_Vector example. Use the rand function to generate random numbers

between 0 and 9. If you need help generating random numbers see:

http://www.cplusplus.com/reference/cstdlib/rand/. Set up a for loop that puts 100 of these random

number into a STL Vector. Change the printVector function in the example to print out all of the contents of your vector. Now you can see the contents of the vector which is the 100 random numbers you generated.

Write a second function called countElements. The definition will be:

int countElements( const std::vector<unsigned int& MyVector, unsigned int SearchValue );

You will pass into countElements your vector (by reference), and the number you are looking for.

Your function will use a for loop with an iterator (like the one used in printVector) to compare each Vector element to the SearchValue. Count up the number of matches and return the total count.

You have an example executable program to mimic.

Questions to Answer in your ReadMe.txt file.

Are your numbers truly random? Run your program a number of times. Do you get the same numbers each time you run it? If not, can you make them random?

Put your findings in your ReadMe.txt file.

You'll get 1 file (7.1MB)