Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <vector>
- using namespace std;
- class Event {
- protected:
- string name; //atrybut
- int bonus;
- int start_time;
- int end_time;
- int duration;
- public:
- Event(string name_s);
- string get_name();
- virtual ~Event() {}
- int is_bonus();
- };
- class Chore: public Event {
- public:
- Chore(string name_s) : Event(name_s){
- bonus = 0;
- };
- void set_start_time(int start_t);
- void set_end_time(int end_t);
- int get_start_time();
- int get_end_time();
- };
- class Bonus: public Event {
- public:
- Bonus(string name_s) : Event(name_s){
- bonus = 1;
- };
- void set_duration(int d);
- int get_duration();
- };
- Event::Event(string name_s)
- {
- name = name_s;
- }
- int Event::is_bonus()
- {
- cout << "NO KURWA " << bonus;
- return bonus;
- }
- int hhmm_to_minutes(int hhmm){
- int minuty = hhmm % 100;
- int godziny = 60 * floor(hhmm / 100);
- return godziny + minuty;
- }
- int minutes_to_hhmm(int minutes){
- int minuty = minutes % 60;
- int godziny = 100 * ((minutes - minuty) / 60);
- return godziny + minuty;
- }
- void Chore::set_start_time(int start_time_tmp)
- {
- start_time = hhmm_to_minutes(start_time_tmp);
- cout << endl << "ustawiam start" << start_time << endl;
- }
- void Chore::set_end_time(int end_time_tmp)
- {
- end_time = hhmm_to_minutes(end_time_tmp);
- cout << endl << "ustawiam end" << end_time << endl;
- };
- int Chore::get_end_time()
- {
- return end_time;
- }
- int Chore::get_start_time()
- {
- return start_time;
- }
- string Event::get_name()
- {
- return name;
- }
- void Bonus::set_duration(int d)
- {
- duration = d;
- }
- int Bonus::get_duration(){
- return duration;
- }
- void add_event_loop(std::vector<Event*> *chores){
- int enter;
- string name_tmp;
- string enter_tmp;
- int start_tmp;
- int end_tmp;
- do {
- cout << "- DODAJ WYDARZENIE -" << endl;
- cout << "Podaj nazwe wydarzenia: ";
- cin >> name_tmp;
- cout << "Podaj godzine rozpoczecia (w formacie HHMM): ";
- cin >> start_tmp; //przerabia na minuty i zapisuje do zmiennej start_time
- cout << "Podaj godzine zakonczenia (w formacie HHMM): ";
- cin >> end_tmp;
- Chore nowy = Chore(name_tmp);
- nowy.set_start_time(start_tmp);
- nowy.set_end_time(end_tmp);
- Chore *ptr;
- ptr = &nowy;
- chores->push_back(ptr);
- cout << "Chcesz dodac jeszcze jedno wydarzenie? (tak lub nie)";
- cin >> enter_tmp;
- if (!(enter_tmp).compare("tak")){
- enter = 1;
- }
- else {
- enter = 0;
- }
- } while (enter == 1);
- return;
- };
- void add_bonus_events(std::vector<Event*> *bonus){
- Bonus b1 = Bonus("basen");
- b1.set_duration(60);
- Bonus b2 = Bonus("kawa");
- b2.set_duration(30);
- bonus->push_back(&b1);
- bonus->push_back(&b2);
- }
- void set_wake_up_and_sleep(int &begin, int &end){
- int begin_tmp, end_tmp;
- cout << "Podaj godzine wstania (HHMM): ";
- cin >> begin_tmp;
- begin = hhmm_to_minutes(begin_tmp);
- cout << "Podaj godzine pojscia spac (HHMM): ";
- cin >> end_tmp;
- end = hhmm_to_minutes(end_tmp);
- return;
- }
- void print_day(int* day, int daylength, int begin, int end){
- for (int i = 0; i < daylength; i = i + 15){
- // wypisujemy tylko co 15 minut, ale mozna zmienic xD
- cout << minutes_to_hhmm(begin + i) << ": " << day[i] << endl;
- }
- }
- int main()
- {
- int begin, end, daylength;
- std::vector<Event*> events;
- cout << "Planer dnia" << endl;
- set_wake_up_and_sleep(begin, end);
- daylength = end - begin;
- // tworze os dnia o dlugosci takiej jak dlugosc dnia
- int* day = new int[daylength];
- add_event_loop(&events);
- add_bonus_events(&events);
- cout << "DLUGOSC" << events.size() << endl;
- for (int i = 0; i < events.size(); i++){
- cout << "event " << events[i] << endl;
- cout << events[i]->get_name() << endl;
- if (!events[i]->is_bonus()){
- cout << "NIE JESTEM BONUSEM" << endl;
- Chore* evt = dynamic_cast<Chore*>(events[i]);
- if (evt){
- cout << "SPOKO";
- int start_time = evt->get_start_time();
- int end_time = evt->get_end_time();
- cout << start_time << " " << begin << " " << end_time << " " << end << endl;
- }
- }
- else {
- cout << "JESTEM BONUSEM" << endl;
- }
- }
- print_day(day, daylength, begin, end);
- // dodatkowe
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement