mirror of https://github.com/PatrickLipka/tt.git
Basic class definitions and test program
This commit is contained in:
parent
206161a306
commit
a2ba8123f4
|
@ -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--;
|
||||
}
|
|
@ -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
|
|
@ -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);
|
||||
}
|
|
@ -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
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue