Advertisement
totorialman

Untitled

Mar 25th, 2023
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. //planet.h
  2. #include <iostream>
  3. #include <fstream>
  4. using namespace std;
  5. class Planet {
  6. private:
  7.     char* name;
  8. public:
  9.     Planet(int l_name = 20);
  10.     ~Planet();
  11.     char* getName() {
  12.         return name;
  13.     }
  14.     void setName(char* str) {
  15.         strcpy(name,str);
  16.  
  17.     static int search_db(Planet*&, int&);
  18.  
  19.     friend bool operator==(Planet&, char*&);
  20. };
  21.  
  22. //planet.cpp
  23. bool operator==(Planet& first, char*& second) {
  24.    
  25.     if (strlen(first.getName()) != strlen(second)) return false;
  26.     for (int t = 0; t < strlen(first.getName()); t++) {
  27.         if (first.getName()[t] != second[t]) {
  28.             return false;
  29.         }
  30.     }
  31.     return true;
  32. }
  33.  
  34. int Planet::search_db(Planet*& planets, int& Size) {
  35.     char* name_d = new char[name_l];
  36.     int flag = 0, ind;
  37.     cin >> name_d;
  38.     for (int i = 0; i < Size; i++) {
  39.         if (planets[i].name == name_d) { // здесь использую перегрузку
  40.             ind = i;
  41.             return ind;
  42.         }
  43.     }
  44.     return -1;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement