Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Servant {
- public:
- void get(Servant object);
- void set(char *firstArr,char *secondArr,int third);
- Servant (){
- cout << "Constructors worked" << endl;
- }
- Servant (char *first, char *second, int third) {
- strcpy(name,first);
- strcpy(encryption,second);
- quantity = third;
- cout << "Second Constructors worked" << endl;
- }
- Servant (const Servant &object){
- cout << "Coppy constructor worked" << endl;
- }
- ~Servant(){
- cout << "Destructor worked" << endl;
- delete []name;
- delete []encryption;
- }
- private:
- char *name = new char [30];
- char *encryption = new char [20];
- int quantity = 0;
- };
- void Servant::get(Servant object) {
- cout <<"Name = "<< name << endl <<"Encryption = "<< encryption << endl <<"Quantity = "<< quantity << endl;
- }
- void Servant::set(char *firstArr,char *secondArr,int third){
- strcpy(name,firstArr);
- strcpy(encryption,secondArr);
- quantity = third;
- }
- int main() {
- char *strFirst = new char [strlen("Sofa")+1];
- char *strSecond = new char [strlen("QWERTY")+1];
- strcpy(strFirst,"Sofa");
- strcpy(strSecond,"QWERTY");
- int tester = 10;
- Servant first ;
- Servant *second = new Servant(strFirst, strSecond,tester);
- second ->set(strFirst,strSecond,tester);
- second ->get(first);
- delete second;
- delete [] strFirst;
- delete [] strSecond;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement