daily pastebin goal
16%
SHARE
TWEET

Task_21.3_new2

a guest Mar 21st, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <list>
  3. #include <string>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     list<double> array;
  10.     vector<list<double>::iterator> oper;
  11.     int command, operation=0;
  12.     cout << "Print command: \n"
  13. //         << "1 - if you want to enter number\n"
  14. //         << "2 - if you want to delete number\n"
  15.          << "3 - if you want to enter number to the end\n"
  16.          << "4 - if you want to delete number from X operation\n"
  17.          << "5 - if you want to print array\n"
  18.          << "0 - if you want to finish program\n";
  19.     cin >> command;
  20.     while(command!=0){
  21.         if(command==3) {
  22.             double num;
  23.             int x=0;
  24.             cout << "Enter number you want to push\n";
  25.             cin >> num;
  26.             array.push_back(num);
  27.             /*auto it = array.begin();
  28.             while(it!=array.end()){
  29.                 ++x;
  30.                 ++it;
  31.             }
  32.             oper.resize(oper.size()+1);*/
  33.             oper.push_back(--array.end());
  34.             ++operation;
  35.         }
  36.         else if(command==4){
  37.             int X;
  38.             cout << "Enter X\n";
  39.             cin >> X;
  40.             auto it = --array.begin();
  41.             if(X>=oper.size()){
  42.                 cout << "ERROR\n";
  43.             }
  44.             else if(oper[X]!=it){
  45.                 array.erase(oper[X]);
  46.                 oper.push_back(--array.begin());
  47.                 ++operation;
  48.             }
  49.             else if(oper[X]==it){
  50.                 cout << "ERROR\n";
  51.             }
  52.         }
  53.         else{
  54.             for(auto c:array){
  55.                 cout << c << " ";
  56.             }
  57.             cout << "\n";
  58.             oper.push_back(--array.begin());
  59.             ++operation;
  60.         }
  61.         cout << "Print command: \n"
  62.                 << "3 - if you want to enter number to the end\n"
  63.                 << "4 - if you want to delete number from X operation\n"
  64.                 << "5 - if you want to print array\n"
  65.                 << "0 - if you want to finish program\n";
  66.         cin >> command;
  67.     }
  68.     return 0;
  69. }
RAW Paste Data
Top