Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
128 lines (95 loc) · 2.71 KB
/
Copy pathmain.cpp
File metadata and controls
128 lines (95 loc) · 2.71 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
#include <iostream>
#include <cstdlib>
#include "lib/Polynomial.h"
using namespace std;
void inicializers();
void operations();
void printData(const string name, const Polynomial p);
void print(const string name, const Polynomial p);
void division();
void negativeIndexes();
auto &x = Polynomial::x;
int main()
{
system("clear");
inicializers();
// operations();
// negativeIndexes();
// division();
system("pause");
return 0;
}
void inicializers()
{
vector<double> vect = {8, 7, 6, 5};
Polynomial a, b, c, d, e, f;
a = {0, -1, 0, 1, 0, -1, -2, 0};
b = vect;
c = 5;
d = (x ^ 4) * 3 + (x ^ 2) * 7;
e = (x - 3) ^ 3;
f = 4;
f <<= 3;
print("A", a);
print("B", b);
print("C", c);
print("D", d);
print("E", e);
print("F", f);
printData("B", b);
}
void operations()
{
Polynomial p = {4, 7, -3, 5}, q = {1, 6, 3};
cout << "p(x) = " << p << endl;
cout << "q(x) = " << q << endl;
cout << endl;
cout << "(p + q)(x) = " << (p + q) << endl;
cout << "(p - q)(x) = " << (p - q) << endl;
cout << "(p * q)(x) = " << (p * q) << endl;
cout << "(p / q)(x) = " << (p / q) << endl;
cout << "(p % q)(x) = " << (p % q) << endl;
cout << endl;
}
void print(const string name, const Polynomial p)
{
cout << name << "(x) = " << p << endl;
}
void printData(const string name, const Polynomial p)
{
cout << name << "(x) = " << p << endl << endl;
cout << "grade of " << name << ": " << p.grade() << endl << endl;
cout << name << "'(x) = " << p.derivative() << endl;
cout << "|" << name << "(x)dx = " << p.integral() << " + c" << endl << endl;
print("(" + name + " << 3)", p << 3);
print("(" + name + " >> 2)", p >> 2);
for (int i = 0; i <= 5; i++)
cout << name << "(" << i << ") = " << p(i) << endl;
cout << endl;
}
void negativeIndexes()
{
// -6 -5 -4 -3 -2 -1
Polynomial p = {34, 53, 61, 52, 27, 10, 0, 0, 0};
p[-2] = 38;
cout << "p(x) = " << p << endl;
cout << "grade: " << p.grade() << endl;
for (int i = 1; i <= p.grade() + 1; i++)
cout << "p[-" << i << "] -> " << p[-i] << endl;
}
void division()
{
Polynomial p = {34, 53, 61, 52, 27, 10, 0, 0, 0}, q = {4, 3, 2}, s = {8,5,7}, result, residual;
cout << "p(x) = " << p << endl;
cout << "q(x) = " << q << endl;
cout << "s(x) = " << s << endl << endl;
p.writeDivision(q, result, residual);
cout << "(p / q)(x) = " << result << endl;
cout << "(p % q)(x) = " << residual << endl << endl;
q.writeDivision(p, result, residual);
cout << "(q / p)(x) = " << result << endl;
cout << "(q % p)(x) = " << residual << endl << endl;
q.writeDivision(s, result, residual);
cout << "(q / s)(x) = " << result << endl;
cout << "(q % s)(x) = " << residual << endl << endl;
}