working on...
This commit is contained in:
		| @@ -42,6 +42,24 @@ bool ask_question(const string& question) | ||||
|     } | ||||
| } | ||||
|  | ||||
| class date final | ||||
| { | ||||
| private: | ||||
|     unsigned short day_; | ||||
|     unsigned short month_; | ||||
|     unsigned short year_; | ||||
| public: | ||||
|     date(const unsigned short day, const unsigned short month, const unsigned short year) : day_(day), month_(month), | ||||
|                                                                                             year_(year) | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     int get_sum() const | ||||
|     { | ||||
|         return year_ + month_ + day_; | ||||
|     } | ||||
| }; | ||||
|  | ||||
| class address final | ||||
| { | ||||
| private: | ||||
| @@ -150,18 +168,34 @@ class reservation final | ||||
| { | ||||
| private: | ||||
|     int id_; | ||||
|     string start_ = {}; | ||||
|     string end_ = {}; | ||||
|     date start_; | ||||
|     date end_; | ||||
|     short motorcycle_ = -1; // => -1 means nothing reserved | ||||
|     customer* customer_; | ||||
| public: | ||||
|     reservation(string start, string end, const short motorcycle, customer* customer) : id_(++next_reservation_id), | ||||
|                                                                                         start_(move(start)), | ||||
|                                                                                         end_(move(end)), | ||||
|                                                                                         motorcycle_(motorcycle), | ||||
|                                                                                         customer_(customer) | ||||
|     reservation(const date start, const date end, const short motorcycle, customer* customer) : | ||||
|         id_(++next_reservation_id), | ||||
|         start_(start), | ||||
|         end_(end), | ||||
|         motorcycle_(motorcycle), | ||||
|         customer_(customer) | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     date get_start_date() const | ||||
|     { | ||||
|         return start_; | ||||
|     } | ||||
|  | ||||
|     date get_end_date() const | ||||
|     { | ||||
|         return end_; | ||||
|     } | ||||
|  | ||||
|     short get_motorcycle() const | ||||
|     { | ||||
|         return motorcycle_; | ||||
|     } | ||||
| }; | ||||
|  | ||||
| string motorcycles[] = | ||||
| @@ -261,28 +295,21 @@ vector<customer*> find_customers_by_name(const string& name) | ||||
|     return result; | ||||
| } | ||||
|  | ||||
| bool validate_date(string& date) | ||||
| { | ||||
|     auto day = 0, month = 0, year = 0; | ||||
|     const auto res = sscanf_s(date.c_str(), "%2d.%2d.%4d", | ||||
|                               &day, | ||||
|                               &month, | ||||
|                               &year); | ||||
|     if (res != 3) return false; | ||||
|     if (month < 1 || month > 12) return false; | ||||
|     if (day < 1 || day > 31) return false; | ||||
|     if (year < 1900 || month > 2200) return false; | ||||
|     return true; | ||||
| } | ||||
|  | ||||
| string get_validated_date(const string&& question) | ||||
| date get_validated_date(const string&& question) | ||||
| { | ||||
|     while (true) | ||||
|     { | ||||
|         auto date = ask_question<string>(question + " (tt.mm.jjjj)"); | ||||
|         if (validate_date(date)) | ||||
|         auto date_as_string = ask_question<string>(question + " (tt.mm.jjjj)"); | ||||
|  | ||||
|         unsigned short day = 0, month = 0, year = 0; | ||||
|         const auto res = sscanf_s(date_as_string.c_str(), "%2d.%2d.%4d", | ||||
|                                   &day, | ||||
|                                   &month, | ||||
|                                   &year); | ||||
|  | ||||
|         if (res == 3 && (month >= 1 && month <= 12) && (day >= 1 && day <= 31) && (year >= 1900 && month <= 2200)) | ||||
|         { | ||||
|             return date; | ||||
|             return date{day, month, year}; | ||||
|         } | ||||
|         cout << "Fehlerhafte Eingabe." << endl; | ||||
|     } | ||||
| @@ -320,6 +347,21 @@ int select_motorcycle() | ||||
|     } | ||||
| } | ||||
|  | ||||
|  | ||||
| bool validate_reservation(reservation* const reservation) | ||||
| { | ||||
|     for (auto r : reservations) | ||||
|     { | ||||
|         if(r->get_motorcycle() == reservation->get_motorcycle()) | ||||
|         { | ||||
|             if(reservation->get_start_date().get_sum() > r->get_end_date().get_sum()) | ||||
|             { | ||||
|                 //TODO | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| void create_reservation() | ||||
| { | ||||
|     system("cls"); | ||||
| @@ -352,7 +394,10 @@ void create_reservation() | ||||
|     const auto end_date = get_validated_date("Enddatum"); | ||||
|     const auto motorcycle = select_motorcycle(); | ||||
|     const auto r = new reservation(start_date, end_date, motorcycle, current); | ||||
|     reservations.push_back(r); | ||||
|     if (validate_reservation(r)) | ||||
|     { | ||||
|         reservations.push_back(r); | ||||
|     } | ||||
| } | ||||
|  | ||||
| void rent_a_motorcycle() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Holger Boerchers
					Holger Boerchers