-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeek 26 Homework.cpp
More file actions
892 lines (738 loc) · 35.3 KB
/
Week 26 Homework.cpp
File metadata and controls
892 lines (738 loc) · 35.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
#include <windows.h>
#include <iostream>
#include <string> // getline()
using namespace std;
class Telescope
{
private:
char* brand = nullptr; // покажчик на бренд
char* model = nullptr; // покажчик на модель
char* opticalDesign = nullptr; // покажчик на оптичну конструкцію
char* aperture = nullptr; // покажчик на діаметр об'єктива
char* focalLength = nullptr; // покажчик на фокусну відстань
char* mountType = nullptr; // покажчик на тип монтування
char* eyepiece = nullptr; // покажчик на опис окуляра
char* filter = nullptr; // покажчик на світлофільтр
char* skyObject = nullptr; // покажчик на небесне тіло
bool isAimed; // чи наведено телескоп на об'єкт?
bool isFocused; // чи виконано фокусування?
// Приватний метод ініціалізації для делегування
void InitTelescope(const string& brand = "Celestron",
const string& model = "PowerSeeker 70 AZ",
const string& opticalDesign = "Рефрактор",
const string& aperture = "70 мм",
const string& focalLength = "70 см",
const string& mountType = "Азимутальне",
const string& eyepiece = "20 мм (35x), 1,25\"",
const string& filter = "Відсутній",
const string& skyObject = "Місяць")
{
this->brand = new char[brand.length() + 1];
// https://en.cppreference.com/w/c/string/byte/strcpy
strcpy_s(this->brand, brand.length() + 1, brand.c_str());
// https://cplusplus.com/reference/string/string/c_str/
this->model = new char[model.length() + 1];
strcpy_s(this->model, model.length() + 1, model.c_str());
this->opticalDesign = new char[opticalDesign.length() + 1];
strcpy_s(this->opticalDesign, opticalDesign.length() + 1,
opticalDesign.c_str());
this->aperture = new char[aperture.length() + 1];
strcpy_s(this->aperture, aperture.length() + 1, aperture.c_str());
this->focalLength = new char[focalLength.length() + 1];
strcpy_s(this->focalLength, focalLength.length() + 1,
focalLength.c_str());
this->mountType = new char[mountType.length() + 1];
strcpy_s(this->mountType, mountType.length() + 1, mountType.c_str());
this->eyepiece = new char[eyepiece.length() + 1];
strcpy_s(this->eyepiece, eyepiece.length() + 1, eyepiece.c_str());
this->filter = new char[filter.length() + 1];
strcpy_s(this->filter, filter.length() + 1, filter.c_str());
this->skyObject = new char[skyObject.length() + 1];
strcpy_s(this->skyObject, skyObject.length() + 1, skyObject.c_str());
isAimed = false;
isFocused = false;
}
public:
// Конструктор за замовчуванням
Telescope()
{
InitTelescope();
}
// Конструктор із параметрами
Telescope(const string& brand, const string& model,
const string& opticalDesign, const string& aperture,
const string& focalLength, const string& mountType,
const string& eyepiece, const string& filter, const string& skyObject)
{
InitTelescope(brand, model, opticalDesign, aperture, focalLength,
mountType, eyepiece, filter, skyObject);
}
// Конструктор копіювання
Telescope(const Telescope& other)
{
InitTelescope(other.brand, other.model, other.opticalDesign,
other.aperture, other.focalLength, other.mountType,
other.eyepiece, other.filter, other.skyObject);
this->isAimed = other.isAimed;
this->isFocused = other.isFocused;
}
// Деструктор
~Telescope()
{
delete[] brand;
delete[] model;
delete[] opticalDesign;
delete[] aperture;
delete[] focalLength;
delete[] mountType;
delete[] eyepiece;
delete[] filter;
delete[] skyObject;
}
// Сеттери для покажчиків
void SetBrand(const string& brand)
{
if (brand.empty()) throw string("Бажано зазначити бренд телескопа!");
delete[] this->brand;
this->brand = new char[brand.length() + 1];
strcpy_s(this->brand, brand.length() + 1, brand.c_str());
}
void SetModel(const string& model)
{
if (model.empty()) throw string("Бажано зазначити модель телескопа!");
delete[] this->model;
this->model = new char[model.length() + 1];
strcpy_s(this->model, model.length() + 1, model.c_str());
}
void SetOpticalDesign(const string& opticalDesign)
{
if (opticalDesign.empty()) throw string("Рефрактор чи рефлектор?..");
delete[] this->opticalDesign;
this->opticalDesign = new char[opticalDesign.length() + 1];
strcpy_s(this->opticalDesign, opticalDesign.length() + 1,
opticalDesign.c_str());
}
void SetAperture(const string& aperture)
{
if (aperture.empty())
throw string("Будь ласка, вкажіть діаметр об'єктива в міліметрах");
delete[] this->aperture;
this->aperture = new char[aperture.length() + 1];
strcpy_s(this->aperture, aperture.length() + 1, aperture.c_str());
}
void SetFocalLength(const string& focalLength)
{
if (focalLength.empty())
throw string("Будь ласка, вкажіть фокусну відстань телескопа "
"в міліметрах, сантиметрах, метрах!..");
delete[] this->focalLength;
this->focalLength = new char[focalLength.length() + 1];
strcpy_s(this->focalLength, focalLength.length() + 1,
focalLength.c_str());
}
void SetMountType(const string& mountType)
{
if (mountType.empty())
throw string("Монтування азимутальне, екваторіальне, Добсона, "
"виделкове, екваторіально-азимутальне?..");
delete[] this->mountType;
this->mountType = new char[mountType.length() + 1];
strcpy_s(this->mountType, mountType.length() + 1, mountType.c_str());
}
void SetEyepiece(const string& eyepiece)
{
if (eyepiece.empty()) throw string("Спробуйте з комплектним окуляром");
delete[] this->eyepiece;
this->eyepiece = new char[eyepiece.length() + 1];
strcpy_s(this->eyepiece, eyepiece.length() + 1, eyepiece.c_str());
this->isFocused = false;
}
void SetterFilter(const string& filter)
{
if (filter.empty())
throw string("Передивіться свій новий набір світлофільтрів.");
delete[] this->filter;
this->filter = new char[filter.length() + 1];
strcpy_s(this->filter, filter.length() + 1, filter.c_str());
}
void SetSkyObject(const string& skyObject)
{
if ((skyObject == "Сонце" || skyObject == "The Sun" ||
skyObject == "Sun") && strcmp(this->filter, "Сонячний") != 0)
// https://en.cppreference.com/w/c/string/byte/strcmp.html
throw string("Ніколи не дивіться на Сонце без спеціального "
"сонячного світлофільтра — це дуже небезпечно!"
" Найкраще — використовуйте метод проєкції на екран.");
delete[] this->skyObject;
this->skyObject = new char[skyObject.length() + 1];
strcpy_s(this->skyObject, skyObject.length() + 1, skyObject.c_str());
}
void SetIsAimed(bool isAimed = true)
{
this->isAimed = isAimed;
}
void SetIsFocused(bool isFocused = true)
{
this->isFocused = isFocused;
}
// Геттери для покажчиків
string GetBrand() const { return string(brand); }
string GetModel() const { return string(model); }
string GetOpticalDesign() const { return string(opticalDesign); }
string GetAperture() const { return string(aperture); }
string GetFocalLength() const { return string(focalLength); }
string GetMountType() const { return string(mountType); }
string GetEyepiece() const { return string(eyepiece); }
string GetFilter() const { return string(filter); }
string GetSkyObject() const { return string(skyObject); }
bool GetIsAimed() const { return this->isAimed; }
bool GetIsFocused() const { return this->isFocused; }
// Метод для встановлення характеристик телескопа
void InputTelescopeData()
{
system("cls");
cout << "\tАБСТРАГУВАННЯ: ДАВНО НЕ СПОСТЕРІГАВ ЗОРЯНЕ НЕБО\n\n";
string input; // допоміжна змінна для збереження введеного тексту
cout << "Маєте телескоп? Введіть бренд: ";
getline(cin, input);
if (!input.empty()) SetBrand(input);
cout << "Введіть модель телескопа: ";
getline(cin, input);
if (!input.empty()) SetModel(input);
cout << "Введіть різновид оптичної конструкції: ";
getline(cin, input);
if (!input.empty()) SetOpticalDesign(input);
cout << "Введіть діаметр об'єктива (зазначте одиницю): ";
getline(cin, input);
if (!input.empty()) SetAperture(input);
cout << "Введіть фокусну відстань (зазначте одиницю): ";
getline(cin, input);
if (!input.empty()) SetFocalLength(input);
cout << "Введіть тип монтування: ";
getline(cin, input);
if (!input.empty()) SetMountType(input);
}
// Метод для наведення на астрономічний об'єкт
void AimAtObject(const string& skyObject)
{
SetSkyObject(skyObject);
this->isAimed = true;
}
// Метод для фокусування
void FocusTelescope()
{
if (this->isAimed) this->isFocused = true;
}
// Метод для заміни окуляра
void ChangeEyepiece(const string& otherEyepiece)
{
delete[] this->eyepiece;
this->eyepiece = new char[otherEyepiece.length() + 1];
strcpy_s(this->eyepiece, otherEyepiece.length() + 1,
otherEyepiece.c_str());
isFocused = false;
}
// Метод для встановлення світлофільтра
void SetFilter(const string& newFilter)
{
delete[] this->filter;
this->filter = new char[newFilter.length() + 1];
strcpy_s(this->filter, newFilter.length() + 1, newFilter.c_str());
}
// Метод для виведення всієї інформації та стану дій
void PrintInfo(const string& comment) const
{
system("cls");
cout << "\tПрограма - журнал спостережень зоряного неба\n\n";
cout << "Телескоп: " << GetBrand() << " " << GetModel() << "\n";
cout << "Оптична конструкція: " << GetOpticalDesign() << "\n";
cout << "Діаметр об'єктива: " << GetAperture() << "\n";
cout << "Фокусна відстань: " << GetFocalLength() << "\n";
cout << "Тип монтування: " << GetMountType() << "\n";
cout << "\nОкуляр: " << GetEyepiece() << "\n";
cout << "Світлофільтр: " << GetFilter() << "\n";
cout << "\nТелескоп " << (GetIsAimed() ? "наведено на " +
GetSkyObject() + "." :
"ще не наведено, скористайтесь шукачем!") << "\n";
cout << "Фокусування " << (GetIsFocused() ? "виконано!" :
"ще не виконано!") << "\n";
cout << "\n\nКОМЕНТАР: " << comment << "\n";
}
};
class WaterBottle
{
private:
string* brand; // покажчик на бренд
string* producer; // покажчик на завод-виробник
float* capacity; // покажчик на об'єм бутеля
float* currentVolume; // покажчик на поточний рівень води
string* expirationDate; // покажчик на кінцеву дату споживання
string* mineralization; // покажчик на мінералізацію води
string* material; // покажчик на матеріал бутеля
bool isExpired = false; // чи термін споживання закінчився?
bool isOpened = false; // чи відкритий бутель?
bool isBeingPoured = false; // чи наливається вода?
bool isWiped = false; // чи бутель був протертий серветкою?
// Приватний метод ініціалізації для делегування
void InitWaterBottle(const string& brand = "Моршинська",
const string& producer = "Моршинський завод мінеральних вод \"Оскар\"",
const float& capacity = 6.0f,
const float& currentVolume = 6.0f,
const string& expirationDate = "02.11.25",
const string& mineralization = "0,1-0,4 г/л",
const string& material = "Пластик")
{
this->brand = new string(brand);
this->producer = new string(producer);
this->capacity = new float(capacity);
this->currentVolume = new float(currentVolume);
this->expirationDate = new string(expirationDate);
this->mineralization = new string(mineralization);
this->material = new string(material);
isExpired = false;
isOpened = false;
isBeingPoured = false;
isWiped = false;
}
public:
// Конструктор за замовчуванням
WaterBottle()
{
InitWaterBottle();
}
// Конструктор із параметрами
WaterBottle(const string& brand, const string& producer,
const float& capacity, const float& currentVolume,
const string& expirationDate, const string& mineralization,
const string& material)
{
InitWaterBottle(brand, producer, capacity, currentVolume,
expirationDate, mineralization, material);
}
// Конструктор копіювання
WaterBottle(const WaterBottle& other)
{
InitWaterBottle(*other.brand, *other.producer, *other.capacity,
*other.currentVolume, *other.expirationDate,
*other.mineralization, *other.material);
this->isExpired = other.isExpired;
this->isOpened = other.isOpened;
this->isBeingPoured = other.isBeingPoured;
this->isWiped = other.isWiped;
}
// Деструктор
~WaterBottle()
{
delete brand;
delete producer;
delete capacity;
delete currentVolume;
delete expirationDate;
delete mineralization;
delete material;
}
// Сеттери для покажчиків
void SetBrand(const string& brand)
{
if (!brand.empty()) *this->brand = brand;
}
void SetProducer(const string& producer)
{
if (!producer.empty()) *this->producer = producer;
}
void SetCapacity(float capacity)
{
if (capacity < 1.0 || capacity > 25.0)
throw string("Об'єм бутеля має бути в межах 1 - 25 літрів!");
*this->capacity = capacity;
if (*this->currentVolume > *this->capacity)
*this->currentVolume = *this->capacity;
}
void SetCurrentVolume(float currentVolume)
{
if (currentVolume < 0 || currentVolume > *this->capacity)
throw string("Поточний об'єм води в літрах має бути в межах "
"від 0 до максимальної ємності бутеля!");
*this->currentVolume = currentVolume;
}
void SetExpirationDate(const string& expirationDate)
{
if (expirationDate.length() != 8 || expirationDate[2] != '.' ||
expirationDate[5] != '.')
throw string("Дата має бути вказана щонайменше у форматі"
" ДД.ММ.РР та проходити повну валідацію!");
*this->expirationDate = expirationDate;
}
void SetMineralization(const string& mineralization)
{
if (!mineralization.empty()) *this->mineralization = mineralization;
}
void SetMaterial(const string& material)
{
if (material != "Пластик" && material != "пластик" &&
material != "Скло" && material != "скло" &&
material != "Нержавіюча сталь" && material != "нержавіюча сталь" &&
material != "Харчовий пластик" && material != "харчовий пластик")
throw string("Виберіть придатний матеріал для зберігання води!");
*this->material = material;
}
void SetIsExpired(bool isExpired = true)
{
this->isExpired = isExpired;
}
void SetIsOpened(bool isOpened = true)
{
this->isOpened = isOpened;
}
void SetIsBeingPoured(bool isBeingPoured = true)
{
this->isBeingPoured = isBeingPoured;
}
void SetIsWiped(bool isWiped = true)
{
this->isWiped = isWiped;
}
// Геттери для покажчиків
string GetBrand() const { return *this->brand; }
string GetProducer() const { return *this->producer; }
float GetCapacity() const { return *this->capacity; }
float GetCurrentVolume() const { return *this->currentVolume; }
string GetExpirationDate() const { return *this->expirationDate; }
string GetMineralization() const { return *this->mineralization; }
string GetMaterial() const { return *this->material; }
bool GetIsExpired() const { return isExpired; }
bool GetIsOpened() const { return isOpened; }
bool GetIsBeingPoured() const { return isBeingPoured; }
bool GetIsWiped() const { return isWiped; }
// Метод для введення характеристик бутеля
void InputBottleData()
{
system("cls");
cout << "\tАБСТРАГУВАННЯ: НЕМАЄ ВОДИ\n\n";
string input;
cout << "Введіть відомий бренд: ";
getline(cin, input);
if (!input.empty()) SetBrand(input);
cout << "Введіть завод-виробник: ";
getline(cin, input);
if (!input.empty()) SetProducer(input);
cout << "Введіть об'єм бутеля: ";
cin >> *this->capacity;
cin.ignore();
cout << "Введіть кінцеву дату споживання у форматі ЧЧ.ММ.РР: ";
getline(cin, input);
if (!input.empty()) SetExpirationDate(input);
cout << "Визначте рівень мінералізації води: ";
getline(cin, input);
if (!input.empty()) SetMineralization(input);
cout << "Зазначте матеріал бутеля: ";
getline(cin, input);
if (!input.empty()) SetMaterial(input);
}
// Метод для перевірки терміну придатності
void CheckExpiration()
{
// Отримуємо поточний час у секундах з 1970-01-01 (epoch time)
time_t now = time(nullptr);
// https://learn.microsoft.com/ru-ru/cpp/c-runtime-library/reference/time-time32-time64?view=msvc-170
// Перетворюємо часовий штамп у локальний час
struct tm localTime;
localtime_s(&localTime, &now);
// https://learn.microsoft.com/ru-ru/cpp/c-runtime-library/reference/localtime-s-localtime32-s-localtime64-s?view=msvc-170
// Доступ до компонентів дати - поточні день, місяць, рік:
int todayDay = localTime.tm_mday;
int todayMonth = localTime.tm_mon + 1; // tm_mon починається з 0
int todayYear = localTime.tm_year + 1900; // відлік з 1900
// Перетворюємо кінцеву дату споживання, використовуючи метод для
// отримання підрядка та функцію для перетворення рядка на число
int day = stoi(expirationDate->substr(0, 2));
int month = stoi(expirationDate->substr(3, 2));
int year = stoi(expirationDate->substr(6, 2)) + 2000;
// Оновлюємо булеву змінну "прострочено"
this->isExpired = year < todayYear ||
(year == todayYear && month < todayMonth) ||
(year == todayYear && month == todayMonth && day < todayDay + 2);
}
// Метод для відкривання бутеля
void OpenBottle()
{
if (!this->isExpired) this->isOpened = true;
}
// Метод для закриття бутеля
void CloseBottle()
{
this->isBeingPoured = false;
this->isOpened = false;
}
// Метод для наливання води (по 3 л за раз)
void PourWater()
{
if (this->isOpened && *this->currentVolume >= 3.0)
{
this->isBeingPoured = true;
*this->currentVolume -= 3.0;
}
else
{
this->isBeingPoured = false;
cout << "Води більше немає!" << "\n";
}
}
// Метод для протирання бутеля серветкою
void WipeBottle()
{
this->isWiped = true;
}
// Метод для виведення інформації про бутель
void PrintInfo(const string& comment) const
{
system("cls");
cout << "\tСТАН БУТЕЛЯ ВОДИ\n\n";
cout << "Бренд води для щоденного вживання: " << *this->brand << "\n";
cout << "Виробник: " << *this->producer << "\n";
cout << "Об'єм: " << *this->capacity << "\n";
cout << "Вжити до: " << *this->expirationDate << "\n";
cout << "Мінералізація води: " << *this->mineralization << "\n";
cout << "Матеріал бутеля: " << *this->material << "\n";
cout << "\nБутель " << (this->isWiped ?
"протертий вологою серветкою!" : "ще не протертий") << "\n";
cout << (this->isExpired ? "Термін споживання закінчився!" :
"Термін споживання ще не закінчився") << "\n";
cout << "Бутель " << (this->isOpened ? "відкритий!" :
"закритий") << "\n";
cout << "Поточний рівень води: " << *this->currentVolume << " л\n";
cout << (this->isBeingPoured ? "Наливаємо воду!" : "") << "\n";
cout << "\nКОМЕНТАР: " << comment << "\n";
}
};
class GetterShowCaseTask
{
public:
static void DisplayTelescopeFields(const Telescope* telescope)
{
if (!telescope) {
cout << "Об'єкт Telescope не знайдено за вказаною адресою!\n";
return;
}
cout << "\n\n\n\t==== Telescope Object State ====\n\n";
cout << "class Telescope\n";
cout << "{\n";
cout << "private:\n";
cout << "\tstring brand = \"" << telescope->GetBrand() << "\";\n";
cout << "\tstring model = \"" << telescope->GetModel() << "\";\n";
cout << "\tstring opticalDesign = \""
<< telescope->GetOpticalDesign() << "\";\n";
cout << "\tstring aperture = \""
<< telescope->GetAperture() << "\";\n";
cout << "\tstring focalLength = \""
<< telescope->GetFocalLength() << "\";\n";
cout << "\tstring mountType = \""
<< telescope->GetMountType() << "\";\n";
cout << "\tstring eyepiece = \""
<< telescope->GetEyepiece() << "\";\n";
cout << "\tstring filter = \"" << telescope->GetFilter() << "\";\n";
cout << "\tbool isAimed = "
<< (telescope->GetIsAimed() ? "true" : "false") << ";\n";
cout << "\tbool isFocused = "
<< (telescope->GetIsFocused() ? "true" : "false") << ";\n";
cout << "\tstring skyObject = \""
<< telescope->GetSkyObject() << "\";\n";
}
static void DisplayWaterBottleFields(const WaterBottle* waterbottle)
{
if (!waterbottle) {
cout << "Об'єкт WaterBottle не знайдено за вказаною адресою!\n";
return;
}
cout << "\n\n\n\t==== WaterBottle Object State ====\n\n";
cout << "class WaterBottle\n";
cout << "{\n";
cout << "private:\n";
cout << "\tstring brand = \"" << waterbottle->GetBrand() << "\";\n";
cout << "\tstring producer = \""
<< waterbottle->GetProducer() << "\";\n";
cout << "\tfloat capacity = " << waterbottle->GetCapacity() << ";\n";
cout << "\tfloat currentVolume = "
<< waterbottle->GetCurrentVolume() << ";\n";
cout << "\tstring expirationDate = \""
<< waterbottle->GetExpirationDate() << "\";\n";
cout << "\tstring mineralization = \""
<< waterbottle->GetMineralization() << "\";\n";
cout << "\tstring material = \""
<< waterbottle->GetMaterial() << "\";\n";
cout << "\tbool isExpired = "
<< (waterbottle->GetIsExpired() ? "true" : "false") << ";\n";
cout << "\tbool isOpened = "
<< (waterbottle->GetIsOpened() ? "true" : "false") << ";\n";
cout << "\tbool isBeingPoured = "
<< (waterbottle->GetIsBeingPoured() ? "true" : "false") << ";\n";
cout << "\tbool isWiped = "
<< (waterbottle->GetIsWiped() ? "true" : "false") << ";\n";
}
};
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
// Використання конструктора за замовчуванням для Telescope
Telescope myTelescope;
myTelescope.InputTelescopeData();
myTelescope.PrintInfo("Підготовка телескопа"); Sleep(20000);
myTelescope.AimAtObject("Місяць");
myTelescope.PrintInfo("Захоплення в поле зору"); Sleep(20000);
myTelescope.FocusTelescope();
myTelescope.PrintInfo("Спостереження з малим збільшенням"); Sleep(20000);
myTelescope.ChangeEyepiece("4 мм (175х), 1,25\"");
myTelescope.SetFilter("Місячний фільтр");
myTelescope.PrintInfo("Установлення аксесуарів"); Sleep(20000);
myTelescope.FocusTelescope();
myTelescope.PrintInfo("Спостереження з великим збільшенням"); Sleep(30000);
// Використання сеттерів для Telescope
Telescope newTelescope;
try {
newTelescope.SetBrand("Celestron");
newTelescope.SetModel("AstroMaster 130");
newTelescope.SetOpticalDesign("Рефлектор Ньютона");
newTelescope.SetAperture("130 мм");
newTelescope.SetFocalLength("750 мм");
newTelescope.SetMountType("Екваторіальне з автостеженням");
newTelescope.SetEyepiece("Стандартний окуляр 10 мм");
newTelescope.SetterFilter("Світло-жовтий");
newTelescope.SetIsAimed();
newTelescope.SetIsFocused();
newTelescope.SetSkyObject("Місяць біля Сатурна, Нептуна, Урана і "
"Плеяд");
newTelescope.PrintInfo("Встановлено телескоп");
GetterShowCaseTask::DisplayTelescopeFields(&newTelescope);
Sleep(15000);
system("cls");
newTelescope.SetIsAimed(false);
newTelescope.SetIsFocused(false);
newTelescope.SetFilter("Сонячний");
newTelescope.SetSkyObject("Сонце");
newTelescope.FocusTelescope();
newTelescope.PrintInfo("DANGER");
GetterShowCaseTask::DisplayTelescopeFields(&newTelescope);
Sleep(30000);
}
catch (const string& message) {
cerr << "\n" << message << "\n";
}
// Використання конструктора з параметрами для Telescope
try {
Telescope customTelescope("Celestron", "AstroMaster 130",
"Рефлектор Ньютона", "130 мм", "750 мм",
"Екваторіальне з автостеженням", "Стандартний окуляр 10 мм",
"Світло-жовтий", "Місяць біля Сатурна, Нептуна, Урана і Плеяд");
customTelescope.PrintInfo("Створено телескоп із заданими параметрами");
GetterShowCaseTask::DisplayTelescopeFields(&customTelescope);
Sleep(15000);
system("cls");
}
catch (const string& message) {
cerr << "\n" << message << "\n";
}
// Використання конструктора копіювання для Telescope
try {
Telescope copiedTelescope(myTelescope);
copiedTelescope.SetSkyObject("Марс");
copiedTelescope.PrintInfo("Скопійовано телескоп");
GetterShowCaseTask::DisplayTelescopeFields(&copiedTelescope);
Sleep(15000);
system("cls");
}
catch (const string& message) {
cerr << "\n" << message << "\n";
}
// Використання конструктора за замовчуванням для WaterBottle
WaterBottle oneBottle;
oneBottle.InputBottleData();
oneBottle.PrintInfo("Стоїть бутель"); Sleep(10000);
oneBottle.CheckExpiration();
oneBottle.PrintInfo("Перевіримо дату"); Sleep(10000);
oneBottle.WipeBottle();
oneBottle.PrintInfo("Треба протерти від пилу"); Sleep(10000);
oneBottle.OpenBottle();
oneBottle.PrintInfo("Відкриваємо бутель"); Sleep(10000);
oneBottle.PourWater();
oneBottle.PrintInfo("Наливаємо 3 л"); Sleep(10000);
oneBottle.CloseBottle();
oneBottle.PrintInfo("Закриваємо кришкою"); Sleep(10000);
oneBottle.OpenBottle();
oneBottle.PrintInfo("Відкриваємо бутель"); Sleep(10000);
oneBottle.PourWater();
oneBottle.PrintInfo("Наливаємо 3 л"); Sleep(10000);
oneBottle.CloseBottle();
oneBottle.PrintInfo("Закриваємо кришкою"); Sleep(10000);
oneBottle.OpenBottle();
oneBottle.PrintInfo("Відкриваємо бутель"); Sleep(10000);
oneBottle.PourWater();
oneBottle.PrintInfo("А бутель спорожнів"); Sleep(10000);
oneBottle.CloseBottle();
oneBottle.PrintInfo("Закриваємо кришкою"); Sleep(30000);
// Використання сеттерів для WaterBottle
WaterBottle anotherBottle;
try {
GetterShowCaseTask::DisplayWaterBottleFields(&anotherBottle);
Sleep(15000);
system("cls");
anotherBottle.SetBrand("AquaLife");
anotherBottle.SetProducer("Миргородський завод мінеральних вод");
anotherBottle.SetCapacity(5.0f);
anotherBottle.SetCurrentVolume(5.0f);
anotherBottle.SetExpirationDate("05.06.26");
anotherBottle.SetMineralization("300-500 мг/л");
anotherBottle.SetMaterial("Харчовий пластик");
anotherBottle.SetIsExpired(false);
anotherBottle.SetIsOpened(false);
anotherBottle.SetIsBeingPoured(false);
anotherBottle.SetIsWiped(false);
anotherBottle.PrintInfo("Принесли з магазину");
GetterShowCaseTask::DisplayWaterBottleFields(&anotherBottle);
Sleep(20000);
system("cls");
anotherBottle.CheckExpiration();
anotherBottle.WipeBottle();
anotherBottle.PrintInfo("Ще раз перевірили дату, протремо");
GetterShowCaseTask::DisplayWaterBottleFields(&anotherBottle);
Sleep(20000);
system("cls");
}
catch (const string& message) {
cerr << "\n" << message << "\n";
}
// Використання конструктора з параметрами для WaterBottle
try {
WaterBottle customBottle("AquaLife",
"Миргородський завод мінеральних вод", 5.0f, 5.0f,
"05.06.26", "300-500 мг/л", "Харчовий пластик");
customBottle.PrintInfo("Створено бутель із заданими параметрами");
GetterShowCaseTask::DisplayWaterBottleFields(&customBottle);
Sleep(15000);
system("cls");
customBottle.CheckExpiration();
customBottle.WipeBottle();
customBottle.OpenBottle();
customBottle.PourWater();
customBottle.PrintInfo("Наливаємо воду з нового бутеля");
GetterShowCaseTask::DisplayWaterBottleFields(&customBottle);
Sleep(15000);
system("cls");
}
catch (const string& message) {
cerr << "\n" << message << "\n";
}
// Використання конструктора копіювання для WaterBottle
try {
WaterBottle copiedBottle(oneBottle);
copiedBottle.SetBrand("Пізно пити Боржомі");
copiedBottle.PrintInfo("Скопійовано бутель і змінено бренд");
GetterShowCaseTask::DisplayWaterBottleFields(&copiedBottle);
Sleep(15000);
system("cls");
}
catch (const string& message) {
cerr << "\n" << message << "\n";
}
return 0;
}