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 #include #include #include using namespace std;   int main() { int even = 0; srand(time(0)); vector vector01; vector 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!

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Linked List Representation
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education