-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.cpp
158 lines (130 loc) · 2.69 KB
/
driver.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include<iostream>
#include<conio.h>
#include "PolynomialCalculator.h"
int main()
{
PolynomialCalculator obj(1, 1, 4, 2);
PolynomialCalculator obj2(1, 1, 3, 1, 6, 5);
//obj2.display();
PolynomialCalculator obj3(obj2);
void menu(); // function prototype
while (true) // menu function
{
menu();
char c = _getch();
switch (c)
{
case '1':
{
obj2 + obj;
break;
}
case '2':
{
obj2 - obj;
break;
}
case '3':
{
obj2 *= obj;
break;
}
case '4':
{
int x = 0;
std::cout << "enter the value you want to compute" << std::endl;
std::cin >> x;
std::cout << "value = at x(" << x << ") = " << obj.value(x) << std::endl;
break;
}
case '5':
{
std::cin >> obj;
break;
}
case '6':
{
std::cin >> obj;
break;
}
case '7':
{
std::cout << obj << std::endl;
break;
}
case '8':
{
std::cout << obj2 << std::endl;
break;
}
case 'q':
{
std::cout << obj2 << std::endl;
return 0;
}
default:
{
std::cout << "Invalid user input" << std::endl;
break;
}
} // switch
_getch();
system("cls");
}
//std::cout << obj << std::endl;
//std::cout << obj2 << std::endl;
//std::cout << std::endl << std::endl;
////obj2 = obj;
//std::cout << "///" << std::endl;
////std::cout << obj.value(5) << std::endl;
////std::cout << obj2 << std::endl;
//std::cin >> obj;
//std::cout << obj << std::endl;
//obj + obj2;
//std::cout << obj << std::endl;
//obj.tester();
std::cin.get();
return 0;
}
std::ostream& operator << (std::ostream& out, PolynomialCalculator& p)
{
if (*(p.coefficient) == -1 && *(p.exponent) == -1)
{
out << "Error, there is no polynomial present here" << std::endl;
}
else
{
for (int i = p.exponent_size - 1; i >= 0; i--)
{
if (p.exponent[i] != 0 && p.coefficient[i] != 0)
{
if (p.coefficient[i] > 0 && i != p.exponent_size - 1)
{
out << " + ";
}
if (p.coefficient[i] < 0)
{
out << " ";
}
if (p.coefficient[i] == 0)
{
out << " + ";
}
out << p.coefficient[i] << "x^" << p.exponent[i] << " ";
}
}
}
return out;
}
void menu() // function body
{
std::cout << "Press 1 to add 2 polynomials" << std::endl;
std::cout << "Press 2 to subtract 2 polynomials" << std::endl;
std::cout << "Press 3 to multiply 2 polynomials" << std::endl;
std::cout << "Press 4 to compute the polynomial" << std::endl;
std::cout << "Press 5 to take an input for polynomial" << std::endl;
std::cout << "Press 6 to take an input for polynomial" << std::endl;
std::cout << "Press 7 to display polynomial 1" << std::endl;
std::cout << "Press 8 to display the polynomial 2" << std::endl;
std::cout << "Press q to quit" << std::endl;
}