Question: Write a program where you first enter a set of name-and-value pairs, such as Joe 17 and Barbara 22. For each pair, add the name
Write a program where you first enter a set of name-and-value pairs, such as Joe 17 and Barbara 22. For each pair, add the name to a vector called names and the number to a vector called scores (in corresponding positions, so that if names[7]=="Joe" then scores[7]==17). Terminate input with NoName 0. Check that each name is unique and terminate with an error message if a name is entered twice. Write out all the (name,score) pairs, one per line
#include#include using namespace std; void getData(vector < string > names, vector < int > scores) { // put the definition here } // Here is some simple test code to use: int main() { vector names; vector scores; getData(names, scores); // after the call is complete, // we expect both vectors to contain some information // let's display it: cout << "This is what we got: "; for (int i = 0; i < names.size(); i++) { cout << names.at(i) << " " << scores.at(i) << endl; } return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
