Basic class definitions and test program

This commit is contained in:
Patrick Lipka 2021-12-08 19:16:40 +01:00
parent 206161a306
commit a2ba8123f4
5 changed files with 87 additions and 0 deletions

21
src/project.cpp Normal file
View File

@ -0,0 +1,21 @@
#include <vector>
#include <algorithm>
#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--;
}

20
src/project.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef PROJECT_H
#define PROJECT_H
#include <string>
#include <vector>
#include "task.h"
class Project{
public:
Project(std::string name);
std::string name;
int num_tasks;
std::vector<Task> tasks;
void add_task(Task task);
void remove_task(int id);
int active_task;
};
#endif

12
src/task.cpp Normal file
View File

@ -0,0 +1,12 @@
#include <iostream>
#include <algorithm>
#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);
}

15
src/task.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef TASK_H
#define TASK_H
#include <string>
#include <algorithm>
class Task{
public:
Task(std::string name);
std::string name;
int work_time;
void add_time(int seconds);
};
#endif

19
src/tt.cpp Normal file
View File

@ -0,0 +1,19 @@
#include <iostream>
#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;
}