Created
June 23, 2025 18:57
-
-
Save Grimitch/3195360db89e70cf6f39e4c2881a6324 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Электрочайник | |
| class Electrochainik { | |
| private: | |
| string brand; | |
| float volume; | |
| public: | |
| Electrochainik(string brand, float volume) { | |
| SetBrand(brand); | |
| SetVolume(volume); | |
| } | |
| void SetBrand(string brand) { | |
| if (brand.empty()) cout << "Brand can't be empty!\n"; | |
| else this->brand = brand; | |
| } | |
| string GetBrand() { return brand; } | |
| void SetVolume(float volume) { | |
| if (volume <= 0 || volume > 5.0) cout << "Volume must be between 0 and 5 liters.\n"; | |
| else this->volume = volume; | |
| } | |
| float GetVolume() { return volume; } | |
| void printInfo() { | |
| cout << "Electrochainik: " << brand << ", V: " << volume << " L\n"; | |
| } | |
| }; | |
| // Книга | |
| class Kniga { | |
| private: | |
| string title; | |
| string author; | |
| public: | |
| Kniga(string title, string author) { | |
| SetTitle(title); | |
| SetAuthor(author); | |
| } | |
| void SetTitle(string title) { | |
| if (title.empty()) cout << "Title can't be empty!\n"; | |
| else this->title = title; | |
| } | |
| string GetTitle() { return title; } | |
| void SetAuthor(string author) { | |
| if (author.empty()) cout << "Author can't be empty!\n"; | |
| else this->author = author; | |
| } | |
| string GetAuthor() { return author; } | |
| void printInfo() { | |
| cout << "Kniga: \"" << title << "\" Autor: " << author << "\n"; | |
| } | |
| }; | |
| // Телефон | |
| class Telephon { | |
| private: | |
| string model; | |
| string os; | |
| public: | |
| Telephon(string model, string os) { | |
| SetModel(model); | |
| SetOS(os); | |
| } | |
| void SetModel(string model) { | |
| if (model.empty()) cout << "Model can't be empty!\n"; | |
| else this->model = model; | |
| } | |
| string GetModel() { return model; } | |
| void SetOS(string os) { | |
| if (os != "iOS" && os != "Android") cout << "OS must be 'iOS' or 'Android'!\n"; | |
| else this->os = os; | |
| } | |
| string GetOS() { return os; } | |
| void printInfo() { | |
| cout << "Telephon: " << model << ", OS: " << os << "\n"; | |
| } | |
| }; | |
| // Гелевая ручка | |
| class Gelevayaruchka { | |
| private: | |
| string color; | |
| float tipSize; | |
| public: | |
| Gelevayaruchka(string color, float tipSize) { | |
| SetColor(color); | |
| SetTipSize(tipSize); | |
| } | |
| void SetColor(string color) { | |
| if (color.empty()) cout << "Color can't be empty!\n"; | |
| else this->color = color; | |
| } | |
| string GetColor() { return color; } | |
| void SetTipSize(float tipSize) { | |
| if (tipSize <= 0 || tipSize > 2.0) cout << "Tip size must be between 0 and 2 mm.\n"; | |
| else this->tipSize = tipSize; | |
| } | |
| float GetTipSize() { return tipSize; } | |
| void printInfo() { | |
| cout << "Gelevayaruchka: colour " << color << ", width: " << tipSize << " mm\n"; | |
| } | |
| }; | |
| // Купюра | |
| class Cupura { | |
| private: | |
| int value; | |
| string currency; | |
| public: | |
| Cupura(int value, string currency) { | |
| SetValue(value); | |
| SetCurrency(currency); | |
| } | |
| void SetValue(int value) { | |
| if (value <= 0) cout << "Value must be greater than 0!\n"; | |
| else this->value = value; | |
| } | |
| int GetValue() { return value; } | |
| void SetCurrency(string currency) { | |
| if (currency.empty()) cout << "Currency can't be empty!\n"; | |
| else this->currency = currency; | |
| } | |
| string GetCurrency() { return currency; } | |
| void printInfo() { | |
| cout << "Cupura: " << value << " " << currency << "\n"; | |
| } | |
| }; | |
| int main() { | |
| Electrochainik kettle("Philips", 1.7); | |
| Kniga book("Мартин Иден", "Джек Лондон"); | |
| Telephon phone("iPhone 14", "iOS"); | |
| Gelevayaruchka pen("синяя", 0.5); | |
| Cupura money(1000, "грн"); | |
| kettle.printInfo(); | |
| book.printInfo(); | |
| phone.printInfo(); | |
| pen.printInfo(); | |
| money.printInfo(); | |
| } | |
| РЕПОЗИТОРИЙ НЕ РАБОТАЕТ ВЫКЛАДЫВАЮ ВОТ ТАК ЧЕРЕЗ ГИСТ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment