Skip to content

Instantly share code, notes, and snippets.

@Grimitch
Created June 19, 2025 17:15
Show Gist options
  • Select an option

  • Save Grimitch/bf0ceaf41628b4b8f927f28bc5128191 to your computer and use it in GitHub Desktop.

Select an option

Save Grimitch/bf0ceaf41628b4b8f927f28bc5128191 to your computer and use it in GitHub Desktop.
Main.cpp
#include "electrochainik.h"
#include "kniga.h"
#include "telephon.h"
#include "gelevayaruchka.h"
#include "cupura.h"
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();
}
-----------
electrochainik.h
#pragma once
#include <string>
using namespace std;
class Electrochainik {
private:
string brand;
float volume;
public:
Electrochainik(string brand, float volume);
void SetBrand(string brand);
string GetBrand();
void SetVolume(float volume);
float GetVolume();
void printInfo();
};
-----------
electrochainik.cpp
#include "electrochainik.h"
#include <iostream>
Electrochainik::Electrochainik(string brand, float volume) {
SetBrand(brand);
SetVolume(volume);
}
void Electrochainik::SetBrand(string b) {
if (b.empty()) cout << "Brand can't be empty!\n";
else brand = b;
}
string Electrochainik::GetBrand() {
return brand;
}
void Electrochainik::SetVolume(float v) {
if (v <= 0 || v > 5.0) cout << "Volume must be between 0 and 5 liters.\n";
else volume = v;
}
float Electrochainik::GetVolume() {
return volume;
}
void Electrochainik::printInfo() {
cout << "Electrochainik: " << brand << ", V: " << volume << " L\n";
}
-----------
kniga.h
#pragma once
#include <string>
using namespace std;
class kniga {
private:
string brand;
float volume;
public:
kniga(string brand, float volume);
void SetBrand(string brand);
string GetBrand();
void SetVolume(float volume);
float GetVolume();
void printInfo();
};
-----------
kniga.cpp
#include "kniga.h"
#include <iostream>
kniga::kniga(string brand, float volume) {
SetBrand(brand);
SetVolume(volume);
}
void kniga::SetBrand(string b) {
if (b.empty()) cout << "Brand can't be empty!\n";
else brand = b;
}
string kniga::GetBrand() {
return brand;
}
void kniga::SetVolume(float v) {
if (v <= 0 || v > 5.0) cout << "Volume must be between 0 and 5 liters.\n";
else volume = v;
}
float kniga::GetVolume() {
return volume;
}
void kniga::printInfo() {
cout << "kniga: " << brand << ", V: " << volume << " L\n";
}
-----------
telephon.h
#pragma once
#include <string>
using namespace std;
class telephon {
private:
string brand;
float volume;
public:
telephon(string brand, float volume);
void SetBrand(string brand);
string GetBrand();
void SetVolume(float volume);
float GetVolume();
void printInfo();
};
-----------
telephon.cpp
#include "telephon.h"
#include <iostream>
telephon::telephon(string brand, float volume) {
SetBrand(brand);
SetVolume(volume);
}
void telephon::SetBrand(string b) {
if (b.empty()) cout << "Brand can't be empty!\n";
else brand = b;
}
string telephon::GetBrand() {
return brand;
}
void telephon::SetVolume(float v) {
if (v <= 0 || v > 5.0) cout << "Volume must be between 0 and 5 liters.\n";
else volume = v;
}
float telephon::GetVolume() {
return volume;
}
void telephon::printInfo() {
cout << "telephon: " << brand << ", V: " << volume << " L\n";
}
-----------
gelevayaruchka.h
#pragma once
#include <string>
using namespace std;
class gelevayaruchka {
private:
string brand;
float volume;
public:
gelevayaruchka(string brand, float volume);
void SetBrand(string brand);
string GetBrand();
void SetVolume(float volume);
float GetVolume();
void printInfo();
};
-----------
gelevayaruchka.cpp
#include "gelevayaruchka.h"
#include <iostream>
gelevayaruchka::gelevayaruchka(string brand, float volume) {
SetBrand(brand);
SetVolume(volume);
}
void gelevayaruchka::SetBrand(string b) {
if (b.empty()) cout << "Brand can't be empty!\n";
else brand = b;
}
string gelevayaruchka::GetBrand() {
return brand;
}
void gelevayaruchka::SetVolume(float v) {
if (v <= 0 || v > 5.0) cout << "Volume must be between 0 and 5 liters.\n";
else volume = v;
}
float gelevayaruchka::GetVolume() {
return volume;
}
void gelevayaruchka::printInfo() {
cout << "gelevayaruchka: " << brand << ", V: " << volume << " L\n";
}
-----------
cupura.h
#pragma once
#include <string>
using namespace std;
class cupura {
private:
string brand;
float volume;
public:
cupura(string brand, float volume);
void SetBrand(string brand);
string GetBrand();
void SetVolume(float volume);
float GetVolume();
void printInfo();
};
-----------
cupura.cpp
#include "cupura.h"
#include <iostream>
cupura::cupura(string brand, float volume) {
SetBrand(brand);
SetVolume(volume);
}
void cupura::SetBrand(string b) {
if (b.empty()) cout << "Brand can't be empty!\n";
else brand = b;
}
string cupura::GetBrand() {
return brand;
}
void cupura::SetVolume(float v) {
if (v <= 0 || v > 5.0) cout << "Volume must be between 0 and 5 liters.\n";
else volume = v;
}
float cupura::GetVolume() {
return volume;
}
void cupura::printInfo() {
cout << "cupura: " << brand << ", V: " << volume << " L\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment