Что-то я не могу понять откуда взялась такая ошибка:
error C2065: 'NOD' : undeclared identifierкласс коэфициентовКод:
#include <iostream>
using namespace std;
class Koef
{
int koef;
public:
Koef(int a=0);
Koef(const Koef&X);
virtual ~Koef();
Koef operator *(const Koef b);
Koef operator +(const Koef b);
Koef operator /(const Koef b);
Koef operator -(const Koef b);
Koef operator =(const Koef b);
bool operator !=(const Koef b);
bool operator >(const Koef b);
friend ostream &operator <<(ostream &stream,const Koef &b){
stream<<b.koef;
return stream;
};
friend istream &operator >>(istream &stream, Koef &b){
stream>>b.koef;
return stream;
};
};
Koef.cppКод:
Koef::Koef(int a)
{
koef=a;
}
Koef::Koef( const Koef&X){
koef=X.koef;
}
Koef::~Koef()
{
}
Koef Koef:: operator*(const Koef b){
return koef*b.koef;
}
Koef Koef::operator +(const Koef b){
return koef+b.koef;
}
Koef Koef::operator /(const Koef b){
return koef/b.koef;
}
Koef Koef::operator -(const Koef b){
return koef-b.koef;
}
Koef Koef::operator =(const Koef b){
koef=b.koef;
return *this;
}
bool Koef::operator !=(const Koef b){
if(koef!=b.koef) return true;
else return false;
}
bool Koef::operator >(const Koef b){
if(koef>b.koef) return true;
else return false;
}
класс полиномовКод:
#include "Koef.h"
#include <iostream>
using namespace std;
class Polynom
{
Koef*poli;
int n;
public:
Polynom();
Polynom(int newsize);
Polynom (const Polynom &X);
virtual ~Polynom();
Polynom operator +(const Polynom &X);
Polynom operator =(const Polynom &X);
Polynom operator *(const Polynom &X);
Polynom operator -(const Polynom &X);
bool operator !=(const Polynom &X);
bool operator >(const Polynom &X);
Polynom NOD(Polynom &X, Polynom &Y);
friend ostream &operator <<(ostream &stream,const Polynom &X){
for(int i=0;i<X.n;i++) stream<<X.poli[i]<<"t^"<<i<<"+";
return stream;
}
friend istream &operator >>(istream &stream, Polynom &X){
cout<<"Input koef of polinom"<<endl;
for(int i=0;i<X.n;i++) stream >> X.poli[i];
return stream;
}
};
Polinomial.cppКод:
Polynom::Polynom(){
cout<<"Input degree of polinom"<<endl;
cin>>n;
poli=new Koef[n];
}
//////////////////////////////////////////////////////////////////////
Polynom::Polynom(int newsize){
n=newsize;
poli=new Koef[n];
for(int i=0;i<n;i++) poli[i]=0;
}
//////////////////////////////////////////////////////////////////////
Polynom::Polynom(const Polynom &X){
n=X.n;
poli=new Koef[n];
for(int i=0;i<n;i++) poli[i]=X.poli[i];
}
//////////////////////////////////////////////////////////////////////
Polynom::~Polynom()
{
delete[]poli;
}
//////////////////////////////////////////////////////////////////////
Polynom Polynom::operator +(const Polynom &X){
if(n<=X.n){
Polynom sum(X.n);
Polynom poli1(X.n);
for(int i=0;i<n;i++) poli1.poli[i]=poli[i];
for(int j=0;j<X.n;j++) sum.poli[j]=X.poli[j]+poli1.poli[j];
return sum;
}
if(n>X.n){
Polynom sum(n);
Polynom poli1(n);
for(int i=0;i<X.n;i++) poli1.poli[i]=X.poli[i];
for(int j=0;j<n;j++) sum.poli[j]=poli[j]+poli1.poli[j];
return sum;
}
}
//////////////////////////////////////////////////////////////////////
Polynom Polynom::operator =(const Polynom &X){
n=X.n;
poli=new Koef[n];
for(int i=0;i<n;i++) poli[i]=X.poli[i];
return *this;
}
//////////////////////////////////////////////////////////////////////
Polynom Polynom::operator *(const Polynom &X){
Polynom product(n+X.n-1);
for(int i=0;i<X.n;i++){
for(int j=0;j<n;j++){
product.poli[i+j]=product.poli[i+j]+poli[j]*X.poli[i];
}
}
return product;
}
//////////////////////////////////////////////////////////////////////
Polynom Polynom ::operator -(const Polynom &X){
if(n<=X.n){
Polynom sum(X.n);
Polynom poli1(X.n);
for(int i=0;i<n;i++) poli1.poli[i]=poli[i];
for(int j=0;j<X.n;j++) sum.poli[j]=X.poli[j]-poli1.poli[j];
return sum;
}
if(n>X.n){
Polynom sum(n);
Polynom poli1(n);
for(int i=0;i<X.n;i++) poli1.poli[i]=X.poli[i];
for(int j=0;j<n;j++) sum.poli[j]=poli[j]-poli1.poli[j];
return sum;
}
return *this;
}
//////////////////////////////////////////////////////////////////////
bool Polynom::operator !=(const Polynom &X){
if(n!=X.n) return true;
else{
for(int i=0;i<n+X.n;i++){
if(poli[i]!=X.poli[i]) return true;
else return false;
}
}
}
//////////////////////////////////////////////////////////////////////
bool Polynom::operator >(const Polynom &X){
if(n>X.n && poli[n]!=0) return true;
else{
for(int i=0;i<n+X.n;i++){
if(poli[i]>X.poli[i]) return true;
else return false;
}
}
}
//////////////////////////////////////////////////////////////////////
Polynom Polynom::NOD(Polynom &X, Polynom &Y){
while(X!=Y){
if(X>Y) X=X-Y;
else Y=Y-X;
}
return X;
}
mainКод:
#include "Polinomial.h"
#include "Koef.h"
#include <iostream>
using namespace std;
void main(){
Polynom a;
cin>>a;
cout<<a<<endl;
Polynom b;
cin>>b;
cout<<b<<endl;
Polynom result1(0);
result1=a+b;
cout<<"Sum of polynoms"<<endl<<result1<<endl;
Polynom result2(0);
result2=a*b;
cout<<"Product of polynoms"<<endl<<result2<<endl;
Polynom result3(0);
result3=a-b;
cout<<"Difference of polynoms"<<endl<<result3<<endl;
Polynom result4(0);
result4=NOD(a,b);
cout<<"The greatest general divider"<<endl<<result4<<endl;
}