Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #define MAX 5
- using namespace std;
- struct Kartu {
- int angka;
- string jenis[MAX];
- }K;
- void entri(){
- K.angka = -1;
- }
- bool isEmpty() {
- return K.angka == -1;
- }
- bool isFull() {
- return K.angka == MAX-1;
- }
- void push() {
- if (isFull()) {
- cout<< "============================"<<endl;
- cout << "\nTumpukan penuh"<<endl;
- cout<< "============================"<<endl;
- }
- else {
- K.angka++;
- cout<< "==========================================="<<endl;
- cout << "\nMasukkan Angka Dan Jenis Kartu = "; cin.sync();getline(cin,K.jenis[K.angka]);
- cout << "Kartu " << K.jenis[K.angka] << " Masuk Ke Tumpukan Kartu"<<endl;
- cout<< "==========================================="<<endl;
- }
- }
- void pop() {
- if (isEmpty()) {
- cout<< "==========================================="<<endl;
- cout << "\nKartu Kosong\n"<<endl;
- cout<< "==========================================="<<endl;
- }
- else {
- cout<< "==========================================="<<endl;
- cout << "\nKartu "<<K.jenis[K.angka]<<endl;
- cout<< "==========================================="<<endl;
- K.angka--;
- }
- }
- void printKartu() {
- if (isEmpty()) {
- cout<< "==========================================="<<endl;
- cout << "Tumpukan Kartu Masih Kosong"<<endl;
- cout<< "==========================================="<<endl;
- }
- else {
- cout<< "==========================================="<<endl;
- for (int x = K.angka; x >= 0; x--)
- cout << "\nTumpukan Kartu ["<<x<<"]= "<< K.jenis[x] << ((x == 0) ? "" : " ");
- }
- }
- int main() {
- int pilihan, jenis;
- entri();
- cout<< "Nama Kelompok : 1. Feriyan Yusuf Arianto (06849)\n";
- cout<< "\t\t 2. Dion Rozin Kurnia Furqon (06859) \n"<<endl;
- do {
- printKartu();
- cout<<endl;
- cout << "\n1. Buka Kartu (Pop)\n";
- cout<<"2. Entri Kartu (push)\n";
- cout<<"3. Keluar\n";
- cout<<" Pilih Menu : ";
- cin >> pilihan;
- switch (pilihan)
- {
- case 1:
- pop();
- break;
- case 2:
- push();
- break;
- default:
- cout << "EXIT" << endl;
- break;
- }
- } while (pilihan!=3);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement