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

Problem: (Program to be written in C++) Write a program that uses a list of stri

ID: 3606426 • Letter: P

Question

Problem: (Program to be written in C++) Write a program that uses a list of string to keep track of a list of chores that you have to accomplish today. Your program should perform several tasks in the following order:

1. obtain a initial list of chores that you plan to accomplish today from a input file.

2. display how many items on the list.

3. print the list of chores to the screen.

4. delete those items you are not going to accomplish or you have already accomplished today and then print the list again. (Ask the user for which items the user wants to delete)

5. add some items which are not on the list but you need to accomplish today. (Ask the user to add the new items)

6. display the list of chores to the screen again.

Use a linked based list to write the program.

Use two functions in this project: one is to get the initial list from an input file; the other is to print the list to the screen.

Explanation / Answer

#include <bits/stdc++.h>

using namespace std;

struct llist{

string s;

struct llist * next;

};

llist* makeNode(string s){

llist* node = new llist();

node->s = s;

node->next = NULL;

return node;

}

void deleteNode( llist* head, llist * node )

{

if(node->next == NULL){

llist *t;

llist *temp = head;

while(temp->next != NULL)

{

t=temp;

temp=temp->next;

}

free(t->next);

t->next=NULL;

return;

}else{

llist * temp = node->next;

node->s = node->next->s;

node->next = temp->next;

free(temp);

}

return;

}

int main(){

llist *head,*temp;

ifstream infile("C:/Users/Acer/Desktop/input.txt");

string s;

int len=0;

infile >> s;

head = makeNode(s);

len++;

temp = head;

while( infile >> s){

temp->next = makeNode(s);

temp = temp->next;

len++;

}

cout << "There are " << len << " number of chores in the list" << endl;

temp = head;

cout << "List of chores:" << endl;

while(temp != NULL){

cout << temp->s << endl;

temp = temp->next;

}

char c;

while(1){

cout << "Enter the chore you have alredy done or not going to do:" << endl;

cin >> s;

temp = head;

while(temp != NULL){

if(temp->s.compare(s) == 0){

deleteNode(head,temp);

break;

}

temp = temp->next;

}

temp = head;

cout << "List of chores:" << endl;

while(temp != NULL){

cout << temp->s << endl;

temp = temp->next;

}

cout << "Do you want to remove more chores?(y/n)" << endl;

scanf(" %c",&c);

if(c == 'n')

break;

}

while(1){

cout << "Enter the chore you want to add to list:" << endl;

cin >> s;

llist *node = makeNode(s);

node->next = head;

head = node;

temp = head;

cout << "List of chores:" << endl;

while(temp != NULL){

cout << temp->s << endl;

temp = temp->next;

}

cout << "Do you want to add more chores?(y/n)" << endl;

scanf(" %c",&c);

if(c == 'n')

break;

}

cout << "Final list of chores:" << endl;

temp = head;

while(temp != NULL){

cout << temp->s << endl;

temp = temp->next;

}

return 0;

}

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