Здравствуйте! Есть методичка и код, на остове методичке надо сделать отчет по программе!
#include
#include
using namespace std;
class Polynom {
private:
double a;
double b;
double c;
public:
double getA() const {
return a;
}
double getB() const {
return b;
}
double getC() const {
return c;
}
Polynom(double a, double b, double c) : a(a), b(b), c(c) {}
friend std::ostream &operator<<(std::ostream &os, const Polynom &polynom) {
os << "a: " << polynom.a << " b: " << polynom.b << " c: " << polynom.c;
return os;
}
double f(double x) {
return a * x * x + b * x + c;
}
};
class PolynomOps : Polynom {
public:
PolynomOps(double a, double b, double c) : Polynom(a, b, c) {}
Polynom *add(Polynom p) {
return new Polynom(getA() + p.getA(), getB() + p.getB(), getC() + p.getC());
}
Polynom *sub(Polynom p) {
return new Polynom(getA() - p.getA(), getB() - p.getB(), getC() - p.getC());
}
Polynom *mul(Polynom p) {
return new Polynom(getA() + getB() * p.getB(), getB() + getA() * p.getB() + p.getA() * getB(),
getC() * p.getC());
}
};
#include
bool is_number( std::string token )
{
return std::regex_match( token, std::regex( ( "((-)?[[:digit:]]+)(\\.(([[:digit:]]+)?))?" ) ) );
}
int main() {
string a, b, c;
while (true) { // ввод параметров для класса-основателя
cout << "Введите a: " << endl;
cin >> a;
cout << "Введите b: " << endl;
cin >> b;
cout << "Введите c: " << endl;
cin >> c;
if (is_number(a) && is_number(b) && is_number(c))
break;
cout << "Вы ввели не число! Попробуйте еще 1 раз.." << endl;
}
Polynom p1(stod(a), stod(b), stod(c));
while (true) { // ввод параметров для класса-наследника
cout << "Введите a: " << endl;
cin >> a;
cout << "Введите b: " << endl;
cin >> b;
cout << "Введите c: " << endl;
cin >> c;
if (is_number(a) && is_number(b) && is_number(c))
break;
cout << "Вы ввели не число! Попробуйте еще 1 раз.." << endl;
}
PolynomOps po1(stod(a), stod(b), stod(c));
// вывод в консоль
cout << "Многочлен: " << p1 << endl;
// расчет значения для заданного аргумента
cout << "f(1) = " << p1.f(10) << endl;</p><p><br></p><p> // сложение-вычитание-умножение многочленов</p><p> cout << "Add: " << *po1.add(p1) << endl;
cout << "Sub: " << *po1.sub(p1) << endl;
cout << "Mul: " << *po1.mul(p1) << endl;
return 0;
}
| Гарантия на работу | 1 год |
| Средний балл | 4.53 |
| Стоимость | Назначаете сами |
| Эксперт | Выбираете сами |
| Уникальность работы | от 70% |