-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
154 lines (120 loc) · 2.57 KB
/
Copy pathmain.cpp
File metadata and controls
154 lines (120 loc) · 2.57 KB
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
#include <iostream>
#include <stdlib.h>
#include <math.h>
using namespace std;
class T{
int val ;
public :
T(int n ):val(n){};
T():val(0){};
friend T operator+(const T& , const T&);
friend ostream& operator<<(ostream& , T&);
friend istream& operator>>(istream& , T&);
};
T operator+(const T& obj1 , const T& obj2){
return T(obj1.val + obj2.val) ;
}
ostream& operator<<(ostream& out , T& obj){
out << obj.val ;
return out ;
}
istream& operator>>(istream& in , T& obj){
cout << "donner la valeur: " ;
in >> obj.val ;
}
class Td{
double *tab ;
int taille ;
public :
Td(double *Array = NULL , int tal = 0){
taille = tal ;
if(tal != 0){
tab = new double[tal];
for(int i = 0 ; i<tal ; i++){
tab[i] = Array[i] ;
}
}
}
Td(const Td& obj){
tab = obj.tab ;
taille = obj.taille ;
}
~Td(){ delete tab ; }
double* getTab(){
return tab ;
}
int getTaille(){
return taille ;
}
Td& operator=(Td& obj ){
tab = obj.tab ;
return *this ;
}
double& operator[](int pos){
if(pos >= taille){
cout << "out of order !" << endl ;
cout << "this array have " << taille << " only" << endl ;
exit(0);
}
return tab[pos] ;
}
int Taille(){
return taille ;
}
friend ostream& operator<<(ostream& , Td&);
};
ostream& operator<<(ostream& out , Td& obj){
for(int i = 0 ; i<obj.taille ; i++){
out << obj.tab[i] << "\t" ;
}
return out ;
}
class poly{
Td coeff ;
int degre ;
public :
poly(Td coef , int degree){
degre = degree ;
for(int i=0 ; i< degree ; i++ ){
coeff.tab[i] = coef.tab[i];
}
}
poly(const poly& obj){
coeff = obj.coeff ;
degre = obj.degre ;
}
friend ostream& operator<<(ostream& , poly&) ;
};
ostream& operator<<(ostream& out , poly& obj){
for(int i = 0 ; i<= obj.degre ; i++){
if(obj.coeff.tab[i] > 0){
out << " + " obj.coeff.tab[i] << " X(" << i << ")" ;
}else {
out << " - " obj.coeff.tab[i] << " X(" << i << ")" ;
}
}
return out ;
}
int main()
{
T t[5] ;
/*
for(int k = 0 ; k<5 ; k++){
cin >> t[k] ;
}
int i , j ;
for(i = 0 ; i<5 ; i++){
for(j = 0 ; j<=i ;j++){
T v = t[i] + i + j ;
cout << v << "\t" ;
v = 0 ;
}
cout << endl ;
}
*/
double a[] = {1 , 4 , 3 , 5} ;
Td obj1( a , 4);
poly polynome1( obj1 , 4);
cout << polynome1 << endl ;
return 0;
}