-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
155 lines (136 loc) · 4.2 KB
/
main.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
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
#include <iostream>
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define loop(n) for (ll i = 0; i < n; i++)
const char* braille[26] = {
"000001", "000101", "000011", "001011", "001001",
"000111", "001111", "001101", "000110", "001110",
"010001", "010101", "010011", "011011", "011001",
"010111", "011111", "011101", "010110", "011110",
"110001", "110101", "101110", "110011", "111011", "111001"
};
// Print all the alphabet letters in Braille
void braille_AllLetters() {
for (int i = 0; i < 26; i++) {
char c = 'A' + i;
cout << c << " -> \n";
for (int row = 2; row >= 0; row--) {
if (braille[i][row * 2 + 1] == '1') cout << "⠁";
else cout << " ";
if (braille[i][row * 2] == '1') cout << "⠁";
else cout << " ";
cout << "\n";
}
}
}
// Convert a single letter into Braille
void braille_Letter(char c) {
c = char(toupper(c));
for (int row = 2; row >= 0; row--) {
if (braille[c - 'A'][row * 2 + 1] == '1') cout << "⠁";
else cout << " ";
if (braille[c - 'A'][row * 2] == '1') cout << "⠁";
else cout << " ";
cout << "\n";
}
}
// Convert a word into Braille
void braille_Word(string word) {
for (int row = 2; row >= 0; row--) {
for (int i = 0; i < word.size(); i++) {
word[i] = char(toupper(word[i]));
int index = word[i] - 'A';
if (braille[index][row * 2 + 1] == '1') cout << "⠁";
else cout << " ";
if (braille[index][row * 2] == '1') cout << "⠁";
else cout << " ";
cout << " "; // Space between letters
}
cout << endl;
}
}
// Generate a random number between 0 and 25 for the quiz
int generateRandomNumber() {
static bool isSeeded = false;
if (!isSeeded) {
srand(static_cast<unsigned int>(time(0)));
isSeeded = true;
}
return rand() % 26;
}
// Quiz the user by showing Braille and asking them to guess the letter
void Quiz(int q) {
int score = 0;
while (q--) {
cout << "Guess the character: \n\n";
char c = char(generateRandomNumber() + 'A');
braille_Letter(c);
cout << "Your answer is: ";
char b;
cin >> b;
b = char(toupper(b));
if (b == c) {
score += 5;
cout << "\nCorrect! \n\n";
} else {
if (score >= 5) score -= 5;
else score = 0;
cout << "\nIncorrect! The correct answer was: " << c << "\n\n";
}
}
cout << "Your score now is: " << score << "\n";
}
int main() {
cout << "Hello! Hope you're doing great! :) \n"
<< "Welcome to the Braille learning program – let's make learning fun and easy! 🌟\n";
while (true) {
cout << "1. Print all alphabets in Braille.\n"
<< "2. Translate a letter into Braille.\n"
<< "3. Translate a word into Braille.\n"
<< "4. Quiz.\n";
cout << "Choose a num: ";
int choice;
cin >> choice;
switch (choice) {
case 1: {
braille_AllLetters();
break;
}
case 2: {
cout << "Enter a character: ";
char c1;
cin >> c1;
braille_Letter(c1);
break;
}
case 3: {
cout << "Enter a word: ";
string word;
cin >> word;
braille_Word(word);
break;
}
case 4: {
cout << "How many questions do you want? -> ";
int q;
cin >> q;
Quiz(q);
break;
}
default: {
cout << "Invalid choice. Please try again.\n";
}
}
cout << "\nDo you want to continue? \n -Yes/y \t -No/n \n";
string ans;
cout<<"->";
cin >> ans;
if (ans[0] == 'n' || ans[0] == 'N') {
cout << "Great job today! Keep learning and take care! \n Goodbye! ^^ \n";
break;
}
}
return 0;
}