(C++)(Single Linked list) can you fix the main of this program so that the output is the same as this picture #include #include #include #include
(C++)(Single Linked list) can you fix the main of this program so that the output is the same as this picture
#include
using namespace std;
class Node { public: string data; Node *next;
Node(string s) { data = s; } Node(string s, Node *n) { data = s; next = n; } };
Node *head = nullptr; Node *tail = nullptr; Node *head1 = nullptr; Node *tail1 = nullptr;
Node *CreateList(string s[], int size) { Node *first = new Node(s[0]); Node *temp = first;
for (int i = 1; i next = node; temp = node; } return first; }
int main() {
//Declaring file object, Opening file, declaring string to add children names . ifstream inputfile; inputfile.open("input.txt");
// Prompting User to input the number of days. int numofdays; cout > numofdays; cout
// Code to read a line from a text file and separate it into tokens.
string word[6]; char st[20];
inputfile.getline(st, 100); char* token = strtok(st, ","); int i = 0; while (token != nullptr) {
word[i] = token;
token = strtok(nullptr, ","); i++;
} Node* w = CreateList(word, 5);
string duties[6]; char dt[50];
inputfile.getline(dt, 100); char* token2 = strtok(dt, ","); int z = 0; while (token2 != nullptr) {
duties[z] = token2;
token2 = strtok(nullptr, ","); z++; }
Node* d = CreateList(duties, 6);
// Creating the duty list output. cout.width(18); cout data; cout.width(10); cout next->data; cout.width(10); cout next->next->data; cout.width(10); cout next->next->next->data; cout.width(10); cout next->next->next->next->data;
cout
Node *start = w; // head;
// Outputing the children's names for each duty and each day. for (int a = 0; a
while (w != NULL) { cout.width(10); cout data; w = w->next;
if (w == nullptr) { w = start;
}
}
start = start->next; if (start == NULL) {
start = head; }
start = start->next;
cout
cout
Input.txt
Mohd,Ali,John,Alex,Mike Water,Firewood,Cooking,Cleaning,NoDuty
Select Microsoft Visual Studio Debug Console Enter number of days: 6 ay 2 day 3 day 4 ay 5 ay 6 Water Mohd Mike Alex ohn 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 John Ali Mohd Mike
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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