hpnq

XUYNA

Oct 12th, 2024
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.68 KB | None | 0 0
  1. //
  2. // Created by User on 10/12/2024.
  3. //
  4. #import "TIntName.h"
  5. #import "TDoubleName.h"
  6.  
  7. #ifndef UNTITLED3_CONTAINER_H
  8. #define UNTITLED3_CONTAINER_H
  9.  
  10.  
  11. class Container {
  12.     TString **arr;
  13.     int n;
  14. public:
  15.     Container():arr(nullptr), n(0){}
  16.  
  17.     Container(bool st){
  18.         if(st){
  19.             cin >> this->n;
  20.             arr = new TString *[this->n];
  21.             for(int i = 0; i < this->n; i++){
  22.                 string s;
  23.                 string name;
  24.                 cin >> s >> name;
  25.  
  26.                 if(s == "idInt"){
  27.                     int q;
  28.                     cin >> q;
  29.                     arr[i] = new TIntName(name.c_str(), q);
  30.  
  31.                 }else if(s == "idDouble"){
  32.                     double q;
  33.                     cin >> q;
  34.                     arr[i] = new TDoubleName(name.c_str(), q);
  35.                 }
  36.             }
  37.         }else{
  38.             Container();
  39.         }
  40.     }
  41.     ~Container(){
  42.         for(int i = 0; i < this->n; i++){
  43.             delete arr[i];
  44.         }
  45.         delete[]arr;
  46.     }
  47.     //3
  48.     void printData(){
  49.         for(int i = 0; i < this->n; i++){
  50.             arr[i]->printWithLength();
  51.         }
  52.     }
  53.     //4
  54.     int cntDl(){
  55.         int cnt = 0;
  56.  
  57.         for(int i = 0; i < this->n; i++){
  58.             cnt += arr[i]->getLen();
  59.         }
  60.         return cnt;
  61.     }
  62.     //5
  63.  
  64.     int absSumm(){
  65.         int sm = 0;
  66.         for(int i = 0; i < this->n; i++){
  67.             sm += arr[i]->getZn();
  68.         }
  69.         return sm;
  70.     }
  71.     //6
  72.     int posCnt(){
  73.         int sm = 0;
  74.         for(int i = 0; i < this->n; i++){
  75.             sm += (arr[i]->getZn() > 0);
  76.         }
  77.         return sm;
  78.     }
  79.     //7
  80.     double sumMant(){
  81.         double sm = 0;
  82.         for(int i = 0; i < this->n; i++){
  83.             sm += arr[i]->getMant();
  84.         }
  85.         return sm;
  86.     }
  87.     //8
  88.     int minIdx(){
  89.         double min = 1e9;
  90.         int mindx = -1;
  91.         for(int i = 0; i < this->n; i++){
  92.             if(min > arr[i]->getZn()){
  93.                 min = arr[i]->getZn();
  94.                 mindx = i;
  95.             }
  96.         }
  97.         cout << arr[mindx]->getString() << "\n";
  98.         return mindx;
  99.     }
  100.     //9
  101.     int cntRange(double x, double y){
  102.         int cnt = 0;
  103.         for(int i = 0; i < this->n; i++){
  104.             cnt+= (arr[i]->getZn() >= x and y <= arr[i]->getZn());
  105.         }
  106.         return cnt;
  107.     }
  108.     //10
  109.     int cntodd(){
  110.         int cnt = 0;
  111.         for(int i = 0; i < this->n; i++){
  112.             if(typeid(arr[i]->getZn()).name() != "int"){
  113.                 cnt += (int(arr[i]->getZn()) % 2 != 0);
  114.             }
  115.         }
  116.         return cnt;
  117.     }
  118. };
  119.  
  120.  
  121. #endif //UNTITLED3_CONTAINER_H
  122.  
Advertisement
Add Comment
Please, Sign In to add comment