-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathterm.cpp
More file actions
53 lines (46 loc) · 786 Bytes
/
term.cpp
File metadata and controls
53 lines (46 loc) · 786 Bytes
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
//term.cpp
//implementatin for term.h
#include "term.h"
#include <iostream>
std::ostream& operator<<(std::ostream& oStr, const term& myTerm)
{
if (myTerm.exp ==1)
oStr << myTerm.coeff << "x";
if (myTerm.exp ==0)
oStr << myTerm.coeff;
if (myTerm.exp > 1)
oStr << myTerm.coeff << "x^" << myTerm.exp;
return oStr;
}
term::term()
{
coeff=0;
exp=0;
}
term::term(int a, int b)
{
coeff=a;
if (b>=0)
exp=b;
else
{
b=0;
std::cout << "ERROR: Negative Exponent in term(int,int)." << std::endl;
}
}
term::term(const term& t)
{
coeff=t.coeff;
exp=t.exp;
}
term term::operator* (const term& t)
{
term result;
result.coeff=(this->coeff*t.coeff);
result.exp=(this->exp+t.exp);
return result;
}
bool term::operator> (const term& t) const
{
return ((exp)>(t.exp));
}