Skip to content

Instantly share code, notes, and snippets.

@ameryisafreeelf
Last active November 5, 2021 02:29
Show Gist options
  • Save ameryisafreeelf/7d276cbc672870e2fa3bb1f86a271955 to your computer and use it in GitHub Desktop.
Save ameryisafreeelf/7d276cbc672870e2fa3bb1f86a271955 to your computer and use it in GitHub Desktop.
Initial Design in the To Do List exercise (Week 2)
#include <iostream>
#include <string>
#include <vector>
static int taskNumberCounter = 0; // Static variable to assign a taskNumber to task
enum Status {done, notDone};
class Task {
private:
int taskNumber;
std::string name;
Status currStatus = notDone;
public:
Task(std::string name, Status s); // Assigns a taskNumber and increments taskNumberCounter
void setName(std::string newName);
void setStatus(Status s);
};
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
// Returns a copy of taskList
std::vector<Task> viewTaskList();
};
@ameryisafreeelf
Copy link
Author

One other thing to note, that I was second-guessing a lot- I decided to add a static variable called taskNumberCounter that would assign an ID called taskNumber to tasks. This provides a convenient way to access Tasks in Lists, which would be especially useful for referring to Tasks when writing HTTP endpoints.

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