khisby

History Web Simulation 2

Mar 18th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #define maxsize 2
  4. using namespace std;
  5.  
  6. struct history{
  7.     string url;
  8.     string time;
  9. }history[maxsize];
  10. int top=-1;
  11.  
  12. void pop() {
  13.    string data;
  14.    if(top != -1) {
  15.       data = history[top].url;
  16.       top = top - 1;
  17.       cout << "History " << data << " terhapus" << endl;
  18.    } else {
  19.       cout << "History Kosong";
  20.    }
  21.    system("pause");
  22. }
  23.  
  24. void push() {
  25.    if(top != maxsize-1) {
  26.         system("cls");
  27.         top++;
  28.         cout << "Masukkan url : ";
  29.         cin >> history[top].url;
  30.         cout << "Masukkan time : ";
  31.         cin >> history[top].time;
  32.         cout << "Anda mengakses : " << history[top].url << " " << history[top].time << endl;
  33.    } else {
  34.       cout << "History Penuh";
  35.    }
  36.    system("pause");
  37. }
  38.  
  39. int main() {
  40.    int menu;
  41.  
  42.    do{
  43.         system("cls");
  44.         for(int i=top;i>=0;i--){
  45.             cout << history[i].url << " " << history[i].time<<endl;
  46.         }
  47.         cout << endl;
  48.         cout << "1. Buka URL (PUSH)" << endl;
  49.         cout << "2. Hapus URL Terakhir (POP)" << endl;
  50.         cout << "3. keluar" << endl;
  51.         cout << "Masukkan nomor menu : ";
  52.         cin >> menu;
  53.  
  54.         if(menu == 1) {
  55.             push();
  56.         }else if(menu == 2){
  57.             pop();
  58.         }
  59.    }while(menu!=3);
  60.    return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment