-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathex52.cpp
More file actions
67 lines (55 loc) · 1.03 KB
/
ex52.cpp
File metadata and controls
67 lines (55 loc) · 1.03 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
/*
CPSC 121-0X
Paul De Palma
depalma
Example 52
*/
//Creating the BIFID key and BIFID array
#include <iostream>
#include <string>
using namespace std;
const int MAX = 5;
string getKey();
void createBifid(char[][MAX],string);
void display(char[][MAX]);
int main()
{
string key = getKey();
char bifid[MAX][MAX];
createBifid(bifid,key);
display(bifid);
}
string getKey()
{
string key;
cout << "Enter up to 25 UC chars, no duplicates, no J " << endl;
getline(cin,key);
for (int i = 0; i < 26; i++)
{
char ch = 'A' + i;
if (ch != 'J')
if (key.find(ch) == string::npos)
key = key + ch;
}
return key;
}
void createBifid(char bifid[][MAX],string key)
{
int k = 0;
for (int row = 0; row < MAX; row++)
for (int col = 0; col < MAX; col++)
{
bifid[row][col] = key.at(k);
k++;
}
}
void display(char bifid[][MAX])
{
for (int row = 0; row < MAX; row++)
{
string out;
for (int col = 0; col < MAX; col++)
out = out + bifid[row][col];
cout << out << endl;
}
}