```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 ``` ```#include #include using namespace std; class Polynomial { public: vector elements; Polynomial(); Polynomial(vector); Polynomial(const Polynomial &); ~Polynomial(); void input(); void output(); void set(vector); void multiplyPolynomial(Polynomial &); Polynomial multiplyNumber(int); Polynomial getPrototypal(); Polynomial operator*(const Polynomial &); Polynomial operator*(int); Polynomial operator=(const Polynomial &); friend ostream &operator<<(ostream &, Polynomial &); friend istream &operator>>(istream &, Polynomial &); }; Polynomial::Polynomial() { this->elements.push_back(0); } Polynomial::Polynomial(const Polynomial &polynomial) { this->elements = polynomial.elements; } Polynomial::Polynomial(vector elements) { this->elements = elements; } Polynomial::~Polynomial() { this->elements.clear(); } void Polynomial::input() { this->elements.clear(); int n, num; cout << "Enter size: "; cin >> n; for (int i = 0; i < n; i ++) { cout << (i + 1) << " element: "; cin >> num; this->elements.push_back(num); } cout << "Input finish" << endl; } void Polynomial::output() { for (int i = 0; i < this->elements.size(); i ++) { if (this->elements[i] != 0) { if (i > 0) { cout << "+"; } if (this->elements[i] != 1) { cout << this->elements[i]; } if (this->elements[i] != 1 && this->elements.size() - i != 1) { cout << "*"; } if (this->elements.size() - i != 1) { cout << "x"; } if (this->elements.size() - i > 2) { cout << "^" << (this->elements.size() - i - 1); } } } cout << endl; } void Polynomial::set(vector elements) { this->elements = elements; } void Polynomial::multiplyPolynomial(Polynomial &polynomial) { int max; Polynomial pnm, p1, p2; if (this->elements.size() > polynomial.elements.size()) { max = this->elements.size(); p1 = *this; p2 = polynomial; } else { max = polynomial.elements.size(); p1 = polynomial; p2 = *this; } for (int i = p1.elements.size(); i > 0; i --) { cout << i << endl; for (int j = 0; j < p1.elements.size(); j ++) { } //if (i <= polynomial.elements.size()) { // //cout << "p2: " << polynomial.elements[i-1] << endl; //} //if (i <= this->elements.size()) { // //cout << "p: " << this->elements[i-1] << endl; //} cout << endl; } } Polynomial Polynomial::multiplyNumber(int number) { Polynomial newp; //newp = new Polynomial(); for (int i = 0; i < this->elements.size(); i ++) { newp.elements[i] = this->elements[i] * number; } return newp; } Polynomial Polynomial::getPrototypal() { Polynomial newp; return newp; } Polynomial Polynomial::operator*(const Polynomial& polynomial) { //return this->multiplyPolynomial(polynomial); return polynomial; } /*Polynomial Polynomial::operator*(int number) { this->multiplyNumber(number); return *this; }*/ Polynomial Polynomial::operator=(const Polynomial &polynomial) { if (this == &polynomial) { return *this; } this->elements = polynomial.elements; return *this; } ostream &operator<<(ostream &s, Polynomial &polynomial) { polynomial.output(); return s; } istream &operator>>(istream &s, Polynomial &polynomial) { polynomial.input(); return s; } int main() { Polynomial polynomial, polynomial2, p3; cin >> polynomial; cout << polynomial; //cout << "Enter number: "; //int number; //cin >> number; //polynomial.multiplyNumber(number); //cout << polynomial; cin >> polynomial2; p3 = polynomial * polynomial2; return 1; } ```
 ```1 2 3 4 5 6 7 ``` ```cc1plus: warnings being treated as errors t.cpp: In member function 'void Polynomial::output()': Line 62: warning: comparison between signed and unsigned integer expressions t.cpp: In member function 'void Polynomial::multiplyPolynomial(Polynomial&)': Line 102: warning: comparison between signed and unsigned integer expressions t.cpp: In member function 'Polynomial Polynomial::multiplyNumber(int)': Line 118: warning: comparison between signed and unsigned integer expressions ```