-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathelement.cpp
More file actions
82 lines (65 loc) · 1.79 KB
/
element.cpp
File metadata and controls
82 lines (65 loc) · 1.79 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
#include <iostream>
#include "element.h"
#include <memory>
#include <algorithm>
template<>
std::string TElement<int>::toString() const{
return std::to_string(val);
}
template<>
std::string TElement<char>::toString() const{
return std::string(1, val);
}
template<>
int TElement<int>::evaluate(const Valuation& v) const{
return val;
}
template<>
int TElement<char>::evaluate(const Valuation& v) const{
auto result = v.find(val);
if(result != v.end()){
return result->second;
}
throw "Ei löytynyt";
}
//! yhteenlaskee parametrin ja käsiteltävän olion kokonaisluvun ja sijoittaa sen käsiteltävälle oliolle
template<>
TElement<int>& TElement<int>::operator+=(const TElement<int>& i){
val = i.val + val;
return *this;
}
//! vähentään käsiteltävän olion arvosta parametriolion arvon
template<>
TElement<int>& TElement<int>::operator-=(const TElement<int>& i){
val = val - i.val;
return *this;
}
//! kertoo olioiden arvot keskenään ja sijoittaa käsiteltävään olioon
template<>
TElement<int>& TElement<int>::operator*=(const TElement<int>& i){
val = i.val * val;
return *this;
}
//! tekee temp olion parametriolioiden arvojen summasta
IntElement operator+(const IntElement& a, const IntElement& i){
IntElement temp(a);
temp += i;
return temp;
}
//! tekee temp olion vähentämällä ensimmäisestä parametriolion arvosta toisen olion arvon
IntElement operator-(const IntElement& a, const IntElement& i){
IntElement temp(a);
temp -= i;
return temp;
}
//! tekee temp olion parametriolioiden arvojen kertolaskusta
IntElement operator*(const IntElement& a, const IntElement& i){
IntElement temp(a);
temp *= i;
return temp;
}
//! sijoittaa käsiteltävän olion arvon streamiin
std::ostream& operator<<(std::ostream& out, const Element& i){
out << i.toString();
return out;
}