/** * @title: stackDemo.cpp * @date: 2004.07.15 - 9:01 pm * @author: vinnie * @ main file for the class Stack2730 */ #include #include #include #include #include #include #include #include "stack2730.h" using namespace std; /* struct StackStruc { int numStacks; int *size; int *ind; int **stacks; }; */ void videoInit( ) { system("color 4e"); system("cls"); } void videoRestore( ) { system("color 0f"); system("cls"); printf("Thanks for using stackDemo!\n"); } void dosMenu( ) { gotoxy( 21, 3); puts("--==[~~~ \01 Aahhh OXYG3N \01 ~~~]==--\n\n"); puts(" 1. Allocate stacks 6. Top value"); puts(" 2. Push a value 7. Show stacks"); puts(" 3. Pop a value 8. Get stack size"); puts(" 4. Flush a stack 9. Demo"); puts(" 5. is empty? 0. Exit"); printf("________________________________________\ ________________________________________"); puts("Stack 1 "); puts("Stack 2 "); puts("Stack 3 "); printf("________________________________________\ ________________________________________"); gotoxy( 2, 18); } void updateTime( ) { tm *pMyTime; time_t aclock; time( &aclock); pMyTime = localtime( &aclock); gotoxy(1,1); printf( "%s", asctime( pMyTime) ); } void refresh( Stack2730 *p) { for ( int i = 0; i < p->getNumStacks( ); i++) puts( "a"); } void stackDemo() { int len[3] = { 0, 0, 0}; int choice = 6; int index = 3; for ( int i = 0; i < 3; i++) while ( len[i] <40 || len[i] > 78 ) len[i] = rand( ); Stack2730 *aS = new Stack2730( len[2], 3, len); while ( !kbhit() ) { updateTime( ); index = rand( ); choice = rand( ); while ( index > 2 ) index = rand( ); while ( choice > 8 ) choice = rand( ); switch ( choice) { case 1: case 3: if ( !aS->empty( index) ) aS->pop( index); break; case 2: if ( !aS->empty( index) ) aS->flush( index); break; default: if ( aS->room( index) ) aS->push( rand( ), index); } refresh( aS); } getch( ); aS->~Stack2730( ); return; } /* void myChoice( Stack2730 *p, int ind, int iChoice) { } */ main( ) { videoInit(); dosMenu(); stackDemo( ); int msg; MYLOOP: updateTime(); if ( kbhit() ) { msg = getchar(); switch ( msg) { case '1' : // allocate stacks break; case '2' : // push a value break; case '3' : // pop a value break; case '4' : // flush a stack break; case '5' : // isEmpty break; case '6' : // top value break; case '7' : // show stack break; case '8' : // get stack size break; case '9' : // demo stackDemo( ); break; case '0' : // exit goto MYEXIT; } } goto MYLOOP; MYEXIT: videoRestore(); exit( 0); }