Question & Answer: What does the following program print? Write your answer below the program. Note that the program continues on the next page. class Spaceship { p…..

8. More Pointers! (15 points) What does the following program print? Write your answer below the program. Note that the program continues on the next page. (Hint: the default copy constructor in C++ automatically copies everything allocated statically within an object.) class Spaceship public: Spaceship (const string& initialName, int initialSize) : name (initialName), size(initialsize) void printo cout << name << “: << size << endl; string name: int size; Spaceship functionA (const Spaceship& otherSpaceship) Spaceship newSpaceship (otherSpacesbip) newSpaceship.nameStevie Wonder; return newSpaceship; int functionB (Spaceship& otherSpaceship) otherSpaceship.size5; return otherSpaceship.size void functionC (Spaceship* otherSpaceship) otherSpaceship->nameBeyonce int main Spaceship sl (Paul McCartney, 15); Spaceship s2functionA(sl): Spaceship* s3 new Spaceship(Elton John, 6); s3->size = functionB (s2) ; functionC(&s1) sl.print s2 print s3->print

What does the following program print? Write your answer below the program. Note that the program continues on the next page. class Spaceship { public: Spaceship (const strings& initialName, int initialSize): name(initialName), size(initialSize) {} void print() { cout

Expert Answer

 

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: What does the following program print? Write your answer below the program. Note that the program continues on the next page. class Spaceship { p…..
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE
Order Essay

Output:

Beyonce : 15
Stevie Wonder : 5
Elton John : 5

#include <iostream>

using namespace std;

class Spaceship

{

public:

Spaceship(const string &initialName,int initialSize):name(initialName),size(initialSize)

{ }

void print()

{

cout<<name <<” : “<<size<<endl;

}

string name;

int size;

 

};

Spaceship functionA(const Spaceship& otherSpaceship)

{

Spaceship newSpaceship(otherSpaceship);

newSpaceship.name = “Stevie Wonder”;

return newSpaceship;

}

int functionB(Spaceship& otherSpaceship)

{

otherSpaceship.size = 5;

return otherSpaceship.size;

}

void functionC(Spaceship *otherSpaceship)

{

otherSpaceship->name = “Beyonce”;

}

int main()

{

 

Spaceship s1(“Paul McCartney”,15); //argument constructor is invoked

Spaceship s2 = functionA(s1); //call to function sending the object s1 where name of spaceship is set to Stevie Wonder

Spaceship *s3 = new Spaceship(“Elton John”,6);

s3->size = functionB(s2); //set size of s2 object to size of s3 ie 5

functionC(&s1);//set name of s1 to Beyonce

s1.print(); //Beyonce 15 , size remains 15

s2.print(); //Stevie Wonder 5

s3->print();// Elton John 5

return 0;

}

Still stressed from student homework?
Get quality assistance from academic writers!