C question Please give me complete code with comments Write

C++ question. Please give me complete code with comments.

Write a class called Zombie. It should have a method called speak() that prints \"Braaaainss!\". It should have a static variable that keeps track of how many Zombie objects have been created. When a Zombie is created, its constructor will need to increment the value in the static variable. In order to keep the count accurate when Zombies are destroyed, you will need a destructor to decrement the value in the static variable.

In your main function you should declare a vector of Zombie-pointers. You should give the user a menu in a loop. The options should be to: 1) create a new Zombie; 2) destroy a Zombie; 3) print the number of existing Zombies; 4) tell all existing Zombies to speak; or 5) quit. When a user chooses to create a new Zombie, you should dynamically allocate the new object (page 671) and push its pointer onto the vector. When a user chooses to destroy a Zombie, you should pop the last Zombie pointer off the vector and deallocate the memory for that Zombie.

Dynamic memory allocation and deallocation are covered in chapter 10, for those who transferred or need to refresh their memories on the topic.

Solution

public class Zombie {

String name;

int serial = 0;

static int count = 0;

public Zombie(String name) {

this.name = name;

count++;

}

static String printStatus() {

String status;

if(count == 1) {

status = (count + \"zombie created so far\");

}

else {

status = (count + \"zombies created so far\");

}

return status;

}

String printZombie() {

String ident = (name + \" is zombie \" + serial);

return ident;

}

public static void main(String[] args) {

printStatus();

Zombie z1 = new Zombie(\"Deb\");

printStatus();

Zombie z2 = new Zombie(\"Andy\");

printStatus();

Zombie z3 = new Zombie(\"Carl\");

printStatus();

z1.printZombie();

z2.printZombie();

z3.printZombie();

}

}

C++ question. Please give me complete code with comments. Write a class called Zombie. It should have a method called speak() that prints \
C++ question. Please give me complete code with comments. Write a class called Zombie. It should have a method called speak() that prints \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site