Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, in my computer science class, we have just been intoduced to pointers and it is very confusing, I have this assignment I have to

Hi, in my computer science class, we have just been intoduced to pointers and it is very confusing, I have this assignment I have to do and I did most of it, althought the second part (my TaskList class) isn't working how it should and I am very confused as to why this is happening. Any help would be very appritiated and some explination if possible, Thank You!! I attached the instructions of the file as a pic and my code is pasted below. NOTE: Task.h and Task.cpp are already done and work perfectly I am only pasting it since it is used in TaskList.cpp. TaskList.cpp is what doesn't complie(Part B).

/* * Task.h * * Created on: Feb 13, 2019 * Author: */

#ifndef TASK_H_ #define TASK_H_ #include using namespace std;

namespace std {

class Task { private: string title; string location; int priority;

public: //constructor Task(string title, string location, int priority);

//mutators void ChangePriority(int newPriority); void InputVal();

//accessor string Description() const; string GetTitle() const; string GetLocation() const; int GetPriority() const;

};

} /* namespace std */

#endif /* TASK_H_ */

/* * Task.cpp * * Created on: Feb 13, 2019 * Author: */

#include "Task.h" #include using namespace std;

//constructor Task::Task(string title, string location, int priority) { this->title = title; this->location = location; this->priority = priority; InputVal(); } void Task::InputVal() { if (priority 5) { cout

if (priority = 3) priority = 5; } }//Error checking: If the priority number given is out of bounds, //print a warning and set the priority to the closest valid number (1 or 5).

//mutators void Task::ChangePriority(int newPriority) { priority = newPriority; InputVal(); }

//accessor string Task::Description() const { string Desc; Desc += "["; Desc += location; Desc += "] "; Desc += title; switch (priority) { case 1: Desc += " *"; break; case 2: Desc += " **"; break; case 3: Desc += " ***"; break; case 4: Desc += " ****"; break; case 5: Desc += " *****"; break; } return Desc; } string Task::GetTitle() const { return title; } string Task::GetLocation() const { return location; } int Task::GetPriority() const { return priority; }

/* * TaskList.h * * Created on: Feb 13, 2019 * Author: */

#ifndef TASKLIST_H_ #define TASKLIST_H_ #include #include "Task.h" using namespace std;

namespace std {

class TaskList { private: string listName; // a name for the entire list int numTasks; // the current number of tasks on the list Task* allTasks[100]; // an array whose elements are pointers

public: //constructor TaskList(string listName);

//mutators void AddTask(string taskTitle, string taskLocation, int taskPriority); void CompleteTask(string taskTitle); void CompleteTask(int index);

//accessors void ShowAll() const; void ShowByPriority(int minPriority, int maxPriority) const; void ShowByLocation(int location) const; };

} /* namespace std

/* * TaskList.cpp * * Created on: Feb 13, 2019 * Author: */

#include "TaskList.h" #include "Task.h" #include using namespace std;

TaskList::TaskList(string listName) { this->listName = listName; allTasks[100] = { NULL }; numTasks = 0; }

//mutators void TaskList::AddTask(string taskTitle, string taskLocation, int taskPriority) { bool stop = false; for (int i = 0; i

if(stop == true) { cout

}void TaskList::CompleteTask(string taskTitle) { for(int i = 0; i

//accessors void TaskList::ShowAll() const { cout = minPriority and allTasks[i].GetPriority

*/

#endif /* TASKLIST_H_ */

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

In this project, you will build a task-management system to track "to do" items. The structure of the code must be as specified here, using two different classes. Part A - The Task Class Create a class named Task, placing code in the appropriate .h and.cpp files. A Task object represents an individual task on a to-do list. It must include three member variables: title (example: "return overdue book") location (example: "library") priority a number between 1 and 5, with higher numbers representing more urgent tasks. Give the class the following public methods: 1. A constructor with three parameters, in the same order as the first three variables above. Error checking: If the priority number given is out of bounds, print a warning and set the priority to the closest valid number (1 or 5). 2. A method with this prototype: void ChangePriority (int newPriority) This must change the priority to the given number. Error checking: If the given number is out of bounds, print a warning and set the priority to the closest valid number (1 or 5). 3. A method with this prototype: string Description) const; This must return a single string, containing these elements in order: The task's location surrounded by square brackets 3. A method with this prototype string Description() const; This must return a single string, containing these elements in order: o The task's location surrounded by square brackets o The task's title oOne or more"" symbols, matching the task's priority Example [home] do laundry ** 4. Three "getter" methods that simply return the values of the three private variables string GetTitle() const; string GetLocation() const; int GetPriority() const; Part A hints: Make sure you read the specifications above carefully. Except for warnings when a value is out of range, none of these methods actually print anything! Part B - The TaskList Class Create a class named TaskList, placing code in the appropriate.h and.cpp files A TaskList represents one entire to-do list. It must have the following private member variables string listName; // a name for the entire list int numTasks; // the current number of tasks on the list Task* allTasks [100]; an array whose elements are pointers Notice that allTasks is an array of 100 pointers. Each element will start out as NULL, and will only be changed to point to an actual Task object as needed Give the class all of the public methods listed below 1. A constructor with one parameter representing the list name Remember a constructor should set all member variables The elements of the alTasks array need to be set to NUU and numTasks needs to be set to 0 1. A constructor with one parameter representing the list name. Remember a constructor should set all member variables. The elements of the allTasks array need to be set to NULL, and numTasks needs to be set to O. 2. A method with this prototype: void AddTask (string taskTitle, string taskLocation, int taskPriority) This must add a task to the list, dynamically allocating a new Task object and updating both numTasks and allTasks appropriately. Error checking: If a task with the same title is already on the list, print an error instead. Do not create a new task or change the list. 3. A method with this prototype: void CompleteTask(string taskTitle); This must first check if a task with the given title exists on the list. If a task with the given title does NOT exist, just print an error. If it does, the following actions must happen, in order: Deallocate the corresponding Task object Copy elements of the list "downward" as needed to close the gap created by removing the given item. Decrease the value of num Tasks. 4. A method with this prototype: void CompleteTask (int index); This must first check if the given index is in range, between O and (numTasks-1). If it is out of range, just print an error. If it is in range, do the same three steps as in item 3: e Deallocate the corresponding Task object Copy elements of the list "downward" as needed to close the gap created by removing the given item. Decrease the value of num Tasks. 5. A method with this prototype: void ShowA11) const; This must nrint the title of the list followed hy all tasks using a numhered list and the strings given hy the 5. A method with this prototype void ShowA11) const; This must print the title of the list followed by all tasks, using a numbered list and the strings given by the Description() method applied to each task. Example: Ry Tasks e) [home] take out the trash 1) [home] do laundry* 2) [school] turn in homework**** 3) [Safeway] buy candy 6. A method with this prototype: void ShowByPriority(int minPriority, int maxPriority) const; This must behave like ShowAllO, but only display those tasks with priority valuesminPriority andmaxPriority. 7. A method with this prototype: void ShowByLocation(string location) const This must behave like ShowAlI), but only display those tasks whose location matches the given location. Part B hints/info: You should make private methods to help with the implementation of the public methods listed here. You may add as many private methods as you want, but the set of public methods must exactly match the list below. It is crucial to deallocate objects when they are removed from the list. Grading will include a test of memory management, with penalties for any memory that is dynamically allocated but not deallocated correctly

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

Recommended Textbook for

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions