Module 13: Add Point structure

This commit is contained in:
David Doblas Jiménez 2021-08-09 18:10:52 +02:00
parent b27c93dfd2
commit c34f2307c0
1 changed files with 27 additions and 4 deletions

31
a.c
View File

@ -17,6 +17,22 @@ string ToUpper(string s) {
return s2;
}
// --------------------------------------------------------------------------------
//-Point
struct Point {
Point() {}
Point(int r, int c) : row(r), col(c) {}
friend ostream& operator<<(ostream& os, const Point& p); // overloading the "<<" op
int row = 0; // defaults value for the constructor
int col = 0;
};
ostream& operator<<(ostream& os, const Point& p) { // for printing
os << "(" << p.row << "," << p.col << ")";
return os;
}
// --------------------------------------------------------------------------------
//-Word
struct Word {
@ -78,6 +94,7 @@ public:
}
void CreatePatternHash(Word* w) {
int len = w->len();
if (len > 7) return; // avoid load of long words
int num_patterns = 1 << len; // create 2^len patterns
// cout << "PATTERN HASH on " << w->word << "\n";
for (int i=0; i<num_patterns; i++) {
@ -172,8 +189,14 @@ int main() {
lib.FindWord("D--");
//Grid grid("MY GRID");
//grid.LoadFromFile("test");
//grid.Check();
//grid.Print();
Grid grid("MY GRID");
grid.LoadFromFile("test");
grid.Check();
grid.Print();
Point p1;
Point p2(2,1);
cout << "Point1 is " << p1 << "\n";
cout << "Point2 is " << p2 << "\n";
}