GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Jun-2008, 13:37
ar31an ar31an is offline
New Member
 
Join Date: May 2008
Posts: 8
ar31an is on a distinguished road
Red face

2D array program


Very often in fairs we come across a puzzle which contains numbered square pieces, which can be
moved horizontally or vertically. A possible arrangement of these pieces is shown below (Hint: This is a
2D integer array!):

1 4 15 7
8 10 2 11
14 3 6 13
12 9 5 ☺

As you can see there is a ☺ at bottom right corner. Implement the program so that a box like the above
one is displayed (lines may not be displayed). Allow the user to hit any of the arrow keys (up, down, left,
or right).
If user hits say, right arrow key then program should give a message that this movement is not possible.
If user hits left arrow key then 5 should move in place of ☺ and ☺ should move in place of 5, and box
will look like:

1 4 15 7
8 10 2 11
14 3 6 13
12 9 ☺ 5

Similarly, you can experience with all arrow keys and movements of ☺ will take place, if possible. The
user would continue hitting the arrow keys till the numbers aren’t sorted in ascending order.


please help me getting solve this problem.
  #2  
Old 11-Jun-2008, 13:55
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 713
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: 2d array program


Here is a start:
CPP / C++ / C Code:
// GameBoard.h

#define ROWS 4
#define COLS 4

class GameBoard
{ public:
    int Board[ROWS][COLS];

    GameBoard();
    ~GameBoard();
    
    void Print();
    bool CanMoveRight();
    bool CanMoveLeft();
    bool CanMoveUp();
    bool CanMoveDown();
    void MoveRight();
    void MoveLeft();
    void MoveUp();
    void MoveDown();
};
CPP / C++ / C Code:
//GameBoard.cpp

#include "GameBoard.h"

GameBoard::GameBoard()
{
  // Initialize board randomly
}

GameBoard::~GameBoard()
{
  // Free any dynamic memory
}

void GameBoard::Print()
{ 
  // Print the board to the screen
}

bool GameBoard::CanMoveRight()
{
  // return true if moving right is legal, otherwise false
}
...
...
  #3  
Old 12-Jun-2008, 05:18
ar31an ar31an is offline
New Member
 
Join Date: May 2008
Posts: 8
ar31an is on a distinguished road

Re: 2d array program


thanks buddy.
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Equation solver RazoR C Programming Language 3 18-May-2008 10:24
Returning a 2 dimensional Array from a function vicky_brsh C++ Forum 1 04-Jan-2008 15:06
Need Help with input files. Efferus C++ Forum 2 24-Nov-2007 17:19
Two-Tier data dissemination code installation problem nidhibansal1984 Computer Software Forum - Linux 6 16-Sep-2007 11:13
Need help deleting the last element in the array headphone69 C++ Forum 2 15-Mar-2006 20:31

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:27.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.