Skip to content

Instantly share code, notes, and snippets.

@ameryisafreeelf
Last active November 5, 2021 02:29
Show Gist options
  • Save ameryisafreeelf/b30386e64f0b5cee715c6ecd67a55ea8 to your computer and use it in GitHub Desktop.
Save ameryisafreeelf/b30386e64f0b5cee715c6ecd67a55ea8 to your computer and use it in GitHub Desktop.
First round of feature requests in To Do List exercise (week 2)
#include <iostream>
#include <string>
#include <vector>
#include <ctime>
static int taskNumberCounter = 0; // Static variable to assign a taskNumber to task
enum Status {done, notDone};
enum Priority {none, low, medium, high};
class Task {
private:
int taskNumber;
std::string name;
Status currStatus = notDone;
Priority currPriority = none;
time_t dueDate;
public:
Task(std::string name, Status s); // Assigns a taskNumber and increments taskNumberCounter
void setName(std::string newName);
void setStatus(Status newStatus);
void setPriority(Priority newPriority);
void setDueDate(timt_t newDueDate);
};
class List {
private:
std::vector<Task> taskList;
public:
List(Task &t); // Creates a List, note that instantiation of a List requires a Task
// Accessors
Task getTask(int taskNumber);
// Mutators for taskList
void addTaskToList(Task &t); // Creates a task object and adds it to taskList
void deleteTaskFromList(Task &t); // If this causes taskList.empty(), delete List
std::vector<Task> viewTaskList(); // Returns a copy of taskList
std::vector<Task> viewTaskListDateSort(bool asc); // Returns list of tasks sorted by Date, ascending or descending
std::vector<Task> viewTaskListByStatus(Status s); // Returns list of tasks filtered by status
std::vector<Task> viewTaskListByPriority(Priority p); // Returns list of tasks filtered by priority
};
@ameryisafreeelf
Copy link
Author

ameryisafreeelf commented Nov 5, 2021

(Second and fourth options)

I implemented a notion of priority and date. This felt relatively straightforward as I simply added a those properties to the Task class with getters and setters. Then, I added some methods in List that allow for sorting by date and filtering by both status and priority.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment