Advertisement
khisby

History Web Simulation

Mar 17th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1.  #include <iostream>
  2. #include <stdlib.h>
  3. #define maxsize 10
  4. using namespace std;
  5.  
  6. struct history{
  7.     string url;
  8.     string time;
  9. }history[maxsize];
  10. int top = -1;
  11.  
  12. int isempty() {
  13.    if(top == -1)
  14.       return 1;
  15.    else
  16.       return 0;
  17. }
  18.  
  19. int isfull() {
  20.    if(top == maxsize)
  21.       return 1;
  22.    else
  23.       return 0;
  24. }
  25.  
  26. void pop() {
  27.    string data;
  28.    if(!isempty()) {
  29.       data = history[top].url;
  30.       top = top - 1;
  31.       cout << "Data " << data;
  32.    } else {
  33.       cout << "data penuh";
  34.    }
  35. }
  36.  
  37. void push(string url, string time) {
  38.  
  39.    if(!isfull()) {
  40.       top = top + 1;
  41.       history[top].url = url;
  42.       history[top].time = time;
  43.       cout << "Anda telah mengakses : " << url << " " << time;
  44.    } else {
  45.       cout << "data penuh";
  46.    }
  47. }
  48.  
  49. int main() {
  50.    int menu;
  51.  
  52.    do{
  53.         system("cls");
  54.         for(int i=0;i<top;i++){
  55.             cout << history[i].url << " " << history[i].time<<endl;
  56.         }
  57.         cout << endl;
  58.         cout << "1. push" << endl;
  59.         cout << "2. pop" << endl;
  60.         cout << "3. keluar" << endl;
  61.         cout << "masukkan menu : ";
  62.         cin >> menu;
  63.  
  64.         if(menu == 1) {
  65.             string url,time;
  66.             system("cls");
  67.             cout << "masukkan url : ";
  68.             cin >> url;
  69.             cout << "masukkan time : ";
  70.             cin >> time;
  71.             push(url,time);
  72.             cout << endl;
  73.             system("pause");
  74.         }else if(menu == 2){
  75.             pop();
  76.         }
  77.    }while(menu!=3);
  78.    return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement