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

Info icon This 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; };
Image of page 1

Info icon This 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.
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 ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern