CS301P ASSIGNMENT 1 SOLUTION FALL 2023 | CS301P ASSIGNMENT 1 SOLUTION 2023 | CS301P ASSIGNMENT 1 2023 | DATA STRUCTURES (PRACTICAL) | VuTech
Visit Website For More Solutions
www.vutechofficial.blogspot.com
KINDLY, DON’T COPY PASTE
Question No. 1
You have to create a C++ program for office task management using Stack data structure implemented with linked list. The objective is to develop a computer program that allows users to efficiently handle their tasks as a Last-In, First-Out (LIFO) data structure.. The program should allow office employees to add, remove and display tasks in a Stack.
Requirements:
You are required to implement a stack data structure using a singly linked list. The stack should be used to manage a collection of tasks.
Implement the following operations on the output console:
1- Push a Task onto the Stack: Users should have the ability to push a new task onto the stack. They should provide the following details:
- Task name
- Task ID
- Description
- Due date
2- Pop a Task from the Stack: Users should be able to pop and remove the task at the top of the stack. T
3- Display the Top Task: Users can view the details of the task that is currently at the top of the stack
4- Display the Entire Stack: The user should be able to view the entire list of tasks, including the task name, task ID, description, and due date.
Stack should be implemented using a linked list data structure, with each node representing a single task in the tasks list. Each node should contain the task name, task ID, description, and due date..
Solution:
#include<iostream>
#include<conio.h>
using namespace std;
class Task
{
private:
int taskID;
string taskName, description, dueDate;
Task *next;
public:
void setTaskID(int id)
{
taskID = id;
}
int getTaskID()
{
return taskID;
}
void setTaskName(string name)
{
taskName = name;
}
string getTaskName()
{
return taskName;
}
void setDescription(string desc)
{
description = desc;
}
string getDescription()
{
return description;
}
void setDueDate(string date)
{
dueDate = date;
}
string getDueDate()
{
return dueDate;
}
void setNext(Task *nextNode)
{
next = nextNode;
}
Task* getNext()
{
return next;
}
};
class TaskStack
{
private:
Task *head;
public:
TaskStack()
{
head = NULL;
}
void pushTask(int taskID, string taskName, string taskDesc, string date)
{
Task *newNode = new Task;
newNode -> setTaskID(taskID);
newNode -> setTaskName(taskName);
newNode -> setDescription(taskDesc);
newNode -> setDueDate(date);
newNode -> setNext(head);
head = newNode;
}
void popTask()
{
Task *ptr = head;
head = head -> getNext();
delete ptr;
}
void topTask()
{
cout<<"Top Task - Name: "<<head -> getTaskName();
cout<<", ID: "<<head -> getTaskID();
cout<<", Description: "<<head -> getDescription();
cout<<", Due Date: "<<head -> getDueDate()<<"\n";
}
void displayTasks()
{
Task *ptr = head;
while(ptr != NULL)
{
cout<<"Name: "<<ptr -> getTaskName();
cout<<", ID: "<<ptr -> getTaskID();
cout<<", Description: "<<ptr -> getDescription();
cout<<", Due Date: "<<ptr -> getDueDate()<<"\n";
ptr = ptr -> getNext();
}
}
};
main()
{
TaskStack TS;
while(1)
{
int choice,id;
string name,desc,date;
cout<<"Task Management System";
cout<<"\n1. Push a Task onto the Stack";
cout<<"\n2. Pop a Task from the Stack";
cout<<"\n3. Display the Top Task";
cout<<"\n4. Display the Entire Stack";
cout<<"\n5. Exit";
cout<<"\nEnter Your Choice : ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"Enter task name: ";
cin>>name;
cout<<"Enter task ID: ";
cin>>id;
cout<<"Enter task description: ";
cin>>desc;
cout<<"Enter due date: ";
cin>>date;
TS.pushTask(id, name, desc, date);
break;
case 2:
TS.popTask();
break;
case 3:
TS.topTask();
break;
case 4:
cout<<"Task Stack:\n";
TS.displayTasks();
break;
case 5:
exit(0);
}
}
}