Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

C++ Vectors Help:

write a program using parallel vectors and a function which fills each of them with 500 random numbers between 1 and 100. The program should then pass both vectors to a function which will return an integer indicating a count of how many times both vectors had even numbers in the same location. So if vector01[0] contained 4 and vector02[0] contained 12, you would add one to count.If vector01[1] contained 3 and vector02[1] contained 4, you would not add one to count.

main would display something like :

The Vectors contain 128 cells where both values are even.

 

Above was the question: I already have the code written:

#include<iostream>

#include<vector>

#include<cstdlib>

#include<ctime>

using namespace std;

 

int main()

{

int even = 0;

srand(time(0));

vector <int> vector01;

vector <int> vector02;

for (int i = 0; i < 500; i++)

{

vector01.push_back(rand() % 100 + 1);

vector02.push_back(rand() % 100 + 1);

if (vector01[i] % 2 == 0 && vector02[i] % 2 == 0)

even++;

}

cout << "The vectors contain " << even << " cells where both values are even." << endl;

return 0;

}

The code completely works, but there is just one problem.

Now the question asked us to pass the vector values into a function and calculate the total even numbers, I can't figure out how to do that at all! Would you please help me with this using the basic vector code and the variables I have? Thank you!

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education