Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Integer numElements is read from input. Then, strings and integers are read and stored into string vector productList and integer vector numberList, respectively. Lastly, string

 

Integer numElements is read from input. Then, strings and integers are read and stored into string vector productList and integer vector numberList, respectively. Lastly, string productAsked and integer numberAsked are read from input.

Assign matchesFound with the number of element pairs that match both productAsked and numberAsked.

For each pair that matches productAsked and numberAsked, output "Exact match found at index " followed by the element pair's index. End with a newline.

Ex: If the input is:

4 sofa 99 dresser 161 sofa 99 sofa 100 sofa 99

Then the output is:

Exact match found at index 0 Exact match found at index 2 Total: 2

Code:

#include
#include
using namespace std;

int main() {
int numElements;
string productAsked;
int numberAsked;
int matchesFound;
unsigned int i;

cin >> numElements;

vector productList(numElements);
vector numberList(numElements);

for (i = 0; i < productList.size(); ++i) {
cin >> productList.at(i);
cin >> numberList.at(i);
}

cin >> productAsked;
cin >> numberAsked;

/* Your code goes here */

cout << "Total: " << matchesFound << endl;

return 0;
}

 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamental Managerial Accounting Concepts

Authors: Thomas Edmonds, Christopher Edmonds, Bor Yi Tsay, Philip Olds

8th edition

978-1259569197

More Books

Students explore these related Accounting questions

Question

Dont smell (i.e., too much perfume/cologne).

Answered: 3 weeks ago