Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Abstract Data type Can you please fix my c++ code and write it in 3 separate file? (resolution.cpp, resolution.h, and main.cpp) Resolution.h ************************ #include using

Abstract Data type

Can you please fix my c++ code and write it in 3 separate file? (resolution.cpp, resolution.h, and main.cpp)

Resolution.h

************************

#include

using namespace std;

struct Node //Definition of structure of task { string name; float time; int priority; Node* next; };

class CS_Resolution //Defintion of class resolution { private: //to store task of resolutions Node* res[1000];

//to store resolution names string res_name[1000]; int n_name; //to store number of resolutions

//remove all tasks at index i void rem_tasks(int i) { Node* p = res[i]; Node* q = NULL; //tail pointer to follow p

//Using loop traversing every node to delete them while (p) { q = p; p = p->next; delete q; } //As all nodes are deleted so pointer res[i] is alloted NULL res[i] = NULL; }

//to insert node(task) according to the priority void sortedInsert(Node** first, Node r) { Node *p, *q; Node *t = new Node; //Creating a new node

//Assigning details of task to new node t->name = r.name; t->time = r.time; t->priority = r.priority; q = NULL; p = *first;

//if there is no task in the resolution if (*first == NULL) { *first = t; t->next = NULL; return; }

//If the task is to be inserted at first position if (r.priority priority) { t->next = *first; *first = t; return; } //Task is inserted in ascending order of priority while (p && r.priority >= p->priority) { q = p; p = p->next; } t->next = p; q->next = t;

} public: //Constructor CS_Resolution() { n_name = 0; for (int i = 0; i

//Add resolution name void add_Resolution(string name) { res_name[n_name] = name; n_name++;

} //Removing resolution name with the tasks void rem_Resolution(string name) { int i; //Searching the index containing given resolution name for (i = 0; i

//Using loop shift all elements from right to left to fill the position //of deleted elements while (i

//As the last element is shifted towards left so position must be NULL res_name[n_name - 1] = ""; res[n_name - 1] = NULL;

n_name--; //decrement the total number of resolutions by 1 }

}

//Add task in resolution of given name void add_task(string name_resolution, Node r) { int i; //Searching index of resolution of given name for (i = 0; i = 1 && r.priority

//Display all tasks for given name void display_task(string name_resolution) { int i; //Searching index of resolution of given name for (i = 0; i name time priority next; } } else //If there is no resolution cout

//Display all resolution with tasks void display_res() { if (n_name == 0) { cout

};

main.cpp

**********************

#include #include "Resolution.h"

using namespace std;

int main() { CS_Resolution resolutions; //Creating object of class CS_Resolution resolutions.add_Resolution("Promise1"); //Adding resolution named Promise1 //Adding task to the resolution named Promise1 resolutions.add_task("Promise1", { "Never lie",2.5,3 });

//Adding resolution named Promise2 resolutions.add_Resolution("Promise2"); //Adding tasks to the resolution named Promise2 resolutions.add_task("Promise2", { "Behave properly",4,4 }); resolutions.add_task("Promise2", { "Never curse",1,3 });

cout

resolutions.display_res(); //Removing resolution named Promise1 resolutions.rem_Resolution("Promise1"); cout

//Adding resolution named Promise3 resolutions.add_Resolution("Promise3"); cout

return 0; }

image text in transcribed

Building Abstract Data Types exercise in building, traversing, and destroying linear linked lists. build a data structure to keep track of your New Year's Resolutions and help us monitor how we are doing at them. The data structure that you will be creating is a linear linked list of New Years Resolutions. Then, for each of these, you should have a linear linked list of all of the tasks you plan to do to achieve your goals - in order by importance. For each resolution, the task list should include: a. The name of the task b.How long you plan to spend on this task c. The priority (1-10) Using Classes We will be building a class (e.g., CS_Resolution) to manage the data structures mentioned. You must have the following functions; the information that these Functions need to work with should be passed as an argument. For example, to Add a new resolution, the information about the item should be passed to the Function from the client program". a.Construct an object (constructor) b. add a Resolution (pass in the name of the New Year's Resolution) c. Remove a Resolution (along with removing all tasks for that Resolution) d. Add a task to do for a particular Resolution (pass in the name of the resolution and the task information; consider using structs to avoid long argument lists) e.Display all tasks for a Resolution (passing in the name of the Resolution) f. Display all Resolutions g. Release all dynamic memory (destructor)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Describe the strategic training and development process.

Answered: 1 week ago