From cdd5b6c28b12a4763c9b1eef9ba45ca85a6ddaa2 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 20 Mar 2024 13:20:09 +0200 Subject: [w4] Solved exercises 1-5 --- week04/Exercise1.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 week04/Exercise1.cpp (limited to 'week04/Exercise1.cpp') 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 + +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; + } +}; -- cgit v1.2.3