Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Created by User on 10/12/2024.
- //
- #import "TIntName.h"
- #import "TDoubleName.h"
- #ifndef UNTITLED3_CONTAINER_H
- #define UNTITLED3_CONTAINER_H
- class Container {
- TString **arr;
- int n;
- public:
- Container():arr(nullptr), n(0){}
- Container(bool st){
- if(st){
- cin >> this->n;
- arr = new TString *[this->n];
- for(int i = 0; i < this->n; i++){
- string s;
- string name;
- cin >> s >> name;
- if(s == "idInt"){
- int q;
- cin >> q;
- arr[i] = new TIntName(name.c_str(), q);
- }else if(s == "idDouble"){
- double q;
- cin >> q;
- arr[i] = new TDoubleName(name.c_str(), q);
- }
- }
- }else{
- Container();
- }
- }
- ~Container(){
- for(int i = 0; i < this->n; i++){
- delete arr[i];
- }
- delete[]arr;
- }
- //3
- void printData(){
- for(int i = 0; i < this->n; i++){
- arr[i]->printWithLength();
- }
- }
- //4
- int cntDl(){
- int cnt = 0;
- for(int i = 0; i < this->n; i++){
- cnt += arr[i]->getLen();
- }
- return cnt;
- }
- //5
- int absSumm(){
- int sm = 0;
- for(int i = 0; i < this->n; i++){
- sm += arr[i]->getZn();
- }
- return sm;
- }
- //6
- int posCnt(){
- int sm = 0;
- for(int i = 0; i < this->n; i++){
- sm += (arr[i]->getZn() > 0);
- }
- return sm;
- }
- //7
- double sumMant(){
- double sm = 0;
- for(int i = 0; i < this->n; i++){
- sm += arr[i]->getMant();
- }
- return sm;
- }
- //8
- int minIdx(){
- double min = 1e9;
- int mindx = -1;
- for(int i = 0; i < this->n; i++){
- if(min > arr[i]->getZn()){
- min = arr[i]->getZn();
- mindx = i;
- }
- }
- cout << arr[mindx]->getString() << "\n";
- return mindx;
- }
- //9
- int cntRange(double x, double y){
- int cnt = 0;
- for(int i = 0; i < this->n; i++){
- cnt+= (arr[i]->getZn() >= x and y <= arr[i]->getZn());
- }
- return cnt;
- }
- //10
- int cntodd(){
- int cnt = 0;
- for(int i = 0; i < this->n; i++){
- if(typeid(arr[i]->getZn()).name() != "int"){
- cnt += (int(arr[i]->getZn()) % 2 != 0);
- }
- }
- return cnt;
- }
- };
- #endif //UNTITLED3_CONTAINER_H
Advertisement
Add Comment
Please, Sign In to add comment