473,288 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,288 software developers and data experts.

towers of hanoi

43
I have a pretty tough assignment for beginner like me & i'm seeking help please

here is the assign

In this assignment, you will be guided to complete the program skeleton provided to you in such a way as to allow the user to interactively solve the Tower of Hanoi problem (i.e. Moving n disks from PegA to PegC using PegB as a temporary Peg), without violating the rules of the game namely that:
Only One disk (the top disk on any Peg) can be moved at a time, and,
A disk d can only be placed on top of an empty Peg or on top of a disk D on another Peg if d is smaller than D. Simply stated a larger disk can not be placed on a smaller disk as discussed in class.

An Executable showing how your program should interact with the user (and sample outputs) have also been provided, as well as soft copies of the program skeleton.

The program uses two structures as follows:

struct PegType
{
char name[_NameSize]; // Stores name of the Peg, e.g. pegA
char shortName; // Stores a one character name for the Peg, e.g. 'A'
int disks[_ArraySize]; // initialize to { 1, 2, 3, 4, 5, 6, 7, 8, 9} for full (pegA)
// and to { _NoDisk } (pegB and pegC)
int TopDiskLocation; // Store the location (index)
// of the top most disk
// This should be = towers.size (=n number of disks to move) if no
// disks are there and decremented by 1 each time
// a disk is added until it reaches 0 when all the n disks are on this peg.
int size; // n or number of disks to move (3 to 9 typically)
};

struct ThreePegsType
{
int GraphicsLargestDiskSize; // Maximum width of base of largest disk
// (default use 10);
int Space_Between_Pegs; // default use = 5;
int size; // n or number of disks to move (3 to 9 typically)
PegType pegA;
PegType pegB;
PegType pegC;
};

With this arrangement, a single variable, e.g. towers of type ThreePegsType will have all the structures you need for your program. Remember to make sure you always initialize the values in the structures and pass them by reference to functions so that changes made to them are actually done on the structures and not to copies of the structures.
Finally the main program, the initialization routines and the routine that displays (prints) the three Pegs configuration are provided as a teaching aid and to give you a head start. You may use these or write your own,

Tasks:

The following tasks are detailed in such a way that will allow to test your program at every stage to ensure that it is correct before proceeding to the next task:

1) Study the data structures, the initialization routines and the routine that displays (prints) the three Pegs configuration to make sure you understand how they work. Compile and Run the program skeleton.
2) Write the function:
void addDiskToPeg (int diskNumber, PegType & peg)
that will simply decrement the TopDiskLocation and adds the disk diskNumber at the new top disk location in the array disks--- on the given peg. (At this point no checking is done).
Test your function by adding the following lines to the bottom of your main program:
addDiskToPeg (4, towers.PegB);
printConfig (towers);
and running the program. Experiment with additional tests adding different disk numbers to the Pegs B or C. Notice that our function should not allow a disk to be added if the disk is full. We will fix that next.
Note: Always remember to comment any lines of code that you add for testing after the testing is complete.
3) Write the function:
bool isFull (const PegType & peg)
that will return true if the Peg is full, false otherwise.
You may test it by adding the following lines to your main program:
If (isFull (towers.PegX))
cout << “Peg is full \n”;
else
cout << “Peg is not full \n”;
Change the X to A, then B then C, running it to ensure it is working correctly. Then comment (or delete) the testing code before proceeding to the next task.

4) Now modify your addDiskToPeg (…)function of part 2 to check and display the message "Peg is full … No more disks are allowed\n" if the peg is full. Otherwise it should add the disk as was done in step 2.
Test your function by adding the following lines to your main program:
addDiskToPeg (1, towers.PegA);
addDiskToPeg (1, towers.PegB);
printConfig (towers);

5) Write the function:
bool isEmpty (const PegType & peg)
that will return true if the Peg is empty, false otherwise.
You may test it by adding the following lines to your main program:
If (isEmpty (towers.PegX))
cout << “Peg is empty \n”;
else
cout << “Peg is not empty \n”;
Change the X to A, then B then C, running it to ensure it is working correctly. Then comment (or delete) the testing code before proceeding to the next task.

6) Now write the function:
bool canAddDisk (int diskNumber, const PegType & peg)
that will return true if the peg is empty, or if diskNumber is less (smaller) than the top disk on the peg. Returns false otherwise. You may of course use the isEmpty function written in the previous step.

7) Again, modify your addDiskToPeg (…) function of part 2 to call the canAddDisk ( …) function to also check that diskNumber can be added to peg before actually adding it. Otherwise, it should display the message "Can not add a larger disk on a smaller disk \n".
Test again your function by adding the following lines to your main program:
addDiskToPeg (1, towers.PegB);
printConfig (towers);
addDiskToPeg (2, towers.PegB);
printConfig (towers);
Test and fix your program before proceeding to the next step.

8) Write the function:
int removeDiskFromPeg (PegType & peg)
that removes the top disk from the peg and returns the disk number of the disk removed from the peg. The function should check first: if the peg is empty and display the message "No more disks are available to move\n" and return _NoDisk (i.e. 0); Otherwise it proceeds to removes the top disk from the peg (and replace its value with _NoDisk) It then increments the TopDiskLocation, and returns the disk number of the disk removed.
Test your function by adding the following lines to your main program:
cout << “Disk Removed “ << removeDiskFromPeg (towers.PegA) << endl;
printConfig (towers);
cout << “Disk Removed “ << removeDiskFromPeg (towers.PegA) << endl;
printConfig (towers);
Test and fix your program before proceeding to the next step.

9) Write the function:
void moveOneDisk (PegType & fromPeg, PegType & toPeg)
which removes the top disk from fromPeg and adds it to the toPeg
by completing the following code:
{
if ( ____________) //there are NO disks on the fromPeg to move
____________; //display the message “No disks on disk X to move\n”
//where X will be A, B or C as appropriate.
else
{
int diskToMove = fromPeg.disks[fromPeg.TopDiskLocation]
if (canAddDisk (diskToMove , toPeg))
{ //write here the code that will call the functions to actually
// remove one disk from the fromPeg and adds it to the toPeg
……
…….
};
else
____;//display the message “Move not allowed\n”
}
};
10) Test your previous function by adding the following lines to your main program:
moveOneDisk (towers.PegC, towers.PegB); printConfig (towers);
moveOneDisk (towers.PegA, towers.PegB); printConfig (towers);
moveOneDisk (towers.PegA, towers.PegB); printConfig (towers);
moveOneDisk (towers.PegA, towers.PegB);
printConfig (towers);

Test and fix your program before proceeding to the next step.

11) Now put aline in your main program to call the function:
void InterActive_TOH_Solve (ThreePegsType & towers);
Notice that it is correctly asking for the peg letters but is not performing any moves.
Complete the above function so that it calls the moveOneDisk( …) as per the user inputs
Notice that allowable (legal moves) moves are:
A to B, A to C, B to A, B to C, C to A, and C to B. For All other combinations you should output “Illegal Move”.

12) Finally, notice that if you play and successfully move all the disks from PegA to PegC (or to PegB) the program does not congratulate you on winning and does not stop. That is because the function:
bool gameIsSolved (PegType & peg);
always returns false. Make it return true if all disks are on the given peg

13) Congratulations ! Enjoy playing the game.
Mar 31 '07 #1
51 7360
maloov
43
and here is the un full sekeleton

#include <iostream>
#include <iomanip>

using namespace std;


const int _ArraySize = 12; // size of array that holds the disks (used as a stack)
const int _NameSize = 15; // size of character array that holds the Peg name
const int _NoDisk = 0; // intialize an element of the peg array to 0 to indicate that
// no disk is present, otherwise store a disk number ( 1 smallest
// disk size,9 largest disk size
struct PegType
{
char name[_NameSize]; // Stores name of the Peg, e.g. pegA
char shortName; // Stores a one character name for the Peg, e.g. 'A'
int disks[_ArraySize]; // initialize to { 1, 2, 3, 4, 5, 6, 7, 8, 9} for full (pegA)
// and to { _NoDisk } (pegB and pegC)
int TopDiskLocation; // Store the location (index)
// of the top most disk
// This should be = towers.size (=n number of disks to move) if no disks are there and decremented by 1 each time
// a disk is added until it reaches 0 when all the n disks are on this peg.
int size; // n or number of disks to move (3 to 9 typically)
};

struct ThreePegsType
{
int GraphicsLargestDiskSize; // Maximum width of base of largest disk (default = 10);
int Space_Between_Pegs; // default use = 5;
int size; // n or number of disks to move (3 to 9 typically)
PegType pegA;
PegType pegB;
PegType pegC;
};


void printSpaces(int HowMany)
{
for (int i= 0; i < HowMany; i++)
cout << " ";
}

void printBase(const ThreePegsType & towers)
{
for (int i= 0; i < 2 * towers.GraphicsLargestDiskSize - 1 ; i++)
cout << "=";
printSpaces(towers.Space_Between_Pegs);

for (int j= 0; j < 2 * towers.GraphicsLargestDiskSize - 1 ; j++)
cout << "=";
printSpaces(towers.Space_Between_Pegs);

for (int k= 0; k < 2 * towers.GraphicsLargestDiskSize - 1 ; k++)
cout << "=";
cout << endl;
}


void printPartLine(const PegType & peg, int level, const ThreePegsType & towers) // level is 0 for top line , arraySize for bottom
{
int howManySpaces;
if (peg.disks[level] == _NoDisk) // print one less space for symmetry
{
howManySpaces = 2 * towers.GraphicsLargestDiskSize - 1;
printSpaces(howManySpaces);
}
else
{
howManySpaces = towers.GraphicsLargestDiskSize - peg.disks[level];

printSpaces(howManySpaces);
// print the disk number n, (2*n - 1) times
for (int j= 0; j <2 * peg.disks[level] -1; j++)
cout << peg.disks[level];

printSpaces(howManySpaces);
}

printSpaces(towers.Space_Between_Pegs);
}


void printConfig (const ThreePegsType towers)
{
for (int level = 0; level < towers.size; level++)
{
printPartLine(towers.pegA, level, towers);
printPartLine(towers.pegB, level, towers);
printPartLine(towers.pegC, level, towers);
cout << endl;
}
printBase(towers);
}


// initialize disks to { 1, 2, 3, 4, 5, 6, 7, 8, 9, ...};
void initializeToFull(PegType & peg, int numOfDisks)
{
for (int location = 0; location < numOfDisks; location++)
{
int diskNumber = location + 1;
peg.disks[location] = diskNumber;
}
peg.TopDiskLocation = 0; //peg is full
peg.size = numOfDisks;
}

// initialize disks to { _NoDisk };
void initializeToEmpty(PegType & peg, int numOfDisks)
{
for (int location = 0; location < numOfDisks; location++)
{
peg.disks[location] = _NoDisk;
}
peg.TopDiskLocation = numOfDisks; //peg is empty
peg.size = numOfDisks;
}


char getPegLetter()
{
char diskLetter;
while (true )
{
cin >> diskLetter;
diskLetter = toupper(diskLetter);

if ((diskLetter == 'A') || (diskLetter == 'B') ||
(diskLetter == 'C') || (diskLetter == 'Q'))
return diskLetter;
else cout << "\nPlease ... Type only A, B, C (a, b, c) to play, Q (or q) to stop\n";
}
}

// Change this to return true if all disks are on the Peg
bool gameIsSolved (PegType & peg)
{
return false;
}


void InterActive_TOH_Solve(ThreePegsType & towers)
{
bool continePlaying = true;

while ( continePlaying )
{
cout << "Type A, B, C to play, Q to stop\n";
cout << "Move disk from Peg: ";
char fromPegLetter = getPegLetter();
if (fromPegLetter != 'Q')
{
cout << "\nMove disk from Peg: " << fromPegLetter << " to Peg: ";
char toPegLetter = getPegLetter();
if (toPegLetter != 'Q')
{
//put here the code that calls the appropriate
// .......
// .......
// .......
// .......
// .......
printConfig (towers); // prints the new configuration after the move
}
else continePlaying = false;
}
else continePlaying = false;
if (gameIsSolved (towers.pegB) || gameIsSolved (towers.pegC))
continePlaying = false;
};
}



int main()
{
ThreePegsType towers;
towers.GraphicsLargestDiskSize = 10; // Maximum width of base of largest disk (default = 10);
towers.Space_Between_Pegs = 5; // default use = 5;

towers.size = 0;
while ((towers.size <= 0) || (towers.size > 9))
{
cout << "Enter the number of disks to move .. n ( 1- 9)\n";
cin >> towers.size;
}

// initialize the short names of the pegs to 'A', 'B', and 'C' respectively
towers.pegA.shortName = 'A';
towers.pegB.shortName = 'B';
towers.pegC.shortName = 'C';

// initialize disks[] and the location (index) of the top disk in each peg
initializeToFull(towers.pegA, towers.size); //peg.TopDiskLocation = 0; means peg is full
initializeToEmpty(towers.pegB, towers.size ); // peg.TopDiskLocation = towers.size means peg is empty
initializeToEmpty(towers.pegC, towers.size);

cout << "Pegs --- initial configuration\n\n";
printConfig (towers);

cout << endl;

return 0; // indicates successful termination

} // end main

/* Sample Interactions .. Outputs
Enter the number of disks to move .. n ( 1- 9)
3
Pegs --- initial configuration

PegA PegB PegC

1
222
33333
=================== =================== ===================
Type A, B, C to play, Q to stop
Move disk from Peg: b

Move disk from Peg: b to Peg: a
No disks on Peg: B to move .
Mar 31 '07 #2
maloov
43
It's a real challange cuz i gotta submit it tommorow so expert guys com' on
Mar 31 '07 #3
r035198x
13,262 8TB
It's a real challange cuz i gotta submit it tommorow so expert guys com' on
There is some big piece missing here. Where is the code that you have written? See guidelines.
Mar 31 '07 #4
JosAH
11,448 Expert 8TB
It's a real challange cuz i gotta submit it tommorow so expert guys com' on
Maybe this assignment is a lesson in better time management too. If I were
you I'd start designing and coding asap.

kind regards,

Jos
Mar 31 '07 #5
maloov
43
hey Josh

i'm really workin hard even now, but every body should help if he can.
Mar 31 '07 #6
r035198x
13,262 8TB
hey Josh

i'm really workin hard even now, but every body should help if he can.
I hope you read the guidelines link that I posted. We all want to help. But we want to make sure you are doing most of the coding.
Mar 31 '07 #7
JosAH
11,448 Expert 8TB
hey Josh

i'm really workin hard even now, but every body should help if he can.
*should help*? Normally I'd like to help people out but for one thing: it's not
my moral obligation to do so; or you must be talking decent hourly rate money;
it'll be quite a different story then; a story that doesn't belong on a forum such
as this one though where volunteers help people out on a voluntary basis.

kind regards,

Jos
Mar 31 '07 #8
maloov
43
so be sure
Mar 31 '07 #9
r035198x
13,262 8TB
so be sure
We can only be sure if you ask a more specific question or you show us the code you've written.
Mar 31 '07 #10
maloov
43
ok


// Change this to return true if all disks are on the Peg

do i made this

bool gameIsSolved (PegType & peg)
{
if (peg.TopDiskLocation = 0) return false;
}


also i need to know what is the code that call the appropriate
after the ???

void InterActive_TOH_Solve(ThreePegsType & towers)
{
bool continePlaying = true;

while ( continePlaying )
{
cout << "Type A, B, C to play, Q to stop\n";
cout << "Move disk from Peg: ";
char fromPegLetter = getPegLetter();
if (fromPegLetter != 'Q')
{
cout << "\nMove disk from Peg: " << fromPegLetter << " to Peg: ";
char toPegLetter = getPegLetter();
if (toPegLetter != 'Q')
{
//?? the code that calls the appropriate
// .......
// .......
// .......
// .......
// .......


printConfig (towers); // prints the new configuration after the move
}
else continePlaying = false;
}
else continePlaying = false;
if (gameIsSolved (towers.pegB) || gameIsSolved (towers.pegC))
continePlaying = false;
};
}
Mar 31 '07 #11
Savage
1,764 Expert 1GB
You need to findout is the move allowed.

To be allowed it must be on top of first tower.If it's allowed move disk to
temporary tower.To move disk to temporary tower u need to first delete disk from first tower.To this you must search disks array and lower the no.of elements by one and move the last element to the place of element just deleted.
Then you must sort again ur array.To move to temp.tower you must increase
no.of elements and add like last element.To move to third tower last element of
temp.array must become first element of third tower and so on.


Savage
Mar 31 '07 #12
maloov
43
thanx savage
Mar 31 '07 #13
Savage
1,764 Expert 1GB
thanx savage

Allways a pleasure.....

And if you get stucked just post and somone will answer u.

Savage
Mar 31 '07 #14
maloov
43
oh the time is over ....

come on let any one solve it so i can understand it

cuz the lab assistant won't solve it ..

she just graded for those who submitted it.

come on i wanna learn..
Apr 1 '07 #15
maloov
43
it's so complecated with lots of variables & functions

i had headache come on i need help

i'm sure it will appear in the exam
Apr 1 '07 #16
Savage
1,764 Expert 1GB
it's so complecated with lots of variables & functions

i had headache come on i need help

i'm sure it will appear in the exam
Where did you get stucked??

Savage
Apr 1 '07 #17
maloov
43
Savage the time is over so ,i wanna the solution with full explanation.
Apr 1 '07 #18
Savage
1,764 Expert 1GB
Savage the time is over so ,i wanna the solution with full explanation.
I'm so sorry but we are not allowed to give a full code.

(See posting guidelines)
Apr 1 '07 #19
maloov
43
well give me part each time..

i'm not kidding i need to learn..
Apr 1 '07 #20
Savage
1,764 Expert 1GB
well give me part each time..

i'm not kidding i need to learn..
I can only give you a pseudo code in which I have solved problem using recursion:

Expand|Select|Wrap|Line Numbers
  1. void moveadisk(int from,int temp,int to,int disknum)
  2. {
  3.  
  4.  here goes condition when recursion is finished,so for this prob it should be 
  5.  finished if disknum is 0.
  6.  it should be like:
  7.  if(diskmun>0).
  8.  If it is call a finction but instead of disknum use disknum-1
  9.  output which disk is being reallocated and delay.After delay call again function
  10.  with disknum-1.
  11.  
  12. }
Apr 1 '07 #21
maloov
43
yeah that's fine and usefull keep on doing that please

and thanx alot
Apr 1 '07 #22
Savage
1,764 Expert 1GB
yeah that's fine and usefull keep on doing that please

and thanx alot
Well,there are only 2 things now left.Both of them are meant to be made inside main().

FIRST:

Ask user to select disk which will be passed to moveadisk.

Disk which is only allowed is at top of first tower and it size is smallest:

tower1[elementsnum] if this is aray which hould disks from the first tower then you have to search it's first(or last element in depandance of how did you populated that array).Here is the pseudocode:

Expand|Select|Wrap|Line Numbers
  1. get user input;
test it against array and confirm that user input is alocated on top of first tower.

Expand|Select|Wrap|Line Numbers
  1. if(tower[0]==userinput) proceed
  2. else print on output that disk can't be moved.
After this you need to lower num of elements and pull out from array user input.To this with for loop:

Expand|Select|Wrap|Line Numbers
  1. for(i=0;i<elementsnum-1;i++) tower1[i]=tower[i+1]
When you have done this post again!!!

Savage
Apr 1 '07 #23
maloov
43
well here what i did but i'm stocked somewhere

see what's written in bold

[code]
void moveOneDisk (PegType & fromPeg, PegType & toPeg)
{
if (peg.TopDiskLocation>0) peg.topDiskLocaion--;

if ( peg.TopDiskLocation=0) //there are NO disks on the fromPeg to move
cout<<"No disks on disk X to move\n"; //displays the message "No disks on disk X to move\n"
//where X will be A, B or C as appropriate.
else
{
int diskToMove = fromPeg.disks[fromPeg.TopDiskLocation]
if (canAddDisk (diskToMove , toPeg))
{ // the code that will call the functions to actually
// remove one disk from the fromPeg and adds it to the toPeg
……
…….
};
else
cout<<"Move not allowed\n";
}
};
Apr 1 '07 #24
maloov
43
do u know what is the biggest problem here

that the variables and function name's are declared by the question and not by

me, that's what causes confused
Apr 1 '07 #25
Savage
1,764 Expert 1GB
[code]
well here what i did but i'm stocked somewhere

see what's written in bold

[code]
void moveOneDisk (PegType & fromPeg, PegType & toPeg)
{
if (peg.TopDiskLocation>0) peg.topDiskLocaion--;

if ( peg.TopDiskLocation=0) //there are NO disks on the fromPeg to move
cout<<"No disks on disk X to move\n"; //displays the message "No disks on disk X to move\n"
//where X will be A, B or C as appropriate.
else
{
int diskToMove = fromPeg.disks[fromPeg.TopDiskLocation]
if (canAddDisk (diskToMove , toPeg))
{ // the code that will call the functions to actually
// remove one disk from the fromPeg and adds it to the toPeg
……
…….
};
else
cout<<"Move not allowed\n";
}
};
Well this will remove a disk from first tower:

Expand|Select|Wrap|Line Numbers
  1. for(i=0;i<elementsnum-1;i++) tower1[i]=tower[i+1];
to move it to temp tower simple increase num of elements and add it like last ellement.There is no reson for any statment because you are doing it by the first tower.

Look:

tower2[elements] ;
on start of the game elements is zero becasue there is no disk moved to secound tower.When first disk is moved,elements should reamain 0 becasue
first element of tower2 has index zero.

So this is it:

Expand|Select|Wrap|Line Numbers
  1. if(k==0) elements=0;
\\k is indicator which shows us how much times did user
\\ moved a disk..
Expand|Select|Wrap|Line Numbers
  1. else k++,elements++;

savage
Apr 1 '07 #26
maloov
43
i do understand what i'm supposed to do but

when i come to apply i feel lost
Apr 1 '07 #27
Savage
1,764 Expert 1GB
do u know what is the biggest problem here

that the variables and function name's are declared by the question and not by

me, that's what causes confused
That's so retarded.Are you allowed to change it to another name if you give it a apropiate description?
Apr 1 '07 #28
maloov
43
i wish i can but you know what

bacause you have the original question

i would ask you ashamed if you can explain it with the variables declared in

the question??
Apr 1 '07 #29
maloov
43
aren't the pvt messages allows more freedom??

i mean if it is not allowed to put codes or some thing like

although i want others to get benefit from the solution
Apr 1 '07 #30
maloov
43
oh lot's of errors have ocured while trying to execute and it's

all because of declaration deferents....

that's really letdown
Apr 1 '07 #31
Savage
1,764 Expert 1GB
i wish i can but you know what

bacause you have the original question

i would ask you ashamed if you can explain it with the variables declared in

the question??
That's a lot to work.Anyway,I'm not sure that I will get it right because there is just to much functions and qeustions to explain.i'm afraid that i will lost my
self in that bunch.Maybe if you can isolate parts of assigmnet which you don't
understand from others.it also may help if you use code tags(#).

Yes,they offer more freedom,but i think that's unfer to other OP's which may post same qesution(Lot of people here posts same qeustions).

Savage
Apr 1 '07 #32
maloov
43
ur awesome dude

and sorry if i'm losing ur time

i will write the parts i feel that i'm stuck in

first look at the words in bold
Expand|Select|Wrap|Line Numbers
  1. void InterActive_TOH_Solve(ThreePegsType & towers)
  2. {
  3.     bool continePlaying = true;
  4.     int Peg[10];
  5.     while ( continePlaying )
  6.     {
  7.         cout << "Type A, B, C to play, Q to stop\n";
  8.         cout << "Move disk from Peg:  ";
  9.         char fromPegLetter = getPegLetter();
  10.         if (fromPegLetter != 'Q')
  11.         {
  12.             cout << "\nMove disk from Peg: " << fromPegLetter << " to Peg: ";
  13.             char toPegLetter = getPegLetter();
  14.             if (toPegLetter != 'Q')
  15.             {
  16.               //here should be the code that calls
  17. // the appropriate                // .......
  18.               // .......
  19.               // .......
  20.               // .......
  21.               // .......
  22.  
  23.  
  24.  
  25.  
  26.                printConfig (towers); // prints the new configuration after the move
  27.             }
  28.             else continePlaying = false;
  29.         }
  30.             else continePlaying = false;
  31.         if (gameIsSolved (towers.pegB) || gameIsSolved (towers.pegC))
  32.             continePlaying = false;
  33.     };
  34.  
Apr 1 '07 #33
maloov
43
well it didn't appears it Bold but i meant the

comments after

Expand|Select|Wrap|Line Numbers
  1.  if (toPegLetter != 'Q')
  2.  
Apr 1 '07 #34
Savage
1,764 Expert 1GB
ur awesome dude

and sorry if i'm losing ur time

i will write the parts i feel that i'm stuck in

first look at the words in bold
Expand|Select|Wrap|Line Numbers
  1. void InterActive_TOH_Solve(ThreePegsType & towers)
  2. {
  3.     bool continePlaying = true;
  4.                 int Peg[10];
  5.     while ( continePlaying )
  6.     {
  7.         cout << "Type A, B, C to play, Q to stop\n";
  8.         cout << "Move disk from Peg:  ";
  9.         char fromPegLetter = getPegLetter();
  10.         if (fromPegLetter != 'Q')
  11.         {
  12.             cout << "\nMove disk from Peg: " << fromPegLetter << " to Peg: ";
  13.             char toPegLetter = getPegLetter();
  14.             if (toPegLetter != 'Q')
  15.             {
  16.               //here should be the code that calls
  17. // the appropriate                // .......
  18.               // .......
  19.               // .......
  20.               // .......
  21.               // .......
  22.  
  23.  
  24.  
  25.  
  26.                printConfig (towers); // prints the new configuration after the move
  27.             }
  28.             else continePlaying = false;
  29.         }
  30.             else continePlaying = false;
  31.         if (gameIsSolved (towers.pegB) || gameIsSolved (towers.pegC))
  32.             continePlaying = false;
  33.     };
  34.  
It has appeard in bold.You need to find out user input.It should be:

Expand|Select|Wrap|Line Numbers
  1.             if (toPegLetter != 'Q')
  2.             {
  3.                                                            //Findout user input
  4.  
  5.                                                           if(toPegLetter =='A') 
  6.                                                           {
  7.                                                                 addDiskToPeg (1,towers.pegA);
  8.  
  9.                                                           }else{  if(toPegLetter=='B')
  10.                                                                     {
  11.                                                                       addDiskToPeg(1,towers.pegB);
  12.  
  13.                                                                     }else addDiskToPeg(1,tw.pegC);
  14.                                                                  }
Apr 1 '07 #35
JosAH
11,448 Expert 8TB
I never knew deadlines for school assignments expired on Sundays?

kind regards,

Jos
Apr 1 '07 #36
Savage
1,764 Expert 1GB
I never knew deadlines for school assignments expired on Sundays?

kind regards,

Jos
Maybe,he is in new time zone +24,so right now it's a Monday?

(Just kiding,it's good for health!!!)

Savage
Apr 1 '07 #37
JosAH
11,448 Expert 8TB
Maybe,he is in new time zone +24,so right now it's a Monday?

(Just kiding,it's good for health!!!)

Savage
Quick! Ask him what the Nasdaq, Dow Jones and the Nikei are doing!

kind regards,

Jos ;-)
Apr 1 '07 #38
Savage
1,764 Expert 1GB
Quick! Ask him what the Nasdaq, Dow Jones and the Nikei are doing!

kind regards,

Jos ;-)
Nah,he is already gone?

May,I ask you one question:

Do you know to programm in FORTRAN?

Savage
Apr 1 '07 #39
JosAH
11,448 Expert 8TB
May,I ask you one question:

Do you know to programm in FORTRAN?

Savage
Does it show? I programmed in Fortran/77 and Fortran/IV ages ago and
hopefully I have forgotten all about it.

kind regards,

Jos
Apr 1 '07 #40
Savage
1,764 Expert 1GB
Does it show? I programmed in Fortran/77 and Fortran/IV ages ago and
hopefully I have forgotten all about it.

kind regards,

Jos

Waohoohoh,you are a VETERAN ! ! ! ! ! !

:-)

Savage
Apr 1 '07 #41
JosAH
11,448 Expert 8TB
Waohoohoh,you are a VETERAN ! ! ! ! ! !

:-)

Savage
I programmed in about every possible mumbo-jumbo dialect invented in this
valley of tears, and Fortran isn't that bad ;-) Cobol and RPG/2still make me
wake up sweating in the middle of the night sometimes but I've got medicines
against that ;-)

kind regards,

Jos
Apr 1 '07 #42
NeoPa
32,554 Expert Mod 16PB
Nice work Jos.
RPG2 - That was never what you could call fun was it ;)
It made you WANT to take up Assembler.
Apr 2 '07 #43
r035198x
13,262 8TB
Nice work Jos.
RPG2 - That was never what you could call fun was it ;)
It made you WANT to take up Assembler.
Hey, what are you doing in the C++ forum?
Finally decided to try a real programming language?
Apr 2 '07 #44
JosAH
11,448 Expert 8TB
Nice work Jos.
RPG2 - That was never what you could call fun was it ;)
It made you WANT to take up Assembler.
Yep, RPG2 made me almost cross-eyed with all those flags on the left and
right side of the pages, *yuck* another one of IBMs mistakes ;-)

kind regards,

Jos
Apr 2 '07 #45
NeoPa
32,554 Expert Mod 16PB
Hey, what are you doing in the C++ forum?
Finally decided to try a real programming language?
I think I would have loved C++. I certainly enjoyed C when I used it (Mid- to late- Eighties.) But I guess you should know why I'm here - as you posted the recommendation thread I was following up on (Appologies to others for oblique reference to a thread in the Experts/Mods forum).
Yep, RPG2 made me almost cross-eyed with all those flags on the left and
right side of the pages, *yuck* another one of IBMs mistakes ;-)

kind regards,

Jos
Yes - very strange it was. It was in keeping with the thinking at the time though. Most things mainframe worked on checking boxes etc. Even Cix was not ready then, as one of the earlier interactive systems. But we could go on about such esoterics for hours, and bore those lucky enough not to have been involved :D
Apr 2 '07 #46
JosAH
11,448 Expert 8TB
Yes - very strange it was. It was in keeping with the thinking at the time though. Most things mainframe worked on checking boxes etc. Even Cix was not ready then, as one of the earlier interactive systems. But we could go on about such esoterics for hours, and bore those lucky enough not to have been involved :D
True; so I'm not going to tell about all the happiness and utmost joy when I
dropped a couple of thousand punched cards on the stairs while running down
to the card reader ;-)

kind regards,

Jos
Apr 2 '07 #47
NeoPa
32,554 Expert Mod 16PB
Lol - You'd need a computer to get them back into the right order :D
I remember in my first job (1979) I followed instructions and wrote my first program (RPG2) on the big sheet for the punch-card 'ladies' to punch up. When I went to do my second one, I found the wait so long, I just edited the first one while I was twiddling my thumbs (We had ICL Cix (or was it CICS - I forget) then, which was interactive) and saved it as the new one. The rest of the department started off shocked, then they all followed suit. I'm afraid the 'ladies' were a bit upset (I was only 19 at the time so hadn't foreseen any adverse side-effects).

-Ade.
Apr 2 '07 #48
JosAH
11,448 Expert 8TB
Lol - You'd need a computer to get them back into the right order :D
I remember in my first job (1979) I followed instructions and wrote my first program (RPG2) on the big sheet for the punch-card 'ladies' to punch up. When I went to do my second one, I found the wait so long, I just edited the first one while I was twiddling my thumbs (We had ICL Cix (or was it CICS - I forget) then, which was interactive) and saved it as the new one. The rest of the department started off shocked, then they all followed suit. I'm afraid the 'ladies' were a bit upset (I was only 19 at the time so hadn't foreseen any adverse side-effects).

-Ade.
It's "CICS" *shudder*, just the memories ;-) And indeed a huge stack of
punched cards gave a whole new meaning to "reusability" especially the
DO I ... and CONTINUE cards were great. I must confess that I've ruined
quite a bit of trees despite the reused cards.

You were lucky to have "ladies" for the typing, I sat in front of those darn
IBM/29s for hours and hours myself ;-)

kind regards,

Jos
Apr 2 '07 #49
maloov
43
wow it have been a general discussion here.

Joash my school requires us to send the assignment via email in our weekend

so don't wonder. every thing possible.

and .. yeah I respect your experience though u were makin fun of me ;)
Apr 2 '07 #50

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Sonia | last post by:
Hi, I have written this code for the Tower of Hanoi problem. I was just wondering if there is any way of optimizing this code ? It's a failry simple code, but I thought that maybe somehow it...
8
by: Constant | last post by:
I need a programe that will deal with the solving of the problem ..i have 3 pegs A, B, C...and I want to move the disk A to disk C using B as auxiliary.At the end all disk should be at peg C in the...
7
by: ashishnh33 | last post by:
hi.......is there nyone to tell me how to solve the "tower of hanoi" problems
3
by: kamvisiouma | last post by:
Hi there, I'm fresh in learning c++ and I have to solve an exercise with hanoi and my problem is that I'm running out of time! The exercise is this, and I have to complete the ??? ...
3
by: shaghayeghcute2003 | last post by:
I'm currently trying to write The Tower Of Hanoi (http:// illuminations.nctm.org/ActivityDetail.aspx?ID=40) in C#. I have a panel on the form and I draw pegs on the panel inside the form class. I...
6
by: poopsy | last post by:
hi guys cud some1 explain to me the towers of hanoi code, the source code is available evrywhr. i've been trying to understand it bt cant. can some1 plz help me i hav even tried to "trace" it but i...
1
by: schoenfeld.one | last post by:
In this article we show that "top-down" controlled demolition accurately accounts for the collapse times of the World Trade Center towers. A top-down controlled demolition can be simply...
5
by: seemanikam | last post by:
Can anyone suggest me how to devise an efficient divide-and-conquer algorithm for the Tower-of-Hanoi problem when the disks are colored alternately red and blue, and with the extra rule that no disk...
2
by: sunyboy | last post by:
hi I need a programe "Towers of Hanoi without use recessive function" in c++ Please help. Thanks for your time.
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.