Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Servant {
  6.  
  7. public:
  8. void get(Servant object);
  9. void set(char *firstArr,char *secondArr,int third);
  10.  
  11. Servant (){
  12. cout << "Constructors worked" << endl;
  13. }
  14.  
  15. Servant (char *first, char *second, int third) {
  16. strcpy(name,first);
  17. strcpy(encryption,second);
  18. quantity = third;
  19. cout << "Second Constructors worked" << endl;
  20. }
  21.  
  22. Servant (const Servant &object){
  23. cout << "Coppy constructor worked" << endl;
  24.  
  25. }
  26.  
  27. ~Servant(){
  28. cout << "Destructor worked" << endl;
  29. delete []name;
  30. delete []encryption;
  31. }
  32.  
  33. private:
  34. char *name = new char [30];
  35. char *encryption = new char [20];
  36. int quantity = 0;
  37. };
  38.  
  39. void Servant::get(Servant object) {
  40. cout <<"Name = "<< name << endl <<"Encryption = "<< encryption << endl <<"Quantity = "<< quantity << endl;
  41. }
  42.  
  43. void Servant::set(char *firstArr,char *secondArr,int third){
  44. strcpy(name,firstArr);
  45. strcpy(encryption,secondArr);
  46. quantity = third;
  47. }
  48.  
  49. int main() {
  50.  
  51. char *strFirst = new char [strlen("Sofa")+1];
  52. char *strSecond = new char [strlen("QWERTY")+1];
  53.  
  54. strcpy(strFirst,"Sofa");
  55. strcpy(strSecond,"QWERTY");
  56. int tester = 10;
  57. Servant first ;
  58. Servant *second = new Servant(strFirst, strSecond,tester);
  59. second ->set(strFirst,strSecond,tester);
  60. second ->get(first);
  61.  
  62. delete second;
  63. delete [] strFirst;
  64. delete [] strSecond;
  65.  
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement