1. Создать класс с заданными полями
2. Создать конструктор без параметров (для начальной инициализации)
3. Создать массив из 5 объектов заданного класса
4. Написать функцию для изменения значений полей (с помощью ссылок)
5. Написать функцию для форматированного вывода всех классов на экран
(упорядоченных по первому полю)
Кондиционер (марка, производительность, мощность, габариты)
Другие языки программирования и технологии
Помогите составить программу на С++
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <algorithm>
#include <iterator>
#include <iomanip>
using namespace std;
class Conditioner {
public:
using dimensions_t = tuple<double, double, double>;
Conditioner(string br, double pr, short pw, dimensions_t dm)
: brand_(br), dimensions_(dm), performance_(pr), power_(pw) {}
Conditioner(const Conditioner&) = default;
Conditioner(Conditioner&&) = default;
Conditioner() : brand_("-"), dimensions_({0, 0, 0}), performance_(0), power_(0) {}
void brand(const string& value) { brand_ = value; }
string brand()const { return brand_; }
void dimensions(const dimensions_t& value) { dimensions_ = value; }
void dimensions(double h, double w, double d) { dimensions_ = { h, w, d }; }
dimensions_t dimensions()const { return dimensions_; }
void performance(double value) { performance_ = value; }
double performance()const { return performance_; }
void power(short value) { power_ = value; }
short power()const { return power_; }
private:
string brand_;
dimensions_t dimensions_;
double performance_;
short power_;
friend bool operator<(const Conditioner& a, const Conditioner& b) { return a.brand_ < b.brand_; }
friend ostream& operator<<(ostream& out, const Conditioner& o) {
string sl{ " | " }, x{ " x " };
auto [height, width, depth] = o.dimensions_;
out << o.brand_ + sl
<< fixed << setprecision(1) << o.performance_ << " куб. м/мин" + sl
<< o.power_ << " Вт" + sl
<< setprecision(1) << height << x << width << x << depth << " см";
out.unsetf(ios::fixed);
return out;
}
};
class Box {
public:
void add(const Conditioner& value) { box_.insert(value); }
void add(Conditioner&& value) { box_.emplace(value); }
void add(tuple<string, double, short, Conditioner::dimensions_t>& suite) {
auto [a, b, c, d] = suite;
box_.emplace(Conditioner{ a, b, c, d });
}
void show()const { copy(box_.begin(), box_.end(), ostream_iterator<Conditioner>(cout, "\n")); }
private:
set<Conditioner> box_;
};
int main() {
system("chcp 1251 > nul");
Conditioner samsung;
samsung.brand("Samsung AR09RSFHMWQNER"s);
samsung.performance(9.6);
samsung.power(2600);
samsung.dimensions({ 82., 28.5, 22.7 });
Conditioner mitsubishi{ "Mitsubishi Heavy Industries SRK20ZSPR-S"s, 10.1, 2000, { 76.9, 26.2, 21. } };
auto electrolux = make_tuple<string, double, short, Conditioner::dimensions_t>("Electrolux EACS"s, 8., 2490, { 79., 27.5, 20. });
Box box;
box.add(mitsubishi);
box.add(electrolux);
box.add(samsung);
box.add(Conditioner{ "Toshiba RAS-10N3KV-E"s, 9.6, 2500, { 74., 25., 19.5 } });
box.add({ "Mitsubishi Electric MSZ-LN25VG"s, 11.9, 2500, { 89., 55., 28.5 } });
box.show();
cin.get();
}
P.S. С вас 5000 :)
#include <string>
#include <tuple>
#include <set>
#include <algorithm>
#include <iterator>
#include <iomanip>
using namespace std;
class Conditioner {
public:
using dimensions_t = tuple<double, double, double>;
Conditioner(string br, double pr, short pw, dimensions_t dm)
: brand_(br), dimensions_(dm), performance_(pr), power_(pw) {}
Conditioner(const Conditioner&) = default;
Conditioner(Conditioner&&) = default;
Conditioner() : brand_("-"), dimensions_({0, 0, 0}), performance_(0), power_(0) {}
void brand(const string& value) { brand_ = value; }
string brand()const { return brand_; }
void dimensions(const dimensions_t& value) { dimensions_ = value; }
void dimensions(double h, double w, double d) { dimensions_ = { h, w, d }; }
dimensions_t dimensions()const { return dimensions_; }
void performance(double value) { performance_ = value; }
double performance()const { return performance_; }
void power(short value) { power_ = value; }
short power()const { return power_; }
private:
string brand_;
dimensions_t dimensions_;
double performance_;
short power_;
friend bool operator<(const Conditioner& a, const Conditioner& b) { return a.brand_ < b.brand_; }
friend ostream& operator<<(ostream& out, const Conditioner& o) {
string sl{ " | " }, x{ " x " };
auto [height, width, depth] = o.dimensions_;
out << o.brand_ + sl
<< fixed << setprecision(1) << o.performance_ << " куб. м/мин" + sl
<< o.power_ << " Вт" + sl
<< setprecision(1) << height << x << width << x << depth << " см";
out.unsetf(ios::fixed);
return out;
}
};
class Box {
public:
void add(const Conditioner& value) { box_.insert(value); }
void add(Conditioner&& value) { box_.emplace(value); }
void add(tuple<string, double, short, Conditioner::dimensions_t>& suite) {
auto [a, b, c, d] = suite;
box_.emplace(Conditioner{ a, b, c, d });
}
void show()const { copy(box_.begin(), box_.end(), ostream_iterator<Conditioner>(cout, "\n")); }
private:
set<Conditioner> box_;
};
int main() {
system("chcp 1251 > nul");
Conditioner samsung;
samsung.brand("Samsung AR09RSFHMWQNER"s);
samsung.performance(9.6);
samsung.power(2600);
samsung.dimensions({ 82., 28.5, 22.7 });
Conditioner mitsubishi{ "Mitsubishi Heavy Industries SRK20ZSPR-S"s, 10.1, 2000, { 76.9, 26.2, 21. } };
auto electrolux = make_tuple<string, double, short, Conditioner::dimensions_t>("Electrolux EACS"s, 8., 2490, { 79., 27.5, 20. });
Box box;
box.add(mitsubishi);
box.add(electrolux);
box.add(samsung);
box.add(Conditioner{ "Toshiba RAS-10N3KV-E"s, 9.6, 2500, { 74., 25., 19.5 } });
box.add({ "Mitsubishi Electric MSZ-LN25VG"s, 11.9, 2500, { 89., 55., 28.5 } });
box.show();
cin.get();
}
P.S. С вас 5000 :)
Похожие вопросы
- Помогите составить программу на паскале!
- Помогите составить программу на pascal
- помогите составить программу на языке Turbo pascal
- Помогите составить программу на языке Pascal
- Помогите составить программу на языке Pascal
- помогите составить программу в паскаль, плиз
- Помогите составить программу на Turbo Pascal?
- Помогите составить программу в Pascal ABC
- Помогите составить программу в Pascal
- Пожалуйста, помогите составить программы для решения следующих задач.