wheel.cpp - Author Brian Choi([email protected] CS 31...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
// Author: Brian Choi ([email protected]) // CS 31 Practice. #include <cassert> #include <cctype> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <iostream> #include <vector> using namespace std; class WheelOfFortune { public: WheelOfFortune(const char* puzzle); ~WheelOfFortune(); bool resetPuzzle(const char* puzzle); int guess(char c); bool solvePuzzle(const char* puzzle); void printPuzzle() const; bool solved() const; private: bool validPuzzle(const char* puzzle) const; char* m_solution; // Solution. char* m_solvedPuzzle; // (Maybe partially) solved puzzle. }; WheelOfFortune::WheelOfFortune(const char* puzzle) { m_solution = NULL; m_solvedPuzzle = NULL; assert(resetPuzzle(puzzle)); // Initial puzzle must be valid. } WheelOfFortune::~WheelOfFortune() { // TODO: Implement the destructor. delete[] m_solution; delete[] m_solvedPuzzle; // Solution ends. } bool WheelOfFortune::resetPuzzle(const char* puzzle) { if (validPuzzle(puzzle)) { // TODO: If "puzzle" is a valid word puzzle, reset the solution and // m_solvedPuzzle, and return true. Otherwise, don't do anything and return // false. // Delete the old strings. delete[] m_solution; delete[] m_solvedPuzzle; // Allocate the arrays newly. int length = strlen(puzzle);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
m_solution = new char[length + 1]; m_solvedPuzzle = new char[length + 1]; // Copy "puzzle" to m_solution. strcpy(m_solution, puzzle); // Generate an unsolved puzzle. for (int i = 0; i < length; i++)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/06/2011 for the course CS 31 taught by Professor Melkanoff during the Spring '00 term at UCLA.

Page1 / 5

wheel.cpp - Author Brian Choi([email protected] CS 31...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online