-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparttwo.cpp
More file actions
219 lines (190 loc) · 4.59 KB
/
parttwo.cpp
File metadata and controls
219 lines (190 loc) · 4.59 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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
//Aaron Bading
#include "parttwo.h"
const int POSLEN = 20;
const int LINELEN = 120;
int positions[POSLEN];
int totStrings = 0;
Parttwo::Parttwo()
{
int numstrings;
computeLengths();
showPositionsArray();
ifstream in("multiStrings.txt");
in>> numstrings;
in.seekg(0);
in.close();
display(true,numstrings);//initial display is true
directAccess();
}
void Parttwo::computeLengths()
{
ifstream in;
char line[LINELEN];
in.open("multiStrings.txt");
if(in.fail())
{cout << "Fail" << endl;}
positions[0] = 0;
while(in.getline(line, LINELEN))
{
positions[totStrings] = strlen(line)+1;
// cout << "number of chars = " << positions[totStrings++] << endl;
positions[totStrings++];
line[strlen(line)] = '\0';
// cout << "string = " << line << endl;
}
in.close();
}
void Parttwo::directAccess()
{
int i, j, currentPos = positions[0];
char line[LINELEN];
ifstream in;
in.open("multiStrings.txt");
in.seekg(currentPos);
string st1,st2;
for(i = 1; i < totStrings-1; i++)
{
in.getline(line, LINELEN);
line[strlen(line)] = '\0';
cout << endl;
// cout << "this string [" << line << "]" << endl;
st1=line;
//now st1 holds the string to be compared to
display(false,i); // this is the ongoing display prints the number and amount of slashes
for(j = i+1; j < totStrings; j++)
{
in.getline(line, LINELEN);
line[strlen(line)] = '\0';
// cout << " compared with [" << line << "]" << endl;
st2=line;
cout << analysis(st1,st2) << " " ; // this will
}
currentPos += positions[i];
in.seekg(currentPos);
}
cout << endl << endl;
}
void Parttwo::showPositionsArray()
{
int i;
for(i = 0; i < totStrings; i++)
{
//cout << " line " << i << " length of string on that line " << positions[i] << endl;
}
}
char Parttwo::analysis(string st1, string st2)
{
int m,n;
m=st1.size();
n=st2.size();
//dynamically allocated 2d array of ints based on size2 and n
int** bucket;
bucket = new int*[2];
for(int i=0; i<2; i++)
{bucket[i]=new int[n+1];}
//initiailize to n=1 bcause we want one more than the size
for(int i=0;i<n+1;i++)
{bucket[0][i]=0;}
bucket[1][0]=0;
//compare the two strings lenghts and determine which one is shorter.
string shorter, longer;
if(st1.size()<st2.size())
{shorter=st1;
longer=st2;}
else
{
shorter=st2;
longer=st1;
}
//compute the LCS of the two strings.
for(int i=0; i<m;i++)
{
//generate row two
bucket[1][0]=0;
char comp =st1.at(i);
for(int j=1; j<n;j++)
{
if(comp==st2.at(j))
{bucket[1][j]=bucket[0][j-1]+1;}
else
{
if(bucket[0][j]>=bucket[1][j-1])
{bucket[1][j]=bucket[0][j];}
else
{bucket[1][j]=bucket[1][j-1];}
}
}
//added section
/*
cout << " PRINTING " << i << endl;
//printing the array
for(int i=0; i<2; i++)
{
for(int j=0; j<=n; j++)
{cout << bucket[i][j] << " ";
}
cout << endl;
}
*/
//make row two row one
for(int i=0;i<n+1;i++)
{bucket[0][i]=bucket[1][i];}
bucket[1][0]=0;
}
//cout << "LCS " << bucket[1][n-1];
int lcs = bucket[1][n-1]; // this is the lcs ....there is some uncertainty here, but when is there ever certainty.
//compare lcs value to the length of shorter string
double k,h; // there are going to be the lengths of the shorter and longer strings
k=shorter.size();
h=longer.size();
//first condition
//lcs is at least 90% of length of shorter.
//length of shorter string is withing 10% of length of longer string
//meaning that length of shorter string must me greater than or equal 90% of length of longer ?????
if((lcs>=(.9*k)&& (k>=.9*h)))
{return 'H';}
// lcs is at least 80% of length of shorter string
// short string is withing 20% of length of longer string
if( (lcs>=(.8*k)&& (k>=.8*h)))
{return 'M';}
//lcs is 50 % of length of shorter string
//length of shorter string is within 40 % of length of longer string.
if( (lcs>=(.5*k)&& (k>=.6*h)))
{return 'L';}
return 'D';
}
void Parttwo::display(bool decision,int howmany)
{
string temp;
if(decision)
{//intial display
ifstream in("multiStrings.txt");
int num;
in>>num;
cout << endl<< endl;
cout << "Part Two : " << endl;
//enter more information about the conditions here.......
//
//
for(int i=1; i<=num+1; i++)
{
getline(in,temp);
if(i!=1)
{cout << i-1 << " = " << temp << endl;}
}
in.clear();
in.seekg(0);
cout << endl;
cout << " " ;
for(int i=1; i<=howmany; i++)
{
cout << i << " " ;
}
}
else
{//ongoing display
cout << howmany <<" ";
for(int i=1; i<=howmany; i++)
cout <<"/ "<< " " ;
}
}