Created
June 23, 2025 19:01
-
-
Save Grimitch/f14849313658bf58b8d49dbc6cc36cfe 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
#include <iostream> | |
#include <string> | |
using namespace std; | |
// Электрочайник | |
class Electrochainik { | |
private: | |
string brand; | |
float volume; | |
int* temps; | |
public: | |
Electrochainik() : Electrochainik("NoName", 1.0) {} | |
Electrochainik(string brand, float volume) { | |
SetBrand(brand); | |
SetVolume(volume); | |
temps = nullptr; | |
} | |
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 SetTemps(int* temps) { | |
this->temps = temps; | |
} | |
int* GetTemps() { return temps; } | |
void printInfo() { | |
cout << "Electrochainik: " << brand << ", V: " << volume << " L\n"; | |
} | |
}; | |
// Книга | |
class Kniga { | |
private: | |
string title; | |
string author; | |
int* pageNumbers; | |
public: | |
Kniga() : Kniga("NoTitle", "NoAuthor") {} | |
Kniga(string title, string author) { | |
SetTitle(title); | |
SetAuthor(author); | |
pageNumbers = nullptr; | |
} | |
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 SetPageNumbers(int* pageNumbers) { | |
this->pageNumbers = pageNumbers; | |
} | |
int* GetPageNumbers() { return pageNumbers; } | |
void printInfo() { | |
cout << "Kniga: \"" << title << "\" Autor: " << author << "\n"; | |
} | |
}; | |
// Телефон | |
class Telephon { | |
private: | |
string model; | |
string os; | |
string* contacts; | |
public: | |
Telephon() : Telephon("UnknownModel", "Android") {} | |
Telephon(string model, string os) { | |
SetModel(model); | |
SetOS(os); | |
contacts = nullptr; | |
} | |
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 SetContacts(string* contacts) { | |
this->contacts = contacts; | |
} | |
string* GetContacts() { return contacts; } | |
void printInfo() { | |
cout << "Telephon: " << model << ", OS: " << os << "\n"; | |
} | |
}; | |
// Гелевая ручка | |
class Gelevayaruchka { | |
private: | |
string color; | |
float tipSize; | |
string* owners; | |
public: | |
Gelevayaruchka() : Gelevayaruchka("black", 0.7) {} | |
Gelevayaruchka(string color, float tipSize) { | |
SetColor(color); | |
SetTipSize(tipSize); | |
owners = nullptr; | |
} | |
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 SetOwners(string* owners) { | |
this->owners = owners; | |
} | |
string* GetOwners() { return owners; } | |
void printInfo() { | |
cout << "Gelevayaruchka: colour " << color << ", width: " << tipSize << " mm\n"; | |
} | |
}; | |
// Купюра | |
class Cupura { | |
private: | |
int value; | |
string currency; | |
string* serials; | |
public: | |
Cupura() : Cupura(1, "USD") {} | |
Cupura(int value, string currency) { | |
SetValue(value); | |
SetCurrency(currency); | |
serials = nullptr; | |
} | |
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 SetSerials(string* serials) { | |
this->serials = serials; | |
} | |
string* GetSerials() { return serials; } | |
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