-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalphabet.cpp
55 lines (50 loc) · 1.12 KB
/
alphabet.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
#include "alphabet.hpp"
#include <iostream>
#include <cmath>
void alphabet::addCharToAlphabet(Character value)
{
alpha.push_back(value);
}
void alphabet::printAlphabet()
{
for(unsigned int i = 0; i < alpha.size(); i++)
{
std::cout << alpha.at(i).toString() << " and ";
}
std::cout << "no more";
}
Character alphabet::getCharacter(int index)
{
if(index < (int) alpha.size() && index >= 0)
{
return alpha.at(index);
}
else
{
std::cout << "index doesn't exist. returning with NULL character\n";
return Character("NULL");
}
}
str alphabet::findNLexo(int n)
{
str temp;
int count = 0;
int tmp = 1;
while(tmp <= n)
{
n -= tmp;
count++;
tmp = pow((double) alpha.size(), (double) count);
}
temp = lexoFindHelper(n,count, temp);
return temp;
}
str alphabet::lexoFindHelper(int n, int count, str temp)
{
for(int i = 0; i < count; i++)
{
temp.addCharToStrFront(alpha.at(n % alpha.size()).toString());
n = n/alpha.size();
}
return temp;
}