,   CyberForum.ru

++


 
Binjo
4 / 1 / 0
: 14.10.2012
: 22
#1

Public Private - C++

07.06.2014, 17:58. 396. 5
( )

!
, private, public.
private, , , .
?
Similar
41792 / 34177 / 6122
: 12.04.2006
: 57,940
07.06.2014, 17:58     Public Private
:

private, protected, public - C++
class test { public: test(); int getPrivate(); int vpublic; protected: int vprotected; private: int vprivate;

Protected Private Public - C++
, , , ...

class public private - C++
, public private : #include <iostream> #include...

LNK2019: private public - C++
, : // "NAbstractNumber.h" class NAbstractNumber{ NAbstractNumber(){}; virtual std::string toString(int...

Private public - C++
! : class CDateTime{ private: qint16 year_; qint8 month_, day_; qint8 hours_, minutes_,...

Public, Private, Protected ( ) - C++
, .

private, public, protected - C++
private, public, protected ?

public, private - C++
. public, private? ...

: public, protected/private - C++
"90 C++". : 44. public,...

Public Private - C++
... 2 : : class GradeBook { public: ...

. public, protected. private - C++
, Unit2.cpp(16): E2251 Cannot find default constructor to initialize base class 'My' unit2.cpp ...

Private public - C++
, , private public ? ...




:
.
castaway
 ++
4881 / 3017 / 370
: 10.11.2010
: 11,076
: 10
: 1
07.06.2014, 18:03     Public Private #2
. .
Binjo
4 / 1 / 0
: 14.10.2012
: 22
07.06.2014, 18:12  []     Public Private #3
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
#ifndef POLYNOMIAL_H
#define POLYNOMIAL_H
 
 
struct info
{
    int degree;//ñòåïå*ü
    double factor;
};
 
 
struct element
{
    info value;
    element *next;
};
 
 
class Polynomial
{
private:
    element *head;
   
    void InsertToHead(int degree, double factor);  
   
    void InsertToTail(int degree, double factor);
   
    void InsertToPos(int degree, double factor);
   
    void DeleteToPos(int degree);
  
    void MakeNull();
   
    void PrintPolynomial();
   
    double Gorner(double x, element *current);
    
    element* LocateHead();
    Polynomial(); //êî*ñòðóêòîð
    Polynomial(const Polynomial &pol);
    ~Polynomial(); //äåñòðóêòîð
public://îòêðûò*ÿ ÷*ñòü
     
 
   
    
   
    const Polynomial operator + (const Polynomial &p) const;
   
    Polynomial& operator += (const Polynomial &p);
  
    const Polynomial operator * (const double &val) const;
    
    const Polynomial operator * (const Polynomial &p) const;
 
    Polynomial& operator *= (const Polynomial &p);
   
    Polynomial& operator = (const Polynomial &p);
};
 
#endif




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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#include "Polynomial.h"
#include <iostream>
 
using namespace std;
//êî*ñòðóêòîð 
Polynomial::Polynomial()
{
    head = 0;//ñïèñîê ïóñò
}
//êî*ñòðóêòîð êîïèðîâ**èÿ
//ïðè*èì*åò ïîëè*îì
Polynomial::Polynomial(const Polynomial &pol)
{
    Polynomial result;//ñþä* êîïèðóåì ïîëè*îì
    element *temp = pol.head;//óê*ç*òåëü, â êîòîðîì õð**èì ãîëîâó êîïðèðóåìîãî ïîëè*îì*
 
    while(temp)//êîïèðóåì ïîëè*îì
    {
        result.InsertToPos(temp->value.degree, temp->value.factor);
        temp = temp->next;
    }
 
    head = result.head;
}
 
Polynomial::~Polynomial()//äåñòðóêòîð
{
    MakeNull();//î÷èù*åò ñïèñîê
}
 
//î÷èù*åì ñïèñîê
void Polynomial::MakeNull()
{
    if(head)//åñëè ñïèñîê ñóùåñòâóåò(ãîëîâ* ** NULL)
    {
        element *temp = head;//ñîç*äåì óê*ç*òåëü è ïîìåù*åì òóä* ãîëîâó
        while(head)//ïîê* *å î÷èñòèì
        {
            head = head->next;//ãîëîâîé ñò**îâèòñÿ ñëåäóþùèé ýëåìå*ò
            delete temp;//óä*ëÿåì ñò*ðóþ ãîëîâó
            temp = head;//ïîëó÷*åì *îâóþ ãîëîâó
        }
    }
}
 
//äîá*âëå*èå â **÷*ëî ñïèñê*
//ïðè*èì*åò ñòåïå*ü è êîýôôåöèå*ò
void Polynomial::InsertToHead(int degree, double factor)
{
    element *temp = new element;//ñîçä*åì óê*ç*òåëüè ïîìåù*åì òóä* ýëåìå*ò
 
    if(!head)//åñëè ñïèñîê ïóñò
        temp->next = 0;//òîãä* ñëåäóþùèé ýëåìå*ò ç* **øèì-*óëü
    else
        temp->next = head;//è**÷å ñëåæóþùèé ýëåìå*ò ç* **øèì-ãîëîâ*
 
    head = temp;//*îâ*ÿ ãîëîâ*-**ø ýëåìå*ò
    temp->value.degree = degree;//ïåðåä*åì ñòåïå*ü
    temp->value.factor = factor;//ïåðåä*åì êîýôôåöèå*ò
}
 
//äîá*âëå*èå â êî*åö ñïèñê*
//ïðè*èì*åò ñòåïå*ü è êîýôôåöèå*ò
void Polynomial::InsertToTail(int degree, double factor)
{
    element *temp = new element;
 
    if(!head)
        head = temp;
    else
    {
        element *last = head;
        while(last->next)//ïîê* *å äîéäåì äî êî*ö*
            last = last->next;
        last->next = temp;
    }
 
    temp->next = 0;//ñëåäóþùèé ç* **øèì-*óëü
    temp->value.degree = degree;
    temp->value.factor = factor;
}
 
//äîá*âëå*èå â óæå ñóùåñòâóþùèé ýëåìå*ò ñïèñê*.ïðè*èì*åò ñòåïå*ü è êîýôôåöèå*ò
void Polynomial::InsertToPos(int degree, double factor)
{
    if(!head)//åñëè ñïèñîê ïóñò, òî äîá*âëÿåì â **÷*ëî
    {
        InsertToHead(degree, factor);
        return;
    }
    else
    {
        element *temp = head;
        while(temp)//èäåì ïî ñïèñêó è èùåì *óæ*óþ ñòåïå*ü
        {
            if(temp->value.degree == degree)
            {
                temp->value.factor += factor;//äîá*âëÿåì ç**÷å*èå ê óæå ñóùåñòâóþùåìó
                return;
            }
            temp = temp->next;
        }
    }
 
    
    InsertToTail(degree, factor);//åñëè *å **øëè ò*êîé ýëåìå*ò, òî äîá*âëÿåì â êî*åö
}
 
//âû÷èñëÿåì ç**÷å*èå ïîëè*îì* ìåòîäîì Ãîð*åð*
//ïðè*èì*åò ç**÷å*èå èêñ*,êîòîðîå **äî ïîäñò*âèòü â ïîëè*îì, è óê*ç*òåëü **  òåêóùèé ýëåìå*ò â ñïèñêå
double Polynomial::Gorner(double x, element *current)
{
    double y = 0;//ñþä* ìû ç*ïèøåì ç**÷å*èå ïîëè*îì*
 
    if(current)//åñëè *å äîøëè äî êî*ö*
    {
        if(current->value.degree == 0)//åñëè ñòåïå*ü ð*â** *óëþ,
            y += current->value.factor;//â èãðèê äîá*âëÿåì ç**÷å*èå êîýôôåöèå*ò*
 
        if(current->next)//åñëè *å ïîñëåä*èé ýëåìå*ò â ñïèñêå
            y += (current->next->value.factor + Gorner(x, current->next))*x;//ê èãðèêó äîá*âëÿåì êîýôôåöèå*ò ñëåäóþùåãî èãðèê*
            //âûçûâ*åì ôó*êöèþ ñ*îâ* è óì*îæ*åì ðåçóëüò*ò ** èêñ
    }   
    else
        y = 0;
 
    return y;
}
 
//âîçâð*ù*åì óê*ç*òåëü ** ãîëîâó
element* Polynomial::LocateHead()
{
    return head;
}
 
//âûâîä ïîëè*îì* ** ýêð**
void Polynomial::PrintPolynomial()
{
    element *temp = head;//óê*ç*òåëü ** ãëîâó
    cout.setf(ios::scientific);//âûâîä â äåñÿòè÷*îì âèäå
 
    while(temp)//*å äîøëè äî êî*ö*
    {
        if(!temp->value.degree)//åñëè ñòåïå*è *åò
            cout << temp->value.factor;//ïðîñòî âûâåäåì êîýôôåöèå*ò
        else
            cout << temp->value.factor << "*X^" << temp->value.degree;//åñëè åñòü, òî âûâîäèì êîýôôå*X^ñòåïå*ü
 
        temp = temp->next;//ïåðåõîäèì ê ñëåäóþùåìó
        if(temp)
            cout << " + ";//ïèøåì ïëþñ
    }
    cout << endl;
}
//ïåðåãðóçêè
//ïåðåãðóçê* óì*îæå*èÿ
const Polynomial Polynomial::operator * (const double &val) const//óì*îæê*èå ïîëè*îì* ** ÷èñëî
//const *óæå* ÷á *å ìå*ÿëèñü ïîëè*îì è ÷èñëî.êî*òðîëü ïîñòîÿ*ñòâ*
{
    Polynomial result;//ïåðåìå***ÿ õð**èò ðåçóëüò*ò óì*îæå*èÿ ïîëè*îì* ** ÷èñëî
    
    if(val == 0)//åñëè óì*îæ*åì ** *óëü, òî ñð*çó âîçâð*ù*åì ðåçóëüò*ò
        return result;
 
    element *temp = head;//óê*ç*òåëü ** ãëîâó
    while(temp)//ïîê* *å ïîñëåä*èé ýëåìå*ò
    {
        result.InsertToPos(temp->value.degree, (temp->value.factor)*val);//êîïèðóåì âåñü ñïèñîê â ðåçóëüò*ò,ê*æäûé êîýôô óì*îæ*åì ** ÷èñëî
        temp = temp->next;//ïåðåõîäèì ê ñëåäóþùåìó
    }
 
    return result;//âîçâð*ù*åì ðåçóëüò*ò.(áóäåò âûçâ** êî*ñòðóêòîð êîïèðîâ**èÿ)
}
 
 
const Polynomial Polynomial::operator +(const Polynomial &p) const//ñëîæå*èå ïîëè*îì* è ïîëè*îì*
{//const *óæå* ÷á *å ìå*ÿëèñü ïîëè*îì è ïîëè*îì
    Polynomial result;//ñîçä*åì
    result = *this;//ëåâûé *ðãóìå*ò êîïèðóåì â ðåçóëüò*ò
    result += p;//âûçûâ*åì ïåðåãðóæå**ûé îïåð*òîð +=
    return result;
}
 
 
Polynomial& Polynomial::operator +=(const Polynomial &p)//ñëîæå*èå ïîëè*îìîâ
{//const *óæå* ÷á *å ìå*ÿëñÿ ïð*âûé ïîëè*îì
    element *temp = p.head;
    
    while(temp)
    {
        this->InsertToPos(temp->value.degree, temp->value.factor);//äîá*âëÿåì ç**÷å*èå â ïîëè*îìå, ñ êîòîðûñì ñêë*äûâ*åì
        temp = temp->next;//ïåðåõîäèì ê ñëåäóþùåìó
    }
    
    return *this;//âîçâð*ù*åì ðåçóëüò*ò(êî*ñòðóêòîð êîïèðîâ**èÿ *å âûçûâ*åòñÿ,ò.ê. ññûëê*)
}
 
 
 
const Polynomial Polynomial::operator *(const Polynomial &p) const//óì*îæå*èå ïîëè*îì* ** ïîëè*îì
{//const *óæå* ÷á *å ìå*ÿëèñü ïîëè*îì è ïîëè*îì
    Polynomial result;
    result = *this;
    result *= p;
    
    return result;
}
 
 
Polynomial& Polynomial::operator *=(const Polynomial &p)//óì*îæå*èå ïîëè*îì* ** ïîëè*îì
{   //const *óæå* ÷á *å ìå*ÿëñÿ ïð*âûé ïîëè*îì
    //eñëè ëåâûé ì*îãî÷ëå* *å ñóùåñòâóåò, òî âîçâð*ù*åì òîëüêî ïð*âûé
    if(!head)
    {
        *this = p;
        return *this;
    }
    
    //eñëè ïð*âûé ì*îãî÷ëå* *å ñóùåñòâóåò, òî âîçâð*ù*åì òîëüêî ëåâûé
    if(!p.head)
        return *this;
    
    //âðåìå**ûå óê*ç*òåëè, äëÿ äâèæå*èÿ ïî ñïèñê*ì, â êîòîðûõ **õîäÿòñÿ ïåðåì*îæ*åìûå ì*îãî÷ëå**û
    element *temp1 = head;
    element *temp2 = p.head;
    Polynomial result;//ïåðåìå***ÿ äëÿ ðåçóëüò*ò*
    
    while(temp1)//ïîê* åñòü 1 ñïèñîê
    {
        temp2 = p.head;//õð**èì ãîëîâó
        while(temp2)//ïîê* åñòü âòîðîé ñïèñîê
        {
            result.InsertToPos((temp1->value.degree)+(temp2->value.degree), (temp1->value.factor)*(temp2->value.factor));//ñêë*äûâ*åì ñòåïå*è è ïåðåì*îæ*åì êîýôôåöèå*òû ïðè ýòèõ ñòåï*ÿõ
            temp2 = temp2->next;//ñëåäóþùèé
        }
        temp1 = temp1->next;//ñëåäóþùèé
    }
    
    *this = result;
    return *this;//âîçâð*ù*åì ðåçóëüò*ò.êî*ñòðóêòîð êîïèðîâ**èÿ *å âûçûâ*åòñÿ
}
 
 
Polynomial& Polynomial::operator =(const Polynomial &p)//ïðèð*â*èâ*åì ïîëè*îì ê ïîëè*îìó
{//const *óæå* ÷á *å ìå*ÿëñÿ ïð*âûé ïîëè*îì
    if(head)//åñëè *å ïóñòîé
        this->MakeNull();//î÷èù*åì ñïèñîê,êîòîðûé ñëåâ*
    element *temp = p.head;//óê*ç*òåëü ** ãîëîâó ñïèñê* ñïð*â*
    while(temp)//ïîê* *å äîñòèã*åì êî*ö*
    {
        this->InsertToPos(temp->value.degree, temp->value.factor);//ç*ïèñûâåì â î÷èùå**ûé ñïèñîê ç**÷å*èÿ èç ç*ïîë*å**îãî ñïèñê*
        temp = temp->next;//ñëåäóþùèé
    }
    return *this;//âîçâð*ù*åì ðåçóëüò*ò.êî*ñòðóêòîð êîïèðîâ**èÿ *å âûçûâ*åòñÿ
}


, :
" 'double Polynomial::Gorner(double, element*)' is private"

2
castaway,
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
#ifndef POLYNOMIAL_H
#define POLYNOMIAL_H
 
 
struct info
{
    int degree;//ñòåïå*ü
    double factor;
};
 
 
struct element
{
    info value;
    element *next;
};
 
 
class Polynomial
{
private:
    element *head;
   
    void InsertToHead(int degree, double factor);  
   
    void InsertToTail(int degree, double factor);
   
    void InsertToPos(int degree, double factor);
   
    void DeleteToPos(int degree);
  
    void MakeNull();
   
    void PrintPolynomial();
   
    double Gorner(double x, element *current);
    
    element* LocateHead();
    Polynomial(); //êî*ñòðóêòîð
    Polynomial(const Polynomial &pol);
    ~Polynomial(); //äåñòðóêòîð
public://îòêðûò*ÿ ÷*ñòü
     
 
   
    
   
    const Polynomial operator + (const Polynomial &p) const;
   
    Polynomial& operator += (const Polynomial &p);
  
    const Polynomial operator * (const double &val) const;
    
    const Polynomial operator * (const Polynomial &p) const;
 
    Polynomial& operator *= (const Polynomial &p);
   
    Polynomial& operator = (const Polynomial &p);
};
 
#endif




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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#include "Polynomial.h"
#include <iostream>
 
using namespace std;
//êî*ñòðóêòîð 
Polynomial::Polynomial()
{
    head = 0;//ñïèñîê ïóñò
}
//êî*ñòðóêòîð êîïèðîâ**èÿ
//ïðè*èì*åò ïîëè*îì
Polynomial::Polynomial(const Polynomial &pol)
{
    Polynomial result;//ñþä* êîïèðóåì ïîëè*îì
    element *temp = pol.head;//óê*ç*òåëü, â êîòîðîì õð**èì ãîëîâó êîïðèðóåìîãî ïîëè*îì*
 
    while(temp)//êîïèðóåì ïîëè*îì
    {
        result.InsertToPos(temp->value.degree, temp->value.factor);
        temp = temp->next;
    }
 
    head = result.head;
}
 
Polynomial::~Polynomial()//äåñòðóêòîð
{
    MakeNull();//î÷èù*åò ñïèñîê
}
 
//î÷èù*åì ñïèñîê
void Polynomial::MakeNull()
{
    if(head)//åñëè ñïèñîê ñóùåñòâóåò(ãîëîâ* ** NULL)
    {
        element *temp = head;//ñîç*äåì óê*ç*òåëü è ïîìåù*åì òóä* ãîëîâó
        while(head)//ïîê* *å î÷èñòèì
        {
            head = head->next;//ãîëîâîé ñò**îâèòñÿ ñëåäóþùèé ýëåìå*ò
            delete temp;//óä*ëÿåì ñò*ðóþ ãîëîâó
            temp = head;//ïîëó÷*åì *îâóþ ãîëîâó
        }
    }
}
 
//äîá*âëå*èå â **÷*ëî ñïèñê*
//ïðè*èì*åò ñòåïå*ü è êîýôôåöèå*ò
void Polynomial::InsertToHead(int degree, double factor)
{
    element *temp = new element;//ñîçä*åì óê*ç*òåëüè ïîìåù*åì òóä* ýëåìå*ò
 
    if(!head)//åñëè ñïèñîê ïóñò
        temp->next = 0;//òîãä* ñëåäóþùèé ýëåìå*ò ç* **øèì-*óëü
    else
        temp->next = head;//è**÷å ñëåæóþùèé ýëåìå*ò ç* **øèì-ãîëîâ*
 
    head = temp;//*îâ*ÿ ãîëîâ*-**ø ýëåìå*ò
    temp->value.degree = degree;//ïåðåä*åì ñòåïå*ü
    temp->value.factor = factor;//ïåðåä*åì êîýôôåöèå*ò
}
 
//äîá*âëå*èå â êî*åö ñïèñê*
//ïðè*èì*åò ñòåïå*ü è êîýôôåöèå*ò
void Polynomial::InsertToTail(int degree, double factor)
{
    element *temp = new element;
 
    if(!head)
        head = temp;
    else
    {
        element *last = head;
        while(last->next)//ïîê* *å äîéäåì äî êî*ö*
            last = last->next;
        last->next = temp;
    }
 
    temp->next = 0;//ñëåäóþùèé ç* **øèì-*óëü
    temp->value.degree = degree;
    temp->value.factor = factor;
}
 
//äîá*âëå*èå â óæå ñóùåñòâóþùèé ýëåìå*ò ñïèñê*.ïðè*èì*åò ñòåïå*ü è êîýôôåöèå*ò
void Polynomial::InsertToPos(int degree, double factor)
{
    if(!head)//åñëè ñïèñîê ïóñò, òî äîá*âëÿåì â **÷*ëî
    {
        InsertToHead(degree, factor);
        return;
    }
    else
    {
        element *temp = head;
        while(temp)//èäåì ïî ñïèñêó è èùåì *óæ*óþ ñòåïå*ü
        {
            if(temp->value.degree == degree)
            {
                temp->value.factor += factor;//äîá*âëÿåì ç**÷å*èå ê óæå ñóùåñòâóþùåìó
                return;
            }
            temp = temp->next;
        }
    }
 
    
    InsertToTail(degree, factor);//åñëè *å **øëè ò*êîé ýëåìå*ò, òî äîá*âëÿåì â êî*åö
}
 
//âû÷èñëÿåì ç**÷å*èå ïîëè*îì* ìåòîäîì Ãîð*åð*
//ïðè*èì*åò ç**÷å*èå èêñ*,êîòîðîå **äî ïîäñò*âèòü â ïîëè*îì, è óê*ç*òåëü **  òåêóùèé ýëåìå*ò â ñïèñêå
double Polynomial::Gorner(double x, element *current)
{
    double y = 0;//ñþä* ìû ç*ïèøåì ç**÷å*èå ïîëè*îì*
 
    if(current)//åñëè *å äîøëè äî êî*ö*
    {
        if(current->value.degree == 0)//åñëè ñòåïå*ü ð*â** *óëþ,
            y += current->value.factor;//â èãðèê äîá*âëÿåì ç**÷å*èå êîýôôåöèå*ò*
 
        if(current->next)//åñëè *å ïîñëåä*èé ýëåìå*ò â ñïèñêå
            y += (current->next->value.factor + Gorner(x, current->next))*x;//ê èãðèêó äîá*âëÿåì êîýôôåöèå*ò ñëåäóþùåãî èãðèê*
            //âûçûâ*åì ôó*êöèþ ñ*îâ* è óì*îæ*åì ðåçóëüò*ò ** èêñ
    }   
    else
        y = 0;
 
    return y;
}
 
//âîçâð*ù*åì óê*ç*òåëü ** ãîëîâó
element* Polynomial::LocateHead()
{
    return head;
}
 
//âûâîä ïîëè*îì* ** ýêð**
void Polynomial::PrintPolynomial()
{
    element *temp = head;//óê*ç*òåëü ** ãëîâó
    cout.setf(ios::scientific);//âûâîä â äåñÿòè÷*îì âèäå
 
    while(temp)//*å äîøëè äî êî*ö*
    {
        if(!temp->value.degree)//åñëè ñòåïå*è *åò
            cout << temp->value.factor;//ïðîñòî âûâåäåì êîýôôåöèå*ò
        else
            cout << temp->value.factor << "*X^" << temp->value.degree;//åñëè åñòü, òî âûâîäèì êîýôôå*X^ñòåïå*ü
 
        temp = temp->next;//ïåðåõîäèì ê ñëåäóþùåìó
        if(temp)
            cout << " + ";//ïèøåì ïëþñ
    }
    cout << endl;
}
//ïåðåãðóçêè
//ïåðåãðóçê* óì*îæå*èÿ
const Polynomial Polynomial::operator * (const double &val) const//óì*îæê*èå ïîëè*îì* ** ÷èñëî
//const *óæå* ÷á *å ìå*ÿëèñü ïîëè*îì è ÷èñëî.êî*òðîëü ïîñòîÿ*ñòâ*
{
    Polynomial result;//ïåðåìå***ÿ õð**èò ðåçóëüò*ò óì*îæå*èÿ ïîëè*îì* ** ÷èñëî
    
    if(val == 0)//åñëè óì*îæ*åì ** *óëü, òî ñð*çó âîçâð*ù*åì ðåçóëüò*ò
        return result;
 
    element *temp = head;//óê*ç*òåëü ** ãëîâó
    while(temp)//ïîê* *å ïîñëåä*èé ýëåìå*ò
    {
        result.InsertToPos(temp->value.degree, (temp->value.factor)*val);//êîïèðóåì âåñü ñïèñîê â ðåçóëüò*ò,ê*æäûé êîýôô óì*îæ*åì ** ÷èñëî
        temp = temp->next;//ïåðåõîäèì ê ñëåäóþùåìó
    }
 
    return result;//âîçâð*ù*åì ðåçóëüò*ò.(áóäåò âûçâ** êî*ñòðóêòîð êîïèðîâ**èÿ)
}
 
 
const Polynomial Polynomial::operator +(const Polynomial &p) const//ñëîæå*èå ïîëè*îì* è ïîëè*îì*
{//const *óæå* ÷á *å ìå*ÿëèñü ïîëè*îì è ïîëè*îì
    Polynomial result;//ñîçä*åì
    result = *this;//ëåâûé *ðãóìå*ò êîïèðóåì â ðåçóëüò*ò
    result += p;//âûçûâ*åì ïåðåãðóæå**ûé îïåð*òîð +=
    return result;
}
 
 
Polynomial& Polynomial::operator +=(const Polynomial &p)//ñëîæå*èå ïîëè*îìîâ
{//const *óæå* ÷á *å ìå*ÿëñÿ ïð*âûé ïîëè*îì
    element *temp = p.head;
    
    while(temp)
    {
        this->InsertToPos(temp->value.degree, temp->value.factor);//äîá*âëÿåì ç**÷å*èå â ïîëè*îìå, ñ êîòîðûñì ñêë*äûâ*åì
        temp = temp->next;//ïåðåõîäèì ê ñëåäóþùåìó
    }
    
    return *this;//âîçâð*ù*åì ðåçóëüò*ò(êî*ñòðóêòîð êîïèðîâ**èÿ *å âûçûâ*åòñÿ,ò.ê. ññûëê*)
}
 
 
 
const Polynomial Polynomial::operator *(const Polynomial &p) const//óì*îæå*èå ïîëè*îì* ** ïîëè*îì
{//const *óæå* ÷á *å ìå*ÿëèñü ïîëè*îì è ïîëè*îì
    Polynomial result;
    result = *this;
    result *= p;
    
    return result;
}
 
 
Polynomial& Polynomial::operator *=(const Polynomial &p)//óì*îæå*èå ïîëè*îì* ** ïîëè*îì
{   //const *óæå* ÷á *å ìå*ÿëñÿ ïð*âûé ïîëè*îì
    //eñëè ëåâûé ì*îãî÷ëå* *å ñóùåñòâóåò, òî âîçâð*ù*åì òîëüêî ïð*âûé
    if(!head)
    {
        *this = p;
        return *this;
    }
    
    //eñëè ïð*âûé ì*îãî÷ëå* *å ñóùåñòâóåò, òî âîçâð*ù*åì òîëüêî ëåâûé
    if(!p.head)
        return *this;
    
    //âðåìå**ûå óê*ç*òåëè, äëÿ äâèæå*èÿ ïî ñïèñê*ì, â êîòîðûõ **õîäÿòñÿ ïåðåì*îæ*åìûå ì*îãî÷ëå**û
    element *temp1 = head;
    element *temp2 = p.head;
    Polynomial result;//ïåðåìå***ÿ äëÿ ðåçóëüò*ò*
    
    while(temp1)//ïîê* åñòü 1 ñïèñîê
    {
        temp2 = p.head;//õð**èì ãîëîâó
        while(temp2)//ïîê* åñòü âòîðîé ñïèñîê
        {
            result.InsertToPos((temp1->value.degree)+(temp2->value.degree), (temp1->value.factor)*(temp2->value.factor));//ñêë*äûâ*åì ñòåïå*è è ïåðåì*îæ*åì êîýôôåöèå*òû ïðè ýòèõ ñòåï*ÿõ
            temp2 = temp2->next;//ñëåäóþùèé
        }
        temp1 = temp1->next;//ñëåäóþùèé
    }
    
    *this = result;
    return *this;//âîçâð*ù*åì ðåçóëüò*ò.êî*ñòðóêòîð êîïèðîâ**èÿ *å âûçûâ*åòñÿ
}
 
 
Polynomial& Polynomial::operator =(const Polynomial &p)//ïðèð*â*èâ*åì ïîëè*îì ê ïîëè*îìó
{//const *óæå* ÷á *å ìå*ÿëñÿ ïð*âûé ïîëè*îì
    if(head)//åñëè *å ïóñòîé
        this->MakeNull();//î÷èù*åì ñïèñîê,êîòîðûé ñëåâ*
    element *temp = p.head;//óê*ç*òåëü ** ãîëîâó ñïèñê* ñïð*â*
    while(temp)//ïîê* *å äîñòèã*åì êî*ö*
    {
        this->InsertToPos(temp->value.degree, temp->value.factor);//ç*ïèñûâåì â î÷èùå**ûé ñïèñîê ç**÷å*èÿ èç ç*ïîë*å**îãî ñïèñê*
        temp = temp->next;//ñëåäóþùèé
    }
    return *this;//âîçâð*ù*åì ðåçóëüò*ò.êî*ñòðóêòîð êîïèðîâ**èÿ *å âûçûâ*åòñÿ
}


, :
" 'double Polynomial::Gorner(double, element*)' is private"
Jupiter
 ++
6552 / 3972 / 226
: 26.03.2010
: 9,273
: 1
: 2
07.06.2014, 18:31     Public Private #4
Binjo
, private, public.
private, , , .
?
"" ?
castaway
 ++
4881 / 3017 / 370
: 10.11.2010
: 11,076
: 10
: 1
07.06.2014, 18:52     Public Private #5
?
kupnu4
26 / 26 / 9
: 03.05.2013
: 71
07.06.2014, 21:25     Public Private #6
Polynomial::Gorner(double, element*) - ?
Yandex
07.06.2014, 21:25     Public Private

- , ,
-
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
@Mail.ru