#include #include #include using namespace std; struct people { string name; int age; people * next; people(string n, int a, people * o) { name = n; age = a; next = o; } void printone() { cout << name << ", age " << age << "\n"; } }; int main() { ifstream infile("people.txt"); if (infile.fail()) { cout << "Couldn't read people.txt\n"; exit(1); } people * all = NULL; while (true) { string n; int a; infile >> n >> a; if (infile.fail()) break; cout << "accepted " << n << ", " << a << "\n"; all = new people(n, a, all); } infile.close(); cout << "The poeple you typed were:\n"; people * temp = all; while (temp != NULL) { temp->printone(); temp = temp->next; } cout << "All done\n"; while (true) { string query; cout << "Eneter a name for search: "; cin >> query; temp = all; int matches = 0; while (temp != NULL) { if (temp->name == query) { cout << query << "'s age is " << temp->age << "\n"; matches += 1; } temp = temp->next; } if (matches == 0) cout << query << " not found\n"; else if (matches > 1) cout << query << " appears more than once\n"; } }