MUstar

IoT C++ 09/12 - Project2_stack.cpp

Sep 12th, 2017
232
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<string.h>
  3. #include "stack.h"
  4. using namespace std;
  5.  
  6. Stack::Stack()  
  7. {
  8.     top = 0;
  9. }
  10.  
  11. bool Stack::isempty() const
  12. {
  13.     return top == 0;
  14. }
  15.  
  16. bool Stack::isfull() const
  17. {
  18.    return top == MAX;
  19. }
  20.  
  21. bool Stack::push(const Item & item)
  22. {
  23.     if (top < MAX)
  24.     {
  25.       items[top++] = item;
  26.       return true;
  27.     }
  28.     else
  29.         return false;
  30. }
  31.  
  32. bool Stack::pop(int delnum)
  33. {
  34.     if (top == 1)
  35.     {
  36.         top--;
  37.         return true;
  38.     }
  39.     else if(top>1)
  40.     {
  41.         for(int i=delnum;i<top-1;i++)
  42.         {
  43.             strcpy(items[i].fullname,items[i+1].fullname);
  44.             items[i].payment = items[i+1].payment;
  45.         }
  46.         top--;
  47.         return true;
  48.     }
  49.     else
  50.         return false;
  51. }
  52.  
  53. void Stack::list()
  54. {
  55.     cout<<"|Num/Name/Payment Amount/|"<<endl;
  56.     for(int i=0;i<top;i++)
  57.         cout<<"|"<<i+1<<"/"<<items[i].fullname<<"/"<<items[i].payment<<"|"<<endl;
  58. }
  59.  
  60. void Stack::stack_del(char *name)
  61. {
  62.     customer db;
  63.     int cnt;
  64.     for(int i=0;i<top;i++)
  65.     {
  66.         char *tmp = items[i].fullname;
  67.         if((strcmp(tmp,name))==0)
  68.         {
  69.             Stack::pop(i);
  70.             cnt++;
  71.         }
  72.     }
  73.     if(cnt==0)
  74.     {
  75.         cout<<"고객이름이 리스트가 없습니다."<<endl;
  76.         return;
  77.     }
  78.     else
  79.     {
  80.         cout<<"정상적으로 처리되었습니다."<<endl;
  81.         return;
  82.     }
  83. }
  84.  
  85. int Stack::payment(void)
  86. {
  87.     int amount=0;
  88.     for(int i=0;i<top;i++)
  89.     {
  90.         amount+=items[i].payment;
  91.     }
  92.     top=0;
  93.     return amount;
  94. }
Add Comment
Please, Sign In to add comment