-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiset.cpp
102 lines (82 loc) · 2.07 KB
/
multiset.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
#include <iostream>
#include <sstream>
#include <string>
#include "multiset.h"
// basic constructor
multiSet::multiSet(){
for(int i = 0; i < 129; i++){
count_array[i] = 0;
}
}
//constructor that uses a string
multiSet::multiSet(char *str){
for( int i = 0; str[i]!= '\0'; i++){
count_array[int(str[i])]++;
}
}
multiSet::multiSet(alphabet * my_alphabet){
for( int i = 0; i< 129 ; i++){
if(my_alphabet->isMember(i)){
count_array[i]++;
}
}
}
bool multiSet::reset(){
for(int i = 0; i < 129; i++){
count_array[i] =0;
}
return true;
}
void multiSet::display(){
for( int i = 0; i < 129; i++){
cout<<count_array[i];
}
}
int& multiSet::operator [](char c){ // int& so that it returns a reference and does not create a new int.
return count_array[int(c)];
}
multiSet multiSet:: operator + (alphabet my_alphabet){
multiSet temp;
for( int i = 0; i < 129 ; i++){
if(my_alphabet.isMember(i)){
temp.count_array[i] = this->count_array[i] + 1 ;
// cout << temp.count_array[i]<<endl;
}
else{
temp.count_array[i] = this->count_array[i];
// cout<< temp.count_array[i]<<endl;
}
}
return temp;
}
multiSet multiSet:: operator + (multiSet my_multiSet){
multiSet temp;
for( int i = 0; i < 129 ; i++){
temp.count_array[i] = this->count_array[i] + my_multiSet.count_array[i] ;
}
return temp;
}
bool multiSet:: operator == (multiSet my_multiSet){
for( int i = 0; i < 129 ; i++){
if(this->count_array[i] != my_multiSet.count_array[i]){
return false;
}
}
return true;
}
ostream& operator << (ostream& s, multiSet& a){
for(int i = 0 ; i < 129; i++){
s << a.count_array[i];
}
s<<endl;
return s;
}
/* Still to confirm the useage of this function. Currently it is not being used, becuase of some confusion on my part
with regards to its appropriate usages.
istream& operator >> (istream& s, multiSet& a){
// for (int i =0; i < 128; i++){
s >> a.count_array[i];
// }
return s;// does this return s or a? plese to be checking and confirming.
}
*/