Menu

Monday 29 April 2013

Contoh Program Struct C++

Alhamdulillah sobat bisa posting buat share ke sesama. Postingan kali ini berkaitan tentang pemerograman dengan menggunakan C++, mungkin yg belum tau akan pusing, tapi kalo udah tau Insya Allah paham. 


Postingan kali membahas listing kode tentang stuck

#include
#include
#include
void main()
{

int stack [10];
int top=-1;
int pilih,i;

do
{
   gotoxy(25,2);cout<<"=========MENU PILIHAN========="<
   gotoxy(25,4);cout<<"=============================="<
   gotoxy(30,6);cout<<"1. PUSH"<
   gotoxy(30,7);cout<<"2. POP"<
   gotoxy(30,8);cout<<"3. VIEW"<
   gotoxy(30,9);cout<<"4. EXIT"<
   gotoxy(30,11);cout<<"=============================="<

   gotoxy(25,12);printf("pilih= ");
   scanf("%d",&pilih);
   switch(pilih)
    {
      case1://push
      clrscr();
      if(top>10)
      printf("Stack Penuh!\n");
      else
      {
      scanf("%d",&stack[top+1]);
      top++;
      }
      break;

      case2://pop
      clrscr();
      if(top<0 div="">
      printf("Stack Kosong!\n");
      else
      {
         printf("Data Keluar =%d\n",stack[top]);
         top--;
         }
      break;

      case3://view
      cout<<"\n\n data yang ada pada STACK: ";

      {
         for(i=top;i>=0;i--)
         printf("%d",stack[i]);
         printf("\n");
         }
      break;

      case4:
      printf("Exit.....\n");
      break;
      }

      }while (pilih!=4);
      }





0 comments: