/* * main.cpp * * Created on: 30.05.2013 * Author: trifon */ #include #include #include #include using namespace std; #include "quicktask.h" #include "simpletask.h" #include "repeattask.h" #include "complextask.h" #include "stack.cpp" void work(Task** tasks, int n, int t) { int i = 0; while (t > 0) { t = tasks[i]->work(t); // *(*(tasks+i)).work(t); tasks[i]->print(); i++; } } void testwork(Task* task, int t) { for(int i = 1; i <= t; i++) { Task* copy = (Task*)task->clone(); cout << copy->getProgress() << ' ' << i << ' '; copy->work(i); assert(copy->getProgress() > 0); cout << copy->getProgress() << endl; copy->print(); cout << endl; } } int main1() { // BaseTask bt("Задача"); Task* t = new QuickTask("хапване"); t = new SimpleTask("лекция", 3); t->print(); t->work(5); t->print(); } int main() { Task* tasks[5] = { new QuickTask("хапване"), // 1 new SimpleTask("лекция", 3), // 3 new RepeatTask("пътуване", 3, new SimpleTask("пътуване с ГТ", 2)), new SimpleTask("излизане", 2), new SimpleTask("сън", 8) }; try { RepeatTask* rtask2 = dynamic_cast(tasks[0]); int* p = new int[1000000000L]; } catch (bad_alloc e) { cerr << "Лошо заделяне! " << e.what(); } catch (bad_cast e) { cerr << "Лошо преобразуване!"; } try { // проверка дали clone работи правилно tasks[2]->print(); Task* newtask = (Task*)tasks[2]->clone(); newtask->work(); tasks[2]->print(); // !!!Task tasks2[2] = { QuickTask("хапване"), // SimpleTask("лекция", 3) }; // !!! Task& tasks3[2] = { *tasks[0], *tasks[1] }; // work(tasks, 5, 9); // проверка за вложени повтарящи се задачи Task* rtask = new RepeatTask("level1", 3, new RepeatTask("level2", 2, new SimpleTask("base", 5))); rtask->print(); cout << endl << rtask->time() << endl; rtask->work(22); rtask->print(); ComplexTask* ctask = new ComplexTask("четвъртък"); for(int i = 4; i >= 0; i--) ctask->push(tasks[i]); ctask->print(); cout << ctask->time() << endl; // testwork(tasks[2], 10); // testwork(rtask, 35); testwork(ctask, 25); // проверка дали има споделяне Task* ctask_copy = (ComplexTask*)ctask->clone(); tasks[2]->work(5); ctask_copy->print(); } catch (int progress) { cerr << "Изключение: " << progress; } return 0; }