Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- I'm just playing around with inheritance here.
- walledMatrix takes a matrix and lines its "edges" with walls.
- edit: changed to support templates
- */
- template <class T>
- class walledMatrix : public matrix<T>
- {
- public:
- walledMatrix(int x, int y) : matrix<T>(x, y){ wall(); }
- void wall(){
- for (int i = 0; i < length; i++){
- operator()(i, 0) = 6, operator()(i, width - 1) = 7;
- }
- for (int i = 0; i < width; i++){
- operator()(0, i) = 8, operator()(length - 1, i) = 9;
- }
- }
- };
- // Sample program:
- /*
- int _tmain(int argc, _TCHAR* argv[])
- {
- int length = 20, width = 20;
- walledMatrix<int> mat(length, width);
- cout << "Sample area:\n";
- for (int c = 0; c < length; c++){
- cout << endl;
- for (int r = 0; r < width; r++)
- cout << (mat(c, r) ? 'X' : '0');
- }
- cout << endl << endl;
- return 0;
- }
- */
- // sample output:
- /*
- Sample area:
- XXXXXXXXXXXXXXXXXXXX
- X000000000000000000X
- X000000000000000000X
- X000000000000000000X
- X000000000000000000X
- X000000000000000000X
- X000000000000000000X
- X000000000000000000X
- X000000000000000000X
- X000000000000000000X
- X000000000000000000X
- X000000000000000000X
- X000000000000000000X
- X000000000000000000X
- X000000000000000000X
- X000000000000000000X
- X000000000000000000X
- X000000000000000000X
- X000000000000000000X
- XXXXXXXXXXXXXXXXXXXX
- Press any key to continue . . .
- */
Advertisement
Add Comment
Please, Sign In to add comment