diff options
| author | Syndamia <kamen@syndamia.com> | 2024-03-20 13:20:09 +0200 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2024-03-20 13:20:09 +0200 |
| commit | cdd5b6c28b12a4763c9b1eef9ba45ca85a6ddaa2 (patch) | |
| tree | c3dca402c9203b0e06b06574bd6459b3b58d5fbd /week04/Exercise1.cpp | |
| parent | 6b7a20b652bd3388ceaac60c96479419ac2c4859 (diff) | |
| download | oop-2023-solutions-cdd5b6c28b12a4763c9b1eef9ba45ca85a6ddaa2.tar oop-2023-solutions-cdd5b6c28b12a4763c9b1eef9ba45ca85a6ddaa2.tar.gz oop-2023-solutions-cdd5b6c28b12a4763c9b1eef9ba45ca85a6ddaa2.zip | |
[w4] Solved exercises 1-5
Diffstat (limited to 'week04/Exercise1.cpp')
| -rw-r--r-- | week04/Exercise1.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/week04/Exercise1.cpp b/week04/Exercise1.cpp new file mode 100644 index 0000000..09e1286 --- /dev/null +++ b/week04/Exercise1.cpp @@ -0,0 +1,50 @@ +#include <cstring> + +struct Smartphone { +private: + char brand[129]; + char model[513]; + unsigned manufacturingYear; + float cameraResolution; + +public: + const char* GetBrand() { + return brand; + } + void SetBrand(const char* newValue) { + if (newValue[0] == '\0' || strlen(newValue) > 128) { + throw "Brand cannot be empty string or longer than 128 characters!"; + } + strcpy(brand, newValue); + } + + const char* GetModel() { + return model; + } + void SetModel(const char* newValue) { + if (newValue[0] == '\0' || strlen(newValue) > 512) { + throw "Model cannot be empty string or longer than 512 characters!"; + } + strcpy(model, newValue); + } + + unsigned GetManufacturingYear() { + return manufacturingYear; + } + void SetManufacturingYear(unsigned newValue) { + if (newValue < 2000 || 2024 < newValue) { + throw "Manufacturing year cannot be before 2000 or after 2024!"; + } + manufacturingYear = newValue; + } + + float GetCameraResolution() { + return cameraResolution; + } + void SetCameraResolution(float newValue) { + if (newValue < 0.0) { + throw "Camera resolution cannot be negative!"; + } + cameraResolution = newValue; + } +}; |
