course.wilkes.edu/CS125Labs
Welcome to the site for CS 125 labs!

 

LifeGame.doc

Prev | Next | Lab 12

// LifeGame.doc documents LifeGame, a class for playing the game of Life.
// Author: Joel Adams, for Hands On C++.
// Date: November 1997.
//

#ifndef LIFE_GAME #define LIFE_GAME

#include <iostream> // istream #include <string> // string #include <cassert> // assert() #include <vector> // vector<> using namespace std;

class LifeGame { public: // ************************************************** // * LifeGame constructor. * // * Receive: fileName, a string. * // * Precondition: fileName contains the name of * // * a file containing a Life configuration * // * (the number of rows, the number of columns, * // * and the values of each cell). * // * Postcondition: myGrid has been initialized * // * to the configuration in fileName. * // ************************************************** LifeGame(const string & fileName);

// *************************************************** // * LifeGame Rows extractor. * // * Return: the number of rows in my configuration. * // *************************************************** int Rows() const;

// ****************************************************** // * LifeGame Columns extractor. * // * Return: the number of columns in my configuration. * // ****************************************************** int Columns() const;

// ****************************************************** // * Generate next LifeGame generation. * // * Postcondition: For each cell myGrid[r][c]: * // * if myGrid[r][c] had 3 living neighbors: * // * myGrid[r][c] contains a 1. * // * if myGrid[r][c] had less than 2 neighbors OR * // * myGrid[r][c] had more than 3 neighbors: * // * myGrid[r][c] contains a 0. * // ****************************************************** void NextGeneration();

// ****************************************************** // * LifeGame Print function member. * // * Receive: out, an ostream. * // * Output: my configuration. * // * Passback: out, containing my configuration. * // ****************************************************** void Print(ostream & out) const; private:

};

//******************************************************** // Ostream insertion operator. * // Receive: out, an ostream, * // theGame, a LifeGame. * // Output: the configuration in theGame. * // Passback: out, containing the output configuration. * // Return: out, for chaining. * //******************************************************** inline ostream & operator<<(ostream & out, const LifeGame & theGame) { theGame.Print(out); return out; }

/* inline int LifeGame::Rows() const {   } */

#endif

Prev | Next | Lab 12

 
  Home

Help

Lab 0

Lab 1

Lab 2

Lab 3a

Lab 3b

Lab 4

Lab 5

Lab 6

Lab 7

Lab 8

Lab 9

Lab 10

Lab 11

Lab 12

Lab 13



Membership

Login




Last update: Tuesday, November 28, 2000 at 12:55:34 PM.
visitors to this page.