From a2ba8123f410a86c47c0199d09d3cf56e2be6626 Mon Sep 17 00:00:00 2001 From: Patrick Lipka Date: Wed, 8 Dec 2021 19:16:40 +0100 Subject: [PATCH] Basic class definitions and test program --- src/project.cpp | 21 +++++++++++++++++++++ src/project.h | 20 ++++++++++++++++++++ src/task.cpp | 12 ++++++++++++ src/task.h | 15 +++++++++++++++ src/tt.cpp | 19 +++++++++++++++++++ 5 files changed, 87 insertions(+) create mode 100644 src/project.cpp create mode 100644 src/project.h create mode 100644 src/task.cpp create mode 100644 src/task.h create mode 100644 src/tt.cpp diff --git a/src/project.cpp b/src/project.cpp new file mode 100644 index 0000000..59ccbb0 --- /dev/null +++ b/src/project.cpp @@ -0,0 +1,21 @@ +#include +#include +#include "project.h" + +Project::Project(std::string name){ + Project::name = name; + Project::num_tasks = 0; + Project::active_task = 0; +} + +void Project::add_task(Task task){ + Project::tasks.push_back(task); + Project::active_task = Project::num_tasks; + Project::num_tasks++; +} + +void Project::remove_task(int id){ + Project::tasks.erase(tasks.begin()+id); + Project::active_task = std::max(id-1,0); + Project::num_tasks--; +} diff --git a/src/project.h b/src/project.h new file mode 100644 index 0000000..4711846 --- /dev/null +++ b/src/project.h @@ -0,0 +1,20 @@ +#ifndef PROJECT_H +#define PROJECT_H + +#include +#include +#include "task.h" + +class Project{ + public: + Project(std::string name); + std::string name; + int num_tasks; + std::vector tasks; + void add_task(Task task); + void remove_task(int id); + int active_task; +}; + + +#endif diff --git a/src/task.cpp b/src/task.cpp new file mode 100644 index 0000000..5969edd --- /dev/null +++ b/src/task.cpp @@ -0,0 +1,12 @@ +#include +#include +#include "task.h" + +Task::Task(std::string name){ + Task::name = name; + Task::work_time = 0; +} + +void Task::add_time(int seconds){ + Task::work_time = std::max(work_time+seconds,0); +} diff --git a/src/task.h b/src/task.h new file mode 100644 index 0000000..f45e95c --- /dev/null +++ b/src/task.h @@ -0,0 +1,15 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include + +class Task{ + public: + Task(std::string name); + std::string name; + int work_time; + void add_time(int seconds); +}; + +#endif diff --git a/src/tt.cpp b/src/tt.cpp new file mode 100644 index 0000000..3f312f3 --- /dev/null +++ b/src/tt.cpp @@ -0,0 +1,19 @@ +#include +#include "task.h" +#include "project.h" + +int main(){ + + Task task("Test task"); + task.add_time(140); + std::cout << "Task name: " << task.name << ", Work Time: " << task.work_time << std::endl; + + Project proj("Test Project"); + proj.add_task(task); + std::cout << "Project name: " << proj.name << " No tasks:"<< proj.num_tasks <<" contains task 0: " << proj.tasks[0].name << " with work time " << proj.tasks[0].work_time << std::endl; + + std::cout << "Removing Task 0 from Project" << std::endl; + proj.remove_task(0); + std::cout << "Number of tasks in project: " << proj.num_tasks << std::endl; + return 0; +}