Question: C++ Please use the template for the code Write a program with the following features: Implement a class named StartWars; Class StartWars has the method
C++ Please use the template for the code
Write a program with the following features:
Implement a class named StartWars; Class StartWars has the method named CreateClone; In CreateClone you should ask the user about the total_number of clone warrior that should be created.
Each warrior is represented as a variable member of the struct data_clone warrior comprised of: int ID, string name, int timeCounter
Use new and delete to keep your struct data_clone warrior properly dynamically allocated and released before the program ends
After creating the struct data_clone warrior with new command, then create the method Input asking the user for each of the clones, what is their info - ID, name, timeCounter
As clones are believed to have a shorter lifespan, run the method LifeSpan, with a loop counting the biological clock of each clone as follows: every loop iteration, print the warrior ID, name and timeCounter; the timeCounter is decreased by 1 in each iteration; if for that clone timeCounter is zero print ID, name, timeCounter and the message "clone is dead" or "clone is alive" if timeCounter is larger than zero; inform when all clones are dead, then finish the program.
Here is the template
#include
void output_all(struct data_clone *pointer_warrior,int total_number){ int i; cout << "output all" << endl; for(i=0;i void output_each(struct data_clone *pointer_warrior,int total_number){ int i; cout << "output each" << endl; for(i=0;i int main() { int i,total_number; struct data_clone *warrior; cout << "how many clones today?" << endl; cin >> total_number; warrior = new struct data_clone[total_number]; for(i=0;i output_all(warrior,total_number); for(i=0;i delete [] warrior; return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
