Coding_for_Crosswords_in_Py.../a.c

55 lines
1.1 KiB
C
Raw Normal View History

2021-07-13 17:27:14 +02:00
#include <iostream> // library for printing
#include <string> // support for strings
#include <vector> // support for vectors
#include <assert.h>
using namespace std;
2021-07-11 19:11:55 +02:00
// For compiling C++ code
// g++ a.c -o a
2021-07-14 21:10:44 +02:00
struct Grid
{
Grid(string n) {
name = n;
}
int rows() const { return lines.size(); }
int cols() const {
if (lines.empty()) {
return 0;
} else {
return lines[0].size(); }
}
void Load() {
lines.push_back("DOG....");
lines.push_back("---....");
lines.push_back("----...");
lines.push_back("-------");
lines.push_back("...----");
lines.push_back("....---");
lines.push_back("....CAT");
}
void Check() const {
for (string s : lines)
{
assert(s.size() == cols());
}
}
void Print() const {
cout << "Grid: " << name
<< " (rows=" << rows()
<< ", cols=" << cols() << ")\n";
for (string s : lines) {
cout << " " << s << "\n";
}
}
string name; // string are initialized empty
vector<string> lines;
};
2021-07-11 19:11:55 +02:00
2021-07-13 17:27:14 +02:00
int main()
{
2021-07-14 21:10:44 +02:00
Grid grid("MY GRID");
2021-07-13 17:27:14 +02:00
2021-07-14 21:10:44 +02:00
grid.Load();
grid.Check();
grid.Print();
2021-07-11 19:11:55 +02:00
}