Advertisement
Guest User

Untitled

a guest
Jun 29th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. class Event {
  8. protected:
  9. string name; //atrybut
  10. int bonus;
  11. int start_time;
  12. int end_time;
  13. int duration;
  14. public:
  15. Event(string name_s);
  16. string get_name();
  17. virtual ~Event() {}
  18. int is_bonus();
  19. };
  20.  
  21. class Chore: public Event {
  22. public:
  23. Chore(string name_s) : Event(name_s){
  24. bonus = 0;
  25. };
  26. void set_start_time(int start_t);
  27. void set_end_time(int end_t);
  28. int get_start_time();
  29. int get_end_time();
  30. };
  31.  
  32. class Bonus: public Event {
  33. public:
  34. Bonus(string name_s) : Event(name_s){
  35. bonus = 1;
  36. };
  37. void set_duration(int d);
  38. int get_duration();
  39. };
  40.  
  41. Event::Event(string name_s)
  42. {
  43. name = name_s;
  44. }
  45.  
  46. int Event::is_bonus()
  47. {
  48. cout << "NO KURWA " << bonus;
  49. return bonus;
  50. }
  51.  
  52. int hhmm_to_minutes(int hhmm){
  53. int minuty = hhmm % 100;
  54. int godziny = 60 * floor(hhmm / 100);
  55. return godziny + minuty;
  56. }
  57.  
  58. int minutes_to_hhmm(int minutes){
  59. int minuty = minutes % 60;
  60. int godziny = 100 * ((minutes - minuty) / 60);
  61. return godziny + minuty;
  62. }
  63.  
  64. void Chore::set_start_time(int start_time_tmp)
  65. {
  66. start_time = hhmm_to_minutes(start_time_tmp);
  67. cout << endl << "ustawiam start" << start_time << endl;
  68. }
  69.  
  70. void Chore::set_end_time(int end_time_tmp)
  71. {
  72. end_time = hhmm_to_minutes(end_time_tmp);
  73. cout << endl << "ustawiam end" << end_time << endl;
  74. };
  75.  
  76. int Chore::get_end_time()
  77. {
  78. return end_time;
  79. }
  80.  
  81. int Chore::get_start_time()
  82. {
  83. return start_time;
  84. }
  85.  
  86. string Event::get_name()
  87. {
  88. return name;
  89. }
  90.  
  91. void Bonus::set_duration(int d)
  92. {
  93. duration = d;
  94. }
  95.  
  96. int Bonus::get_duration(){
  97. return duration;
  98. }
  99.  
  100.  
  101. void add_event_loop(std::vector<Event*> *chores){
  102. int enter;
  103. string name_tmp;
  104. string enter_tmp;
  105. int start_tmp;
  106. int end_tmp;
  107.  
  108. do {
  109. cout << "- DODAJ WYDARZENIE -" << endl;
  110. cout << "Podaj nazwe wydarzenia: ";
  111. cin >> name_tmp;
  112. cout << "Podaj godzine rozpoczecia (w formacie HHMM): ";
  113. cin >> start_tmp; //przerabia na minuty i zapisuje do zmiennej start_time
  114. cout << "Podaj godzine zakonczenia (w formacie HHMM): ";
  115. cin >> end_tmp;
  116.  
  117. Chore nowy = Chore(name_tmp);
  118. nowy.set_start_time(start_tmp);
  119. nowy.set_end_time(end_tmp);
  120.  
  121. Chore *ptr;
  122. ptr = &nowy;
  123.  
  124. chores->push_back(ptr);
  125.  
  126. cout << "Chcesz dodac jeszcze jedno wydarzenie? (tak lub nie)";
  127.  
  128. cin >> enter_tmp;
  129.  
  130. if (!(enter_tmp).compare("tak")){
  131. enter = 1;
  132. }
  133. else {
  134. enter = 0;
  135. }
  136. } while (enter == 1);
  137.  
  138. return;
  139. };
  140.  
  141.  
  142. void add_bonus_events(std::vector<Event*> *bonus){
  143. Bonus b1 = Bonus("basen");
  144. b1.set_duration(60);
  145.  
  146. Bonus b2 = Bonus("kawa");
  147. b2.set_duration(30);
  148.  
  149. bonus->push_back(&b1);
  150. bonus->push_back(&b2);
  151. }
  152.  
  153. void set_wake_up_and_sleep(int &begin, int &end){
  154. int begin_tmp, end_tmp;
  155. cout << "Podaj godzine wstania (HHMM): ";
  156. cin >> begin_tmp;
  157. begin = hhmm_to_minutes(begin_tmp);
  158. cout << "Podaj godzine pojscia spac (HHMM): ";
  159. cin >> end_tmp;
  160. end = hhmm_to_minutes(end_tmp);
  161. return;
  162. }
  163.  
  164.  
  165. void print_day(int* day, int daylength, int begin, int end){
  166. for (int i = 0; i < daylength; i = i + 15){
  167. // wypisujemy tylko co 15 minut, ale mozna zmienic xD
  168. cout << minutes_to_hhmm(begin + i) << ": " << day[i] << endl;
  169. }
  170.  
  171. }
  172.  
  173.  
  174. int main()
  175. {
  176.  
  177. int begin, end, daylength;
  178.  
  179. std::vector<Event*> events;
  180.  
  181. cout << "Planer dnia" << endl;
  182.  
  183. set_wake_up_and_sleep(begin, end);
  184.  
  185. daylength = end - begin;
  186.  
  187. // tworze os dnia o dlugosci takiej jak dlugosc dnia
  188. int* day = new int[daylength];
  189.  
  190. add_event_loop(&events);
  191. add_bonus_events(&events);
  192.  
  193. cout << "DLUGOSC" << events.size() << endl;
  194.  
  195. for (int i = 0; i < events.size(); i++){
  196.  
  197. cout << "event " << events[i] << endl;
  198.  
  199. cout << events[i]->get_name() << endl;
  200. if (!events[i]->is_bonus()){
  201. cout << "NIE JESTEM BONUSEM" << endl;
  202. Chore* evt = dynamic_cast<Chore*>(events[i]);
  203. if (evt){
  204. cout << "SPOKO";
  205. int start_time = evt->get_start_time();
  206. int end_time = evt->get_end_time();
  207. cout << start_time << " " << begin << " " << end_time << " " << end << endl;
  208. }
  209. }
  210. else {
  211. cout << "JESTEM BONUSEM" << endl;
  212. }
  213. }
  214.  
  215. print_day(day, daylength, begin, end);
  216.  
  217.  
  218. // dodatkowe
  219.  
  220.  
  221. return 0;
  222. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement