Repository navigation
Expand file tree
/
Copy pathMain.cpp
More file actions
103 lines (77 loc) · 2.42 KB
/
Copy pathMain.cpp
File metadata and controls
103 lines (77 loc) · 2.42 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
/*----------------------------------------------------------------
* Author: Maxim Kukhtenkov
* Written: 10/10/2014
* Last updated: 10/10/2014
*
* Main Class for a Word Search Puzzle
*
*
*----------------------------------------------------------------*/
#include <iostream>
#include <string>
#include "WordGrid.h"
int main()
{
std::cout << "\n-------------------\n"
<< " Word Search \n"
<< "-------------------\n\n\n";
//-------------------------------------------------------
/* 1. Input the number of rows and columns */
//-------------------------------------------------------
int rows;
int columns;
std::cout << "Enter the number of rows: ";
std::cin >> rows;
std::cout << "Enter the number of columns: ";
std::cin >> columns;
WordGrid* grid = new WordGrid(rows, columns);
grid->display();
/*---------------------------------------------------------
* 2. Chose the wrap or no wrap mode
*-------------------------------------------------------*/
bool wrap = false;
int choice;
std::cout << "Choose the mode: \n1. Wrap\n2. No wrap\n(Type 1 for wrap or 2 for no-wrap)\n";
std::cin >> choice;
// Validate input
while (choice < 1 || choice > 2)
{
std::cout << "Please type 1 for Wrap mode or 2 for No Wrap";
std::cin >> choice;
}
// Assign wrap
switch (choice)
{
case 1: wrap = true;
std::cout << "You chose the WRAP mode\n";
break;
case 2: wrap = false;
std::cout << "You chose the NO WRAP mode\n";
break;
}
grid->initializeNeighbors(wrap);
/*---------------------------------------------------------
* 3. Insert words and search them in the grid
*-------------------------------------------------------*/
int numOfWords;
std::cout << "How many words do you wish to find?\n";
std::cin >> numOfWords;
std::cin.ignore(); // Consume newline left over
std::string* words = new std::string[numOfWords];
// Enter the words
std::cout << "Enter " << numOfWords << ((numOfWords > 1) ? " words: " : " word: ") << "\n";
for (int i = 0; i < numOfWords; i++)
{
std::getline(std::cin, words[i]);
}
// Search and output the result
std::cout << "\n------------\n Output\n------------\n\n";
for (int i = 0; i < numOfWords; i++)
{
grid->searchWord(words[i]);
}
std::cout << "Thanks for playing!\n";
delete[] words;
delete grid;
return 0;
}