-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchEngine.cpp
182 lines (161 loc) · 4.69 KB
/
searchEngine.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
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
//This search engine is developed by Muhib Arshad(muib7353)
//Libraries
#include <iostream>
#include <conio.h>
using namespace std;
//Global variables
const int row = 20;
const int col = 21;
//functions Protoptypes
void design();
int length(char arr[]);
void input(char word[][col], int row, char arr[], int x);
void functionality(char words[][col], int row);
//Main
int main()
{
/*Add your possible searching words
and cahnge the number of rows and columns in global according to it*/
char words[row][col] = {
"apply",
"application",
"bat",
"batch",
"battle",
"compute",
"computer",
"compare",
"device",
"develop",
"developer",
"system",
"systemic",
"systole",
"function",
"functional",
"fucntionality",
"handle",
"handler",
"handling"};
//searching functionalty function
functionality(words, row);
return 0;
}
//Designing function How my console look beautiful
void design()
{
//Spacing lines
for (int i = 0; i < 5; i++)
{
cout << endl;
}
//Introductory line
cout << "\t\t\t\t**********WELCOME TO Muhib's SEARCH ENGINE*********" << endl;
for (int i = 0; i < 2; i++)
{
cout << endl;
}
//Instruction
cout << "\t\t\t\tMAIN FEATURES:" << endl;
cout << "\t\t\t\t *During searching it gives you to suggestions." << endl;
cout << "\t\t\t\t *During searching you can press enter and search another word." << endl;
cout << "\t\t\t\t *During searching you can press 0 to exit the program." << endl;
//Spacing lines
for (int i = 0; i < 3; i++)
{
cout << endl;
}
}
//Lenghth function to calcualte the inputing length of a word
int length(char arr[])
{
int count = 0;
for (int i = 0; arr[i] != '\0'; i++)
{
count++;
}
return count;
}
//Input function----(heart of the code)
void input(char word[][col], int row, char arr[], int x)
{
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
//To check every time searching column is start from zero
if (j == 0)
{
//If first letter of the my searching word and suggesting word is same
if (word[i][j] == arr[0])
{
//Check next letters of searching word and suggesting words are same
int count = 0;
for (int l = j, m = 0; m < length(arr); l++, m++)
{
if (word[i][l] == arr[m])
{
count++;
}
}
//if length of the searching word is equal to word suugesting equality count
if (count == length(arr))
{
cout << "\t\t\t\t ";
//if uper condition is true display the suggesting word to the console
for (int k = 0; word[i][k] != '\0'; k++)
{
cout << word[i][k];
}
cout << endl;
}
}
}
}
}
}
//functionality function
void functionality(char words[][col], int row)
{
bool flag = false;
do
{
//calling design function
design();
cout << "\t\t\t\t*******Search Words here********" << endl;
cout << "\t\t\t\t >>";
char arr[row] = {};
for (int x = 0; x < col; x++)
{
//On every input call the design function and clear the previous screen
arr[x] = getch();
system("cls");
design();
cout << "\t\t\t\t*******Search Words here********" << endl;
cout << "\t\t\t\t >>";
for (int i = 0; i < sizeof(arr) / sizeof(char); i++)
{
cout << arr[i];
}
//If enter is pressed than make the console refreshed
if (arr[x] == 13)
{
system("cls");
cout << "\t\t\t\t>>Enter Pressed:" << endl;
break;
x = 0;
}
//if inout is zero quitted
if (arr[x] == '0')
{
cout << endl;
cout << "Quiting.............." << endl;
flag = true;
break;
}
cout << endl;
//call the main heart of the function to search the words
input(words, row, arr, x);
}
} while (flag == false);
}