Advertisement
kokokozhina

oop

Sep 19th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <set>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. class Time_point{
  9. public:
  10.     string date, time;
  11.     Time_point(string Date, string Time){
  12.         date = Date;
  13.         time = Time;
  14.     }
  15.     ~Time_point(){
  16.         date.clear();
  17.         time.clear();
  18.     }
  19. };
  20.  
  21. class My_list{
  22. public:
  23.     Time_point* cur;
  24.     My_list* next;
  25.     void set(My_list* cur){
  26.         My_list* p = this;
  27.         while(p->next)
  28.             p = p->next;
  29.         p->next = cur;
  30.     }
  31.     void get(string date, string time){
  32.         My_list* p = this;
  33.         while(p){
  34.             if(p->cur->date == date && p->cur->time == time){
  35.                 cout << "found\n";
  36.                 return;
  37.             }
  38.             else
  39.                p = p->next;
  40.         }
  41.         cout << "non-found\n";
  42.     }
  43.     void erase();
  44.     void isEmpty(){
  45.         if(!this)
  46.             cout << "empty\n";
  47.         else
  48.             cout << "non-empty\n";
  49.     }//?
  50.     void print(){
  51.         My_list* p = this;
  52.         while(p){
  53.             cout << p->cur->date << " " << p->cur->time << endl;
  54.             p = p->next;
  55.         }
  56.     }
  57.     My_list(Time_point* Cur){
  58.         cur = Cur;
  59.         next = NULL;
  60.     }
  61.     ~My_list(){
  62.         while(next != NULL){
  63.             delete next->cur;
  64.             delete next;
  65.         }
  66.     } //?
  67. };
  68.  //correct date-time
  69. int main(){
  70.     int n; cin >> n;
  71.     My_list *head = NULL;
  72.     head->isEmpty();
  73.     if(n--){
  74.         string date, time;
  75.         cin >> date >> time;
  76.         head = new My_list(new Time_point(date, time));
  77.     }
  78.     //head->print();
  79.     head->isEmpty();
  80.     for(int i = 0; i < n; i++){
  81.         string date, time;
  82.         cin >> date >> time;
  83.         My_list* new_element = new My_list(new Time_point(date, time));
  84.         head->set(new_element);
  85.     }
  86.     head->print();
  87.     head->isEmpty();
  88.    
  89.     system("pause");
  90.     return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement