forked from shyawnkarim/Poly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
143 lines (120 loc) · 4.25 KB
/
main.cpp
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
// DO NOT change anything in this file. Your code must compile and give the
// correct output with this main on the linux machines.
// Make sure the file containing the member function source is: poly.cpp
// Use all lowercase in the file names.
// This main does not do a thorough job of testing. When testing arrays,
// be sure to test the middle and also all the boundary conditions. Test
// values on the boundary and outside the boundaries, i.e., too big/small.
#include "poly.h"
#include <iostream>
using namespace std;
int main()
{
// Poly A;
// Poly B;
//
// cout << "Enter terms for polynomial A. Enter a coefficient " << endl
// << "then exponent for each term. Enter -1 -1 to terminate." << endl;
// cin >> A;
//
// cout << "Enter terms for polynomial B. Enter a coefficient " << endl
// << "then exponent for each term. Enter -1 -1 to terminate." << endl;
// cin >> B;
//
//
// cout << A << endl;
// cout << B << endl;
// // set poly A and print
// Poly A(5, 7);
// A.setCoeff(10, 1);
// A.setCoeff(-4, 3);
// A.setCoeff(-2, 0);
// cout << "A = " << A << endl;
// cout << "=== A = +5x^7 -4x^3 +10x -2" << endl << endl;
//
// // set poly B and print
// Poly B(3, 4);
// B.setCoeff(1, 3);
// cout << "B = " << B << endl;
// cout << "=== B = +3x^4 +1x^3" << endl << endl;
//
// // Min Chen Polies
// Poly C(2), D(A), X, Y;
// Poly A2, B2, Z1, Z2;
//
// A2 = A;
// cout << "A2 = " << A2 << endl;
//
// B2 = B;
// cout << "B2 = " << B2 << endl;
//
// C = A + B;
// cout << "C = " << C << endl << endl;
//
// cout << ((A == B) ? "A == B" : "A is not == B") << endl;
// cout << ((A != B) ? "A is not == B" : "A == B") << endl << endl;
//
// Z1 = A2 - B2;
// cout << "Z1 = " << Z1 << endl;
// cout << "=== Z1 = +5x^7 -3x^4 -5x^3 +10x -2" << endl << endl;
//
// Z2 = B2 - A2;
// cout << "Z2 = " << Z2 << endl;
// cout << "=== Z2 = -5x^7 +3x^4 +5x^3 -10x +2" << endl << endl;
//--------------------------------------------
// Poly A(5, 7), B(3, 4), C(2), D(A), X, Y;
// Poly A2, B2, Z1, Z2;
//
// A.setCoeff(10, 1);
// A.setCoeff(-4, 3);
// A.setCoeff(-2, 0);
Poly A(5, 7), B(3, 4), C(2), D(A), X, Y;
Poly A2, B2, Z1, Z2;
// set polynomials A and B to desired values
// A = +5x^7 -4x^3 +10x -2
// B = +3x^4 +1x^3
cout << "Enter terms for polynomial A. Enter a coefficient " << endl
<< "then exponent for each term. Enter -1 -1 to terminate." << endl;
// cin >> A; // or use a bunch of setCoeff
A.setCoeff(5, 7);
A.setCoeff(10, 1);
A.setCoeff(-4, 3);
A.setCoeff(-2, 0);
cout << "Enter terms for polynomial B. Enter a coefficient " << endl
<< "then exponent for each term. Enter -1 -1 to terminate." << endl;
// cin >> B; // or use a bunch of setCoeff
B.setCoeff(3, 4);
B.setCoeff(1, 3);
// outputs exactly what is in quotes: "A = +5x^7 -4x^3 +10x -2"
cout << "A =" << A << endl;
// outputs exactly what is in quotes: "B = +3x^4 +1x^3"
cout << "B =" << B << endl << endl;
A2 = A;
B2 = B;
C = A + B;
cout << "Compute C = A + B: " << C << endl << endl;
cout << ((A == B) ? "A == B" : "A is not == B") << endl;
cout << ((A != B) ? "A is not == B" : "A == B") << endl << endl;
Z1 = A2 - B2;
cout << "Compute Z1 = A2 - B2: " << Z1 << endl;
Z2 = B2 - A2;
cout << "Compute Z2 = B2 - A2: " << Z2 << endl << endl;
cout << "Compute D = A * B - 15" << endl;
cout << "Before: D =" << D << endl;
D = A * B - 15;
cout << "After: D =" << D << endl << endl;
cout << "Test assignment operators" << endl;
X = C = D = D;
Y += A -= B *= A;
cout << "X =" << X << endl;
cout << "Y =" << Y << endl << endl;
cout << "Get and Set coefficient" << endl;
int coeff = D.getCoeff(0);
cout << "coeff of subscript 0 of D is: " << coeff << endl;
cout << "Doing getCoeff for term -20000" << endl;
coeff = D.getCoeff(-20000); // handle value out of range
D.setCoeff(50, 0); // set x^0 coeff to 50
D.setCoeff(50, 20000); // set x^20000 coeff to 50
cout << "D =" << D << endl << endl;
return 0;
}