Advertisement
feriyan8

Stack Kartu

Mar 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #define MAX 5
  4.  
  5. using namespace std;
  6.  
  7. struct Kartu {
  8.     int angka;
  9.     string jenis[MAX];
  10. }K;
  11.  
  12. void entri(){
  13.     K.angka = -1;
  14. }
  15.  
  16. bool isEmpty() {
  17.   return K.angka == -1;
  18. }
  19.  
  20. bool isFull() {
  21.     return K.angka == MAX-1;
  22. }
  23.  
  24. void push() {
  25.    if (isFull()) {
  26.         cout<< "============================"<<endl;
  27.         cout << "\nTumpukan penuh"<<endl;
  28.         cout<< "============================"<<endl;
  29.     }
  30.     else {
  31.     K.angka++;
  32.     cout<< "==========================================="<<endl;
  33.     cout << "\nMasukkan Angka Dan Jenis Kartu = "; cin.sync();getline(cin,K.jenis[K.angka]);
  34.     cout << "Kartu " << K.jenis[K.angka] << " Masuk Ke Tumpukan Kartu"<<endl;
  35.     cout<< "==========================================="<<endl;
  36.     }
  37. }
  38.  
  39. void pop() {
  40.     if (isEmpty()) {
  41.         cout<< "==========================================="<<endl;
  42.         cout << "\nKartu Kosong\n"<<endl;
  43.         cout<< "==========================================="<<endl;
  44.     }
  45.     else {
  46.     cout<< "==========================================="<<endl;
  47.     cout << "\nKartu "<<K.jenis[K.angka]<<endl;
  48.     cout<< "==========================================="<<endl;
  49.     K.angka--;
  50.     }
  51. }
  52.  
  53. void printKartu() {
  54.     if (isEmpty()) {
  55.         cout<< "==========================================="<<endl;
  56.         cout << "Tumpukan Kartu Masih Kosong"<<endl;
  57.         cout<< "==========================================="<<endl;
  58.     }
  59.     else {
  60.     cout<< "==========================================="<<endl;
  61.         for (int x = K.angka; x >= 0; x--)
  62.             cout << "\nTumpukan Kartu ["<<x<<"]= "<< K.jenis[x] << ((x == 0) ? "" : " ");
  63.  
  64.     }
  65. }
  66.  
  67. int main() {
  68.     int pilihan, jenis;
  69.     entri();
  70.     cout<< "Nama Kelompok :  1. Feriyan Yusuf Arianto (06849)\n";
  71.     cout<< "\t\t 2. Dion Rozin Kurnia Furqon (06859) \n"<<endl;
  72.     do {
  73.     printKartu();
  74.     cout<<endl;
  75.         cout << "\n1. Buka Kartu (Pop)\n";
  76.         cout<<"2. Entri Kartu (push)\n";
  77.         cout<<"3. Keluar\n";
  78.         cout<<" Pilih Menu : ";
  79.         cin >> pilihan;
  80.         switch (pilihan)
  81.         {
  82.         case 1:
  83.             pop();
  84.             break;
  85.         case 2:
  86.             push();
  87.             break;
  88.         default:
  89.       cout << "EXIT" << endl;
  90.             break;
  91.         }
  92.     } while (pilihan!=3);
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement