Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstring>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- class String
- {
- private:
- char *str;
- public:
- String ();
- String (const char* s)
- {
- str = new char[strlen(s) + 1];
- strcpy(str, s);
- }
- String operator+ (String other)
- {
- String result;
- result.str = new char[strlen(str)+strlen(other.str)+1];
- strcpy(result.str, str);
- strcat(result.str, other.str);
- return result;
- }
- String& operator= (const String other)
- {
- delete[] str;
- str = new char[strlen(other.str)+1];
- strcpy(str, other.str);
- return *this;
- }
- const char* getString()const
- {
- return str;
- }
- ~String()
- {
- delete[] str;
- }
- };
- ostream& operator<< (ostream& os, const String& str)
- {
- os<<str.getString();
- return os;
- }
- class User
- {
- private:
- String name;
- int age;
- String email;
- int id;
- public:
- int setID()
- {
- id = rand();
- return id;
- }
- void setName(String name)
- {
- this->name = name;
- }
- void setAge(int age)
- {
- age = this->age;
- }
- String setEmail(String email)
- {
- this->email = email;
- }
- String getName () const
- {
- return name;
- }
- int getAge () const
- {
- return age;
- }
- String getEmail () const
- {
- return email;
- }
- void registerUser(String name, int age, String email)
- {
- ofstream myfile2;
- myfile2.open ("usersFull.txt");
- myfile2 << name <<" "<< age<< " " << " " << email << endl;
- myfile2.close();
- }
- };
- int main()
- {
- User user1;
- User user2;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment