Skip to content

Instantly share code, notes, and snippets.

@Grimitch
Created June 19, 2025 16:38
Show Gist options
  • Save Grimitch/17e21a206925758c78623cf25d41114c to your computer and use it in GitHub Desktop.
Save Grimitch/17e21a206925758c78623cf25d41114c to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
using namespace std;
// Электрочайник
class Electrochainik {
private:
string brand;
float volume;
public:
Electrochainik(string b, float v) {
SetBrand(b);
SetVolume(v);
}
void SetBrand(string b) {
if (b.empty()) cout << "Brand can't be empty!\n";
else brand = b;
}
string GetBrand() { return brand; }
void SetVolume(float v) {
if (v <= 0 || v > 5.0) cout << "Volume must be between 0 and 5 liters.\n";
else volume = v;
}
float GetVolume() { return volume; }
void printInfo() {
cout << "Electrochainik: " << brand << ", V: " << volume << " L\n";
}
};
// Книга
class Kniga {
private:
string title;
string author;
public:
Kniga(string t, string a) {
SetTitle(t);
SetAuthor(a);
}
void SetTitle(string t) {
if (t.empty()) cout << "Title can't be empty!\n";
else title = t;
}
string GetTitle() { return title; }
void SetAuthor(string a) {
if (a.empty()) cout << "Author can't be empty!\n";
else author = a;
}
string GetAuthor() { return author; }
void printInfo() {
cout << "Kniga: \"" << title << "\" Autor: " << author << "\n";
}
};
// Телефон
class Telephon {
private:
string model;
string os;
public:
Telephon(string m, string o) {
SetModel(m);
SetOS(o);
}
void SetModel(string m) {
if (m.empty()) cout << "Model can't be empty!\n";
else model = m;
}
string GetModel() { return model; }
void SetOS(string o) {
if (o != "iOS" && o != "Android") cout << "OS must be 'iOS' or 'Android'!\n";
else os = o;
}
string GetOS() { return os; }
void printInfo() {
cout << "Telephon: " << model << ", OS: " << os << "\n";
}
};
// Гелевая ручка
class Gelevayaruchka {
private:
string color;
float tipSize;
public:
Gelevayaruchka(string c, float t) {
SetColor(c);
SetTipSize(t);
}
void SetColor(string c) {
if (c.empty()) cout << "Color can't be empty!\n";
else color = c;
}
string GetColor() { return color; }
void SetTipSize(float t) {
if (t <= 0 || t > 2.0) cout << "Tip size must be between 0 and 2 mm.\n";
else tipSize = t;
}
float GetTipSize() { return tipSize; }
void printInfo() {
cout << "Gelevayaruchka: colour " << color << ", width: " << tipSize << " mm\n";
}
};
// Купюра
class Cupura {
private:
int value;
string currency;
public:
Cupura(int v, string c) {
SetValue(v);
SetCurrency(c);
}
void SetValue(int v) {
if (v <= 0) cout << "Value must be greater than 0!\n";
else value = v;
}
int GetValue() { return value; }
void SetCurrency(string c) {
if (c.empty()) cout << "Currency can't be empty!\n";
else currency = c;
}
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