Answered step by step
Verified Expert Solution
Question
1 Approved Answer
STL C++, please make the same output, Input.txt Mohd,Ali,John,Alex,Mike Water,Firewood,Cooking,Cleaning,NoDuty ------ Below is the code to read a line from a text file and separate
STL C++, please make the same output,
Input.txt
Mohd,Ali,John,Alex,Mike
Water,Firewood,Cooking,Cleaning,NoDuty
------
Below is the code to read a line from a text file and separate it into tokens:
ifstream ifile;
ifile.open( "input.txt" );
char word[300];
ifile.getline( word, 100 );
char* token = strtok( word, "," );
while ( token != NULL ) {
// Your code here
token = strtok( NULL, "," );
}
Exercise 2 A scout team consists of five children. There are four duties with a day off to be rotated among team members. Duties are: fetching water, collecting firewood, cooking, and cleaning up. You are to write a program that prompts the user for the desired number of working days and prints a schedule of daily duties for the team. Use two separate list objects to store the team member names and the duties, respectively The program must read the team members list and duties list (both comma-separated) from an input file input.txt, which may look like the example hereafter ohd Below is the code to read a line from a text file and separate it into tokens ifstream ifile; ifile.open "input.txt"; char word[300]; ifile.getlinel word, 100); char* token = strtok( word, "," ); while ( token != NULL ) { // Your code here token -strtok NULL, "," ); Sample Output Select Microsoft Visual Studio Debug Console Enter number of days: 6 Water Mohd Mike Alex John Ali Mohd Firewood Ali Mohd Mike Alex John Ali Cooking John Ali Mohd Mike Alex John Cleaning Alex John Ali Mohd Mike Alex NoDuty Mike Alex ohn Ali Mohd Mike ay 2 ay 3 day 4 ay 6
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started