I need help with C++ programming making star wars clones. Here are the instructi
ID: 3668931 • Letter: I
Question
I need help with C++ programming making star wars clones.
Here are the instructions:
1. Implement a class named StartWars. Class StartWars has the method named CreateClone. In Create Clone, you should ask the user about the total_number of clone warrior that should be created.
2. Each warrior is represented as a variable member of the struct data_clone warrior comprised of int ID, string name, int timeCounter.
3. Use new and delete to keep your struct data_clone warrior properly dinamically allocated and released before the program ends.
4. After creating the struct data_clone warror with new command, then create the method Input asking the user for each of the clones, what is their info - ID, name, timeCounter.
5. As clones are believed to have a shorter lifespan, ru 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's 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.
A template was given:
Explanation / Answer
#include <iostream>
using namespace std;
struct data_clone
{
public:
string name;
int total_number,ID, timeCounter;
};
void data_clone::create clone(); // creating clones
void create clone()
{
cout<<"enter the clone warriors to be created";
cin>>total_number;
}
void output_all(struct data_clone *pointer_warrior,int total_number)
{
int i;
cout << "output all" << endl;
for(i=0;i<total_number;i++)
{
cout << "warrior name "<< pointer_warrior[i].name<<endl;
cout << "inform the warrior id "<< pointer_warrior[i].ID <<endl;
cout << "inform the warrior lifespan/timeCounter "<< pointer_warrior[i].timeCounter <<endl;
}
}
void output_each(struct data_clone *pointer_warrior,int total_number){
int i;
cout << "output each" << endl;
for(i=0;i<total_number;i++){
cout << "warrior name "<< pointer_warrior->name<<endl;
cout << "inform the warrior id "<< pointer_warrior->ID <<endl;
cout << "inform the warrior lifespan/timeCounter "<< pointer_warrior->timeCounter <<endl;
}
}
int main()
{ int i;
struct data_clone *warrior;
warrior = new struct data_clone[total_number];
for(i=0;i<total_number;i++){
cout << i << " inform the warrior name "<<endl;
cin >> warrior[i].name;
cout << i << " inform the warrior id "<<endl;
cin >> warrior[i].ID;
cout << i << " inform the warrior lifespan/timeCounter "<<endl;
cin >> warrior[i].timeCounter;
}
output_all(warrior,total_number);
for(i=0;i<total_number;i++){
output_each(&warrior[i],total_number);
}
delete [] warrior;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.