一元多项式相加 C++

来源:百度知道 编辑:UC知道 时间:2024/05/08 17:51:40
用C++实现 给我源代码 在线等!!!
只要加法 其他运算法则不要!!!

#include <iostream>
using namespace std;
int main()
{
int a,b,c;
cout << "请输入3个数字:"<< endl;
cin >> a >> b >> c;
cout << a << "+" << b << "+" << c << "=" << a + b + c << endl;
return 0;
}

#include <vector>
#include <iostream>
#include <limits>
using namespace std;
class Polynomial
{
public:
friend ostream& operator<< (ostream&, const Polynomial& p);
public:
Polynomial() {}
Polynomial(const double* c, size_t s) { Coffs.assign(c, c+s); }

Polynomial operator+ (Polynomial& other)
{
Polynomial p1, p2;
if (Coffs.size() < other.Coffs.size())
{
p1 = *this;
p2 = other;
}
else
{
p1 = other;
p2 = *this;
}

Polynomial result =