Advertisement
Levii_Valenok

LabWork3

Sep 11th, 2021
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. class String
  6. {
  7.     private:
  8.  
  9.         char sentence[20]{};
  10.  
  11.     public:
  12.         String()
  13.         {
  14.  
  15.             strcpy(sentence, "");
  16.         }
  17.         void putSentence()
  18.         {
  19.             cout << "Enter a sentence" << endl;
  20.             // sentence = new char[20];
  21.             cin >> sentence;
  22.         }
  23.        
  24.        String& operator=(const String& t)
  25.        {
  26.            String temp{t};
  27.            strcpy((*this).sentence, temp.sentence);
  28.            return *this;
  29.        }
  30.  
  31.         void outputSentence()
  32.         {
  33.             cout <<"Sentence is" <<endl;
  34.             cout <<"\t"<<sentence << endl;
  35.         }
  36. };
  37.  
  38. int main()
  39. {
  40.     String sentence1, sentence2;
  41.     sentence1.putSentence();
  42.     sentence1.outputSentence();
  43.     sentence2.putSentence();
  44.     sentence2.outputSentence();
  45.     sentence1 = sentence2;
  46.     sentence1.outputSentence();
  47.     return 0;
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement