30.00 $

Programming resource
Digital learning resource
Category:
✓ Practical programming resource
✓ Suitable for guided study and reference
✓ Tutor guidance available when needed

Description

Rate this product
 
 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:   

 

Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.