0% found this document useful (0 votes)
26 views

Case Study

case study

Uploaded by

rohanstudy73
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Case Study

case study

Uploaded by

rohanstudy73
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Building a Task Manager using Singly Linked

List in C++

1 Introduction
Ask management systems are essential tools for organizing and prioritizing tasks
efficiently. In this case study, we’ll explore how to implement a simple task
manager using a singly linked list in C++. The task manager will allow users
to add tasks, remove tasks, and display tasks in an organized manner.

2 Objective
The objective of this case study is to understand the fundamentals of linked
lists in C++ and how they can be used to implement a basic task management
system. By the end of this case study, participants should be able to:

1. Create a singly linked list data structure.


2. Implement basic operations such as insertion, deletion, and traversal on
the linked list.
3. Develop a task manager application that allows users to add, remove, and
display tasks.

3 Problem statement
Design and implement a task manager application that utilizes a singly linked
list to manage tasks. The application should support the following functionali-
ties:
1. Add a task: Allow users to add a new task to the task list.
2. Remove a task: Allow users to remove a task from the task list.
3. Display tasks: Display all tasks currently in the task list.

1
4 Guidelines
1. Implement a Task class to represent individual tasks. Each task should
have attributes such as task name, description, priority, and due date.
2. Implement a Node class for the singly linked list data structure. Each
node will contain a Task object and a pointer to the next node.
3. Develop a TaskManager class to manage tasks using the linked list. This
class should provide functions for adding tasks, removing tasks, and dis-
playing tasks.
4. Create a user interface to interact with the task manager application. This
can be a simple console-based interface where users can input commands
to perform various actions.
5. Test the application thoroughly to ensure that all functionalities work as
expected.

5 Sample Implementation
#include <iostream>
#include <string>

using namespace std;

// Task class representing individual tasks


class Task {
public:
string name;
string description;
int priority;
string dueDate;

Task(string n, string desc, int prio, string due) : name(n), description(desc), priority
};

// Node class for the singly linked list


class Node {
public:
Task task;
Node* next;

Node(Task t) : task(t), next(nullptr) {}


};

// TaskManager class to manage tasks using a singly linked list

2
class TaskManager {
private:
Node* head;

public:
TaskManager() : head(nullptr) {}

// Function to add a task to the task list


void addTask(Task t) {
Node* newNode = new Node(t);
if (head == nullptr) {
head = newNode;
} else {
Node* current = head;
while (current->next != nullptr) {
current = current->next;
}
current->next = newNode;
}
cout << "Task added successfully!" << endl;
}

// Function to remove a task from the task list by name


void removeTask(string name) {
if (head == nullptr) {
cout << "Task list is empty!" << endl;
return;
}

Node* current = head;


Node* prev = nullptr;

while (current != nullptr && current->task.name != name) {


prev = current;
current = current->next;
}

if (current == nullptr) {
cout << "Task not found!" << endl;
} else {
if (prev == nullptr) {
head = head->next;
} else {
prev->next = current->next;
}
delete current;

3
cout << "Task removed successfully!" << endl;
}
}

// Function to display all tasks in the task list


void displayTasks() {
if (head == nullptr) {
cout << "Task list is empty!" << endl;
return;
}

Node* current = head;


cout << "Tasks:" << endl;
while (current != nullptr) {
Task task = current->task;
cout << "Name: " << task.name << ", Description: " << task.description << ", Pri
current = current->next;
}
}
};

int main() {
TaskManager taskManager;

// Adding tasks
taskManager.addTask(Task("Task 1", "Description of Task 1", 1, "2024-04-21"));
taskManager.addTask(Task("Task 2", "Description of Task 2", 2, "2024-04-22"));

// Displaying tasks
taskManager.displayTasks();

// Removing a task
taskManager.removeTask("Task 1");

// Displaying tasks after removal


taskManager.displayTasks();

return 0;
}

6 Code Explanation
1st part
class Task {

4
public:
string name;
string description;
int priority;
string dueDate;

Task(string n, string desc, int prio, string due) : name(n), description(desc), priority
};

1. The Task class represents individual tasks.


2. It has attributes such as name, description, priority, and dueDate.
3. The constructor initializes these attributes when a new task object is cre-
ated.

2nd part Node Class


class Node {
public:
Task task;
Node* next;

Node(Task t) : task(t), next(nullptr) {}


};

1. The Node class represents nodes in the singly linked list.


2. Each node contains a Task object and a pointer to the next node (next).
3. The constructor initializes the task attribute and sets the next pointer to
nullptr.

3rd part Task Manager Class


class TaskManager {
private:
Node* head;

public:
TaskManager() : head(nullptr) {}

// Function to add a task to the task list


void addTask(Task t) {
// Implementation...
}

5
// Function to remove a task from the task list by name
void removeTask(string name) {
// Implementation...
}

// Function to display all tasks in the task list


void displayTasks() {
// Implementation...
}
};

1. The TaskManager class manages tasks using a singly linked list.


2. It has a private member head, which points to the first node in the linked
list.
3. The addTask, removeTask, and displayTasks functions are used to perform
operations on the task list.

4th part Main Function


int main() {
TaskManager taskManager;

// Adding tasks
taskManager.addTask(Task("Task 1", "Description of Task 1", 1, "2024-04-21"));
taskManager.addTask(Task("Task 2", "Description of Task 2", 2, "2024-04-22"));

// Displaying tasks
taskManager.displayTasks();

// Removing a task
taskManager.removeTask("Task 1");

// Displaying tasks after removal


taskManager.displayTasks();

return 0;
}

1. The main function demonstrates how to use the TaskManager class.


2. It creates a TaskManager object named taskManager.
3. Tasks are added using the addTask method.
4. The list of tasks is displayed using the displayTasks method.

6
5. A task is removed using the removeTask method.
6. The list of tasks is displayed again to show the changes after removal.

7 Conclusion
By completing this case study, participants will gain a deeper understanding of
linked lists in C++ and how they can be applied to real-world problems. They
will also learn the importance of data structure choice in designing efficient
applications. This task manager application serves as a foundation for more
complex task management systems and can be extended with additional features
and functionalities in the future.

You might also like