Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- using namespace std;
- class Trinomial {
- private: int x, x1, x2;
- private: int firstСoefficient, secondСoefficient, thirdСoefficient;
- private: int first = 3, second = 15, third = 34;
- private: char check;
- public: Trinomial(int first, int second, int third) {
- firstСoefficient = first;
- secondСoefficient = second;
- thirdСoefficient = third;
- }
- public: void display() {
- cout << "Your expression: " << firstСoefficient << "'x^2 + ";
- cout << secondСoefficient << "x + " << thirdСoefficient;
- cout << "\nSecond expression: " << first << "'x^2 + ";
- cout << second << "x + " << third;
- }
- public: void sum() {
- cout << "Result of sum: ";
- check = checkSign(second, secondСoefficient);
- cout << first + firstСoefficient << "x^2 " << check << ' ';
- check = checkSign(third, thirdСoefficient);
- cout << second + secondСoefficient << "x " << check << ' ';
- cout << third + thirdСoefficient << '\n';
- }
- public: void difference() {
- cout << "Result of difference: ";
- char check = checkSignInDifference(second, secondСoefficient);
- cout << first - firstСoefficient << "x^2 " << check << ' ';
- check = checkSignInDifference(third, thirdСoefficient);
- cout << second - secondСoefficient << "x " << check << ' ';
- cout << third - thirdСoefficient << '\n';
- }
- private: char checkSign(int first, int second) {
- int result = first + second;
- if (result >= 0) {
- return '+';
- }
- else {
- return '-';
- }
- }
- private: char checkSignInDifference(int first, int second) {
- int result = first - second;
- if (result >= 0) {
- return '+';
- }
- else {
- return '-';
- }
- }
- public: void complainig() {
- double firstD = calculation(firstСoefficient, secondСoefficient, thirdСoefficient);
- double secondD = calculation(first, second, third);
- cout << "Result of complaining: ";
- if (firstD > secondD) {
- cout << "First expression is bigger than second\n";
- }
- else if (firstD < secondD) {
- cout << "First expression is bigger than second\n";
- }
- else {
- cout << "They are equal\n";
- }
- }
- private: int calculation(double Сoefficient, double sСoefficient, double tСoefficient) {
- if ((pow(sСoefficient, 2) - 4 * Сoefficient * tСoefficient) >= 0)
- {
- x1 = (-1 * sСoefficient + sqrt(pow(sСoefficient, 2) - 4 * Сoefficient * tСoefficient)) / (2 * Сoefficient);
- x2 = (-1 * sСoefficient + sqrt(pow(sСoefficient, 2) - 4 * Сoefficient * tСoefficient)) / (2 * Сoefficient);
- }
- else
- {
- return -1;
- }
- return x1 + x2;
- }
- public: void sumWithDouble() {
- double firstD = 3.0, secondD = 4.0, thirdD = 3.0;
- cout << "Result of double number sum: ";
- check = checkSign(secondD, secondСoefficient);
- cout << firstD + firstСoefficient << "x^2 " << check << ' ';
- check = checkSign(thirdD, thirdСoefficient);
- cout << secondD + secondСoefficient << "x " << check << ' ';
- cout << thirdD + thirdСoefficient << '\n';
- }
- public: void multiplyWithDouble() {
- double firstEx[3] = { firstСoefficient, secondСoefficient, thirdСoefficient };
- int secondEx[3] = { first, second, third };
- int resultF = 0, resultS = 0, resultT = 0;
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- if (i == 1) {
- resultS += (firstEx[i] * secondEx[j]);
- }
- else if (i == 2) {
- resultT += (firstEx[i] * secondEx[j]);
- }
- else {
- resultF += (firstEx[i] * secondEx[j]);
- }
- }
- }
- cout << "Result of multiply: ";
- cout << resultF << " + " << resultS << " + " << resultT << '\n';
- }
- public: void calculation(int x) {
- this->x = x;
- cout << "Result if x == " << x << ": ";
- cout << firstСoefficient * pow(x, 2) + secondСoefficient * x + thirdСoefficient<< '\n';
- }
- };
- int main() {
- Trinomial t(1, 3, 4);
- t.display();
- t.sum();
- t.difference();
- t.complainig();
- t.sumWithDouble();
- t.multiplyWithDouble();
- t.calculation(2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement