0 / 0 / 0
Регистрация: 30.05.2013
Сообщений: 22
|
|
1
|
Выдает ошибку invalid conversion from "int*" to "int"
02.06.2013, 18:01. Показов 6634. Ответов 2
Добрый вечер!
Что за ошибка?invalid conversion from "int*" to "int"
C++ | 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
| #include <cstdlib>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
inline void operator>>(const std::string &s, int &i)
{
std::istringstream ss(s);
ss >> i;
}
class Polinomials
{
public:
//------------------------------------------------------------------------------------->
Polinomials()
{
for (int i=0;i<=19;i++)
{
coeff[i]=0;
}
};
//------------------------------------------------------------------------------------->
Polinomials(string coeff_str)
{
string temp_str="";
int j=0;
int len=coeff_str.length();
for (int i=0;i<=len-1;i++)
{
if (coeff_str[i]!=',') {temp_str+=coeff_str[i];}
else
{
temp_str>>coeff[j];
j++;
temp_str="";
}
}
temp_str>>coeff[j];
j++;
for (int i=j;i<=19;i++)
{
coeff[i]=0;
}
};
//------------------------------------------------------------------------------------->
~Polinomials() {};
//------------------------------------------------------------------------------------->
int get_coeff(int n) {return coeff[n];}
int set_coeff(int n, int x) {coeff[n]=x;}
//------------------------------------------------------------------------------------->
int multy_coeff(int i, Polinomials a, Polinomials b)
{
int temp_coeff=0;
for (int j=0;j<=i;j++)
{
temp_coeff+=a.get_coeff(j)*b.get_coeff(i-j);
}
return temp_coeff;
}
//------------------------------------------------------------------------------------->
Polinomials operator * (Polinomials & rhs)
{
Polinomials temp_pol;
for (int k=0;k<=19;k++)
{
temp_pol.set_coeff(k,multy_coeff(k, *(this), rhs));
}
return temp_pol;
}
//------------------------------------------------------------------------------------->
Polinomials operator + (Polinomials & rhs)
{
Polinomials temp_pol;
for (int k=0;k<=19;k++)
{
temp_pol.set_coeff(k, coeff[k]+rhs.get_coeff(k));
}
return temp_pol;
}
//------------------------------------------------------------------------------------->
Polinomials operator - (Polinomials & rhs)
{
Polinomials temp_pol;
for (int k=0;k<=19;k++)
{
temp_pol.set_coeff(k, coeff[k]-rhs.get_coeff(k));
}
return temp_pol;
}
//------------------------------------------------------------------------------------->
void operator += (Polinomials & rhs)
{
for (int k=0;k<=19;k++)
{
coeff[k]+=rhs.get_coeff(k);
}
}
//------------------------------------------------------------------------------------->
void operator -= (Polinomials & rhs)
{
for (int k=0;k<=19;k++)
{
coeff[k]-=rhs.get_coeff(k);
}
}
//------------------------------------------------------------------------------------->
void operator *= (Polinomials & rhs)
{
Polinomials temp_pol=*(this)*rhs;
*(this)=temp_pol;
}
//------------------------------------------------------------------------------------->
void show()
{
int first=1;
if (coeff[0]!=0) {cout<<coeff[0]; first=0;}
for (int i=1;i<=19;i++)
{
if (coeff[i]!=0)
{
if (first==1) cout<<coeff[i]<<"x"<<i;
else
{
if (coeff[i]>0) cout<<"+"<<coeff[i]<<"x"<<i;
else cout<<coeff[i]<<"x"<<i;
}
first=0;
}
}
}
//------------------------------------------------------------------------------------->
int get_sum_coeff()
{
int sum_coeff=0;
for (int i=0;i<=19;i++) sum_coeff+=coeff[i];
return sum_coeff;
}
private:
int coeff[20];
};
int main(int argc, char *argv[])
{
Polinomials one("-1,1");
Polinomials two("5,4");
Polinomials three=one*two;
three.show();
cout<<"\n\n";
one*=two;
one.show();
cout<<"\n\n";
cout<<two.get_sum_coeff();
getchar();
return 0;
}
int PolynomDerivative(const int* a, size_t n)
{
int* da = new int[n - 1];
for (size_t i = 0; i < n - 1; ++i)
da[i] = (i + 1) * a[i];
return da;
} |
|
0
|