{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

assg4.pdf - CSCI1120 Introduction to Computing Using C Fall...

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

View Full Document Right Arrow Icon
CSCI1120 Introduction to Computing Using C++, Fall 2016 Department of Computer Science and Engineering, The Chinese University of Hong Kong Copyright © 2016 CSE, CUHK Page 1 of 5 Assignment 4: 15 - Puzzle Due: 20:00, Wed 23 Nov 2016 Full marks: 100 Introduction The 15-puzzle is a sliding puzzle played on a square board of 15 tiles with one tile missing. The tiles are numbered 1 to 15, placed randomly in the board. The goal of the puzzle is to place the tiles in order (See Figure 1) by sliding the tiles one at a time. In this assignment, you will apply object- oriented programming to write a program to play 15-puzzles. 2 3 14 4 9 5 7 8 6 . 1 11 13 10 15 12 After some moves 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 . Figure 1: An Initial 15-Puzzle (Left) and A Solved 15-Puzzle (Right) Program Specification You have to write your program in two source files FifteenPuzzle.cpp and playgame.cpp . The former is the implementation of the class FifteenPuzzle , while the latter is a client program of class FifteenPuzzle which performs the program flow. You are recommended to finish the FifteenPuzzle class first before writing the client program. When you write the FifteenPuzzle class, implement the member functions and test them individually one by one . Your two files will be graded separately, so you should not mix the functionalities of the two files. Also, you cannot declare any global variables in all your source files (except const ones). Class FifteenPuzzle ( FifteenPuzzle.cpp ) You are given the interface of the FifteenPuzzle class in the header file FifteenPuzzle.h . You are not allowed to modify the contents of this header file. Descriptions of its members are given below. class FifteenPuzzle { public: FifteenPuzzle(unsigned s); bool move(char dir); void print() const; bool isSolved() const; int getSteps() const; private: int board[4][4]; int r, c, steps; };
Background image of page 1

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

View Full Document Right Arrow Icon
CSCI1120 Introduction to Computing Using C++, Fall 2016 Department of Computer Science and Engineering, The Chinese University of Hong Kong Copyright © 2016 CSE, CUHK Page 2 of 5 Private Data Members int board[4][4]; The 15-puzzle is represented by a two-dimensional array of int , storing the numbers 1 to 15 on the tiles. The elements board[0][0] and board[3][3] denote the top-left and bottom-right corners of the puzzle respectively. The missing tile is denoted by the special value 16.
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.

{[ snackBarMessage ]}