Last active
November 5, 2021 02:29
-
-
Save ameryisafreeelf/dd883b39242c00a6266412e0056f2294 to your computer and use it in GitHub Desktop.
Second round of feature requests for To Do List Exercise (Week 2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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}; | |
enum Visibility {Visible, NotVisible}; // Public means that friends can view the task | |
class User { | |
private: | |
std::string name; | |
std::vector<User> listOfFriends; | |
List l; | |
public: | |
std::vector<User> getListOfFriends(); | |
List viewFriendsListOfTasks(User &u); // This will call the input user's list via viewTaskListByVisibility() | |
}; | |
class Task { | |
private: | |
int taskNumber; | |
std::string name; | |
Status currStatus = notDone; | |
Priority currPriority = none; | |
time_t dueDate; | |
Visibility currVisibility = NotVisible; | |
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); | |
void setVisibility(Visibility newVisibility); | |
}; | |
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 | |
std::vector<Task> viewTaskListByVisiblity(Visiblity v); // Returns list of tasks filtered by visilbity | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I created the User class, each of which has a list of friends.
I added a notion of visibility, where public means that a Task is visible when a User's friend views their List. To support this, I added a method to view tasks by visibility. When a User's friend views their List using
viewFriendsListOfTasks
, this will callviewTaskListByVisibility(public)
, so that the friend will only see Tasks set to Public.This reuses the previous code because all we've done is add a
Visibility
property to Task and an accessor in List. Otherwise, the design is the same.