how to fix?
Oct 21, 2012 at 12:22pm UTC
i compiled my program and it says --> name lookup of 'v' changed for ISO 'for' scoping [-fpermissive]. what does it mean?
and no matching function for call to 'PolynomialClass::PolynomialClass(int*&, const int&)' i declared it in the public, so i dont know how to fix this.
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 171 172 173 174 175 176 177 178 179 180
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
class PolynomialClass
{
public :
PolynomialClass();
PolynomialClass (double *pD2, int newExp);
PolynomialClass(PolynomialClass&);
void output(void );
~PolynomialClass();
PolynomialClass operator +(PolynomialClass L);
PolynomialClass operator -(PolynomialClass L);
PolynomialClass operator *(PolynomialClass L);
PolynomialClass operator /(PolynomialClass L);
friend ostream& operator << (ostream&strm, const PolynomialClass);
private :
double *pDouble;
int Exp;
};
PolynomialClass::PolynomialClass()
{
Exp = 0;
pDouble = new double [Exp + 1];
pDouble[0] = 0;
}
PolynomialClass::PolynomialClass(PolynomialClass& copy)
{
Exp=copy.Exp;
copy.pDouble = new double [copy.Exp + 1];
for (int i = 0; i < copy.Exp; i++)
this ->pDouble[i] = copy.pDouble[i];
this ->Exp = copy.Exp;
}
PolynomialClass:: PolynomialClass(double *pD2, int newExp)
{
Exp=newExp;
pDouble = new double [newExp+1];
for (int c = newExp; newExp>=0; c--)
}
PolynomialClass PolynomialClass:: operator +(PolynomialClass L)
{
PolynomialClass plus;
plus.pDouble = new double [this ->Exp+1];
for (int m=this ->Exp; m>=0; m--)
{
plus.pDouble[m]=pDouble[m]+ L.pDouble[m];
plus.Exp= this ->Exp;
}
return plus;
}
PolynomialClass PolynomialClass:: operator -(PolynomialClass L)
{
PolynomialClass minus;
minus.pDouble= new double [this ->Exp+1];
for (int m=this ->Exp; m>=0; m--)
{
minus.pDouble[m]=pDouble[m]- L.pDouble[m];
minus.Exp= this ->Exp;
}
return minus;
}
PolynomialClass PolynomialClass:: operator *(PolynomialClass L)
{
PolynomialClass times;
int Exp= (this ->Exp + L.Exp+1);
times.Exp = (Exp + L.Exp);
for ( int m = 0; m <= Exp; m++ )
for ( int j = 0; j <= L.Exp; j++ )
times.pDouble[ m + j ] = pDouble[ m ] *L.pDouble[ j ];
return times;
}
PolynomialClass PolynomialClass:: operator /(const PolynomialClass L)
{
PolynomialClass divide;
int Exp= (Exp- L.Exp+1);
divide.Exp = (Exp - L.Exp);
for ( int m = 0; m <= Exp; m++ )
for ( int j = 0; j <= L.Exp; j++ )
divide.pDouble[ m - j ] = pDouble[ m ] / L.pDouble[ j ];
return divide;
}
void PolynomialClass::output(void )
{
for (int p=Exp; p>0; p--)
cout <<pDouble[p] << "x^" << p << " + " ;
}
PolynomialClass::~PolynomialClass()
{
delete [] pDouble;
}
int main()
{
cout << "This program can perform the four (4) basic operations (plus, minus, multiplication, and division) of polynomials." <<endl<<endl;
int *polyA, ExpA;
cout <<"Input exponent of polyA:" ;
cin >> ExpA;
polyA= new int [ExpA+1];
for (int v = ExpA; v>=0; v--);
{
cout << "input coefficient of x^ " << v <<":" ; //this is the problem; it says name lookup of 'v' changed for ISO 'for' scoping [-fpermissive].
cin >> polyA[v];
}
const int NewExpA=ExpA;
int *polyB, ExpB;
cout <<"Input degree of poly2:" ;
cin >> ExpB;
polyB= new int [ExpB+1];
for (int w = ExpB; w>=0; w--);
{
cout << "input coefficient of x^" << w << ":" ; //this is the problem; name lookup of 'w' changed for ISO 'for' scoping [-fpermissive].
cin >> polyB[w];
}
const int NewExpB=ExpB;
PolynomialClass C (double polyA, int newExpA); //this is the problem
PolynomialClass D (double polyB, int newExpB); //this is the problem
cout<<"polynomial A is " ;
C.output();
cout<<endl<<"polynomial B is " ;
D.output();
cout<<endl;
PolynomialClass plus;
plus=C+D;
cout<<"Sum of the polynomials is " ;
plus.output();
PolynomialClass minus;
minus=C-D;
cout<<"Difference of the polynomials is " ;
minus.output();
PolynomialClass times;
times=C*D;
cout<<"Product of the polynomials is " ;
times.output();
PolynomialClass divide;
divide=C/D;
cout<<"Quotient of the polynomials is " ;
divide.output();
system ("pause" );
return 0;
}
Last edited on Oct 21, 2012 at 12:23pm UTC
Oct 21, 2012 at 12:37pm UTC
The translation of the first error is "v was not declared in this scope".
The second error is self-evident, just read what it says.
Oct 21, 2012 at 12:44pm UTC
thank you! :)
Topic archived. No new replies allowed.