-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Реализация на абстрактен клас Task и конкретен клас QuickTask
- Loading branch information
Showing
6 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
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
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}) |
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
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(); | ||
} |
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
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; | ||
} |
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
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; | ||
}; |
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
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) {} |
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
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 |