Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to read in a text file consisting of a last name and a hobby, on

ID: 1850159 • Letter: W

Question

Write a program to read in a text file consisting of a last name and a hobby, one per line. Names and hobbies are single word, and space delimited. The file is sorted by name.
The program should display each unique name on a new line, followed by "enjoys" and a list of hobbies enjoyed by that person.
Example output:

Adams enjoys chess and dressage and snowboarding
Baker enjoys forensics
Chesterfield enjoys spelunking and bicycling and dressage and philately and knitting
Davis enjoys chess and rowing
Einberg enjoys bicycling and running and swimming
Feldman enjoys bicycling and forensics
Gibson enjoys guitar

Test data to produce the above output would be:
Adams chess
Adams dressage
Adams snowboarding
Baker forensics
Chesterfield spelunking
Chesterfield bicycling
Chesterfield dressage
Chesterfield philately
Chesterfield knitting
Davis chess
Davis rowing
Einberg bicycling
Einberg running
Einberg swimming
Feldman bicycling
Feldman forensics
Gibson guitar

Explanation / Answer

#include #include #include using namespace std; int main() { ifstream inFile; inFile.open("input.txt", ios::in); string currentName=""; string name; string hobby; string out=""; bool start=false; while (!inFile.eof()) { inFile >> name >> hobby; if(name!=currentName) { if(start) cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote