Integer inputSize is read from input. Then, integers and strings are read and stored into integer vector quantityList and string vector foodList, respectively. Lastly, integer quantityAsked is read from input. Find quantityAsked in quantityList and output the following: • The quantity" • the value of quantityAsked . *is matched with food" the element in foodList at the index of quantityAsked in quantityList *and is at index" the index of quantityAsked in quantityList End with a newline. Ex: If the input is: 4 44 lettuce 48 chicken 59 guava 40 pineapple 48 Then the output is: The quantity 48 is matched with food chicken and is at index 1

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
Integer inputSize is read from input. Then, integers and strings are read and stored into integer vector quantityList and string
vector foodList, respectively. Lastly, integer quantityAsked is read from input. Find quantityAsked in quantityList and output the
following:
• "The quantity"
• the value of quantityAsked
• 'is matched with food'
• the element in foodList at the index of quantityAsked in quantityList
and is at index"
• the index of quantityAsked in quantityList
End with a newline.
Ex: If the input is:
4
44 lettuce 48 chicken 59 guava 40 pineapple
48
Then the output is:
The quantity 48 is matched with food chicken and is at index 1
Note: quantityAsked is an element in quantityList.
6
int inputSize;
7
int quantityAsked;
unsigned int i;
cin >> inputSize;
vector<int> quantityList (inputSize);
13 vector<string> foodList (inputSize);
8
9
10
1121841516181928122
17
for (i = 0; i < quantityList.size(); ++i) {
cin >> quantityList.at(i);
cin>> foodList.at(i);
20 cin >> quantityAsked;
21/ Your code goes here */
return 0:
7
Transcribed Image Text:Integer inputSize is read from input. Then, integers and strings are read and stored into integer vector quantityList and string vector foodList, respectively. Lastly, integer quantityAsked is read from input. Find quantityAsked in quantityList and output the following: • "The quantity" • the value of quantityAsked • 'is matched with food' • the element in foodList at the index of quantityAsked in quantityList and is at index" • the index of quantityAsked in quantityList End with a newline. Ex: If the input is: 4 44 lettuce 48 chicken 59 guava 40 pineapple 48 Then the output is: The quantity 48 is matched with food chicken and is at index 1 Note: quantityAsked is an element in quantityList. 6 int inputSize; 7 int quantityAsked; unsigned int i; cin >> inputSize; vector<int> quantityList (inputSize); 13 vector<string> foodList (inputSize); 8 9 10 1121841516181928122 17 for (i = 0; i < quantityList.size(); ++i) { cin >> quantityList.at(i); cin>> foodList.at(i); 20 cin >> quantityAsked; 21/ Your code goes here */ return 0: 7
Expert Solution
Step 1

Algorithm:

1. Start
2. Declare an integer variable inputSize, an integer variable quantityAsked, and an unsigned integer variable i.
3. Read the size of the input and store it in input size.
4. Declare a vector quantity list of size inputs.
5. Declare a vector food list of size inputs.
6. For i = 0 to inputSize - 1, read in the quantity and food name and store it in quantityList and foodList respectively.
7. Read in the quantity asked and store it in quantityAsked.
8. For i = 0 to input size - 1, check if the quantity in the quantity list at index i is equal to the quantity asked.
9. If yes, print out the food at index i in foodList, index, and break the loop.
10. End.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Binary Search Algorithm
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