Skip to content

Commit

Permalink
Реализация на абстрактен клас Task и конкретен клас QuickTask
Browse files Browse the repository at this point in the history
  • Loading branch information
triffon committed May 11, 2019
1 parent 754c560 commit 5720d9e
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tasks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.7)
project(tasks)
file(GLOB SOURCES "*.cpp" "../common/named.cpp")
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_STANDARD 11)
add_executable(tasks ${SOURCES})
15 changes: 15 additions & 0 deletions tasks/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <iostream>

#include "quick_task.h"

void testQuickTask() {
QuickTask qt("лицева опора");
qt.print();
qt.work(1);
std::cout << std::endl;
qt.print();
}

int main() {
testQuickTask();
}
17 changes: 17 additions & 0 deletions tasks/quick_task.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "quick_task.h"

void QuickTask::print(std::ostream& os) const {
os << "Бърза ";
Task::print(os);
}

QuickTask::QuickTask(char const* n) :
Task(n), finished(false) {}

unsigned QuickTask::work(unsigned t) {
if (finished || t == 0)
return t;

finished = true;
return t - 1;
}
15 changes: 15 additions & 0 deletions tasks/quick_task.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "task.h"

class QuickTask : public Task {
bool finished;
public:
QuickTask(char const* n);

unsigned getExecutionTime() const { return 1; }

unsigned getProgress() const { return finished; }

unsigned work(unsigned t);

void print(std::ostream& os = std::cout) const;
};
9 changes: 9 additions & 0 deletions tasks/task.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "task.h"

void Task::print(std::ostream& os) const {
os << "задача '" << getName() << "', която изисква "
<< getExecutionTime() << " единици време"
<< " и е с прогрес " << getProgress();
}

Task::Task(char const* n) : Named(n) {}
33 changes: 33 additions & 0 deletions tasks/task.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef __TASK_H
#define __TASK_H

#include "../common/printable.h"
#include "../common/named.h"

class Task : public Printable, public Named {

public:

Task(char const* n);

// извежда собствените член-данни
void print(std::ostream& os = std::cout) const;

// време за изпълнение на задачата
virtual unsigned getExecutionTime() const = 0;

// прогрес по задачата
virtual unsigned getProgress() const = 0;

bool isFinished() const {
return getProgress() == getExecutionTime();
}

// отчита time единици работа по задачата
// връща броя неизползвани единици време
virtual unsigned work(unsigned time) = 0;


};

#endif

0 comments on commit 5720d9e

Please sign in to comment.