Mira2706

domashno

Apr 21st, 2020
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <ctime>
  6.  
  7. using namespace std;
  8.  
  9. class String
  10. {
  11. private:
  12.     char *str;
  13. public:
  14.     String ();
  15.  
  16.     String (const char* s)
  17.     {
  18.         str = new char[strlen(s) + 1];
  19.         strcpy(str, s);
  20.     }
  21.  
  22.     String operator+ (String other)
  23.     {
  24.         String result;
  25.         result.str = new char[strlen(str)+strlen(other.str)+1];
  26.         strcpy(result.str, str);
  27.         strcat(result.str, other.str);
  28.         return result;
  29.     }
  30.     String& operator= (const String other)
  31.     {
  32.         delete[] str;
  33.         str = new char[strlen(other.str)+1];
  34.         strcpy(str, other.str);
  35.         return *this;
  36.     }
  37.     const char* getString()const
  38.     {
  39.         return str;
  40.     }
  41.     ~String()
  42.     {
  43.         delete[] str;
  44.     }
  45. };
  46.  
  47. ostream& operator<< (ostream& os, const String& str)
  48. {
  49.     os<<str.getString();
  50.     return os;
  51. }
  52.  
  53. class User
  54. {
  55. private:
  56.  
  57.     String name;
  58.     int age;
  59.     String email;
  60.     int id;
  61. public:
  62.  
  63.     int setID()
  64.     {
  65.         id = rand();
  66.         return id;
  67.     }
  68.     void setName(String name)
  69.     {
  70.         this->name = name;
  71.     }
  72.     void setAge(int age)
  73.     {
  74.         age = this->age;
  75.     }
  76.     String setEmail(String email)
  77.     {
  78.        this->email = email;
  79.     }
  80.  
  81.     String getName () const
  82.     {
  83.         return name;
  84.     }
  85.     int getAge () const
  86.     {
  87.         return age;
  88.     }
  89.     String getEmail () const
  90.     {
  91.         return email;
  92.     }
  93.  
  94.      void registerUser(String name, int age, String email)
  95.     {
  96.  
  97.         ofstream myfile2;
  98.         myfile2.open ("usersFull.txt");
  99.         myfile2 << name <<" "<< age<< " " << " " << email << endl;
  100.         myfile2.close();
  101.     }
  102. };
  103.  
  104.  
  105. int main()
  106. {
  107.     User user1;
  108.     User user2;
  109.     user2.registerUser("Sashka", 19, "[email protected]");
  110.     user1.registerUser("Svetlio", 45, "[email protected]");
  111.  
  112.     return 0;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment