// Bjarne Stroustrup 7/25/2009 // Chapter 8 Exercise 7 #include "std_lib_facilities.h" // note that different compilers/SDEs keep header files in different places // so that you may have to use "../std_lib_facilities.h" or "../../std_lib_facilities.h" // the ../ notation means "look one directly/folder up from the current directory/folder" /* Read 5 names into a vector prompt the user for ages for the 5 names and store the ages in a vector sort the names by name (e.g. "bill" before "joe") print out the (name,age) pairs. As stated, the tricky part is not to loose the corresponence between names and ages when you sort. We looked at reading and writing (name,value) pairs in 4-19 (and 6-4). We "steal" the reading and writing of pairs from 4-19, but make a couple of separate functions to make the code more readable and manageable. The solution presented here is simple, but unless you have struggled a bit with the problem you may not appreciate that. Please try! Most people first come up with something far more complicated (and therefore far harder to get right). Simplicity isn't always simple to achieve. */ vector name; vector age; void read_pairs() { string n; int v; while (cin>>n>>v && n!="NoName") { // read string int pair for (int i=0; i& v,const string& n) // find n's index in v { for (int i=0; i original_names = name; // copy the names vector original_ages = age; // copy the ages sort(name.begin(),name.end()); // sort the names for(int i=0; i