Starting from:

$25

CPSC 1021 -  Lab 8 – Solved

 

C++ Classes


 
 
In today’s lab, we will be implementing a board class to play a game of tic tac toe. We will also continue to practice with I/O manipulation and stringstreams.

Lab Objectives
•         C++ File I/O + Manipulators

•         Writing a Board class

•         Object oriented programming

•         Using stringstreams to quickly build formatted strings

Lab Instructions
Create 3 files, main.cpp, makefile, and board.cpp. Your program does not need command line arguments, but will take in user input via std::cin. You may not use printf or scanf in your program.

Sample Output

Before we go any further, here is the expected output for a default gameboard:

 

Board Class
You will be provided with the board.hpp file. In C++ your header files can be .h or .hpp.  Using the .hpp allows a way to distinguish between C++ and C header files.  You must create a board.cpp file and implement all the functions defined in board.hpp. You may create more functions; however, you shouldn’t need to.

The print function should use a stringstream to build and return a string that you’ll print to the terminal in the main(). See sample output above.

Assumptions you can make:

-          Your program does not need to check if there is already a game piece in a given position. Assume we will not test this.

-          Your program does need to check if we are entering a number between 1 and 9.

-          Your program does need to match my formatting.


Sample input and output:     


More products