Guest User

Untitled

a guest
Sep 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <iostream>
  2. #include "Board.h"
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. Board b(10);
  8. b.displayBoard();
  9. return 0;
  10. }
  11.  
  12. #pragma once
  13. #include <string>
  14. #include <iostream>
  15. using namespace std;
  16. class Board
  17. {
  18. public:
  19. int width = 10;
  20. int height = 10;
  21. char spaces[1000];
  22. Board(int);
  23. ~Board();
  24. const int Area();
  25. //...//
  26. void displayBoard(); // <- not being recognized?!
  27. //...//
  28. };
  29.  
  30. #include "pch.h"
  31. #include "Board.h"
  32. #include <iostream>
  33. using namespace std;
  34.  
  35. Board::Board(int s)
  36. {
  37. width = height = s;
  38. //assumes spaces holds at least width*height
  39. for (int i = 0; i < height; i++) {
  40. for (int j = 0; j < width; j++) {
  41. if (static_cast<bool>((i + j) % 2)) {
  42. spaces[i*width + j] = ' ';
  43. }
  44. else {
  45. spaces[i*width + j] = '#';
  46. }
  47. }
  48. }
  49. }
  50.  
  51. Board::~Board()
  52. {
  53. //delete spaces;
  54. }
  55.  
  56. const int Board::Area()
  57. {
  58. return width * height;
  59. }
  60.  
  61. //...//
  62.  
  63. void Board::displayBoard(void)
  64. {
  65. for (int i = 0; i < height; i++) {
  66. for (int j = 0; j < width; j++) {
  67. cout << spaces[i*width + j];
  68. }
  69. cout << endl;
  70. }
  71. return void();
  72. }
  73.  
  74. //...//
Add Comment
Please, Sign In to add comment