Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help writing a C++ program for class. Any help would be appreciated. Agai

ID: 3689886 • Letter: I

Question

I need help writing a C++ program for class. Any help would be appreciated. Again, this is in C++, NOT Java. Thanks! Here is the prompt:

1) 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; (2 points

2) Each warrior is represented as a variable member of the struct data_clone warrior comprised of: int ID, string name, int timeCounter. (2 points)

3) Use new and delete to keep your struct data_clone warrior properly dynamically allocated and released before the program ends; (2 points)

4) 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; (2 points)

5) As clones are believed to have a shorter lifespan, run the method LifeSpan, with a loop counting the biological clock of each clone as follow: 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 and zero; inform when all clones are dead, then finish the program. (2 points)

Explanation / Answer

Answers of PART 1 TO PART 4: The desired program is given below with proper comments

#include<iostream>
#include<string>
using namespace std;

struct data_clone_warrior //structure for data_clone
{
   int ID;
   string name;
   int timeCounter;
  
   //methods to take values
   void getId(int id)
   {
       ID = id;
   }
  
   void getname(string nam)
   {
       name = nam;
   }
  
   void getTimeCounter(int time)
   {
       timeCounter = time;
   }
};

class StarWars //the starwars class
{
   int total_number_clone_warrior;
  
   public:
       data_clone_warrior* w = NULL;
       void CreateClone()
       {
           cout<<"Enter the total number of clone warrior created"<<endl;
           cin>>total_number_clone_warrior;          
       }
      
       int getTotalNumber() const
       {
           return total_number_clone_warrior;
       }
};

int main()
{
   //object of starwar class
   StarWars* obj = new StarWars();
   obj->CreateClone();
   obj->w = new data_clone_warrior[obj->getTotalNumber()];
   int parId;
   string parName;
   int parTimeCounter;
   for(int i =0; i< obj->getTotalNumber(); i++)
   {
       cout<<"Enter the ID of "<<i+1<<" clone"<<endl;
       cin>>parId;
       obj->w[i].getId(parId);
       cout<<"Enter the NAME of "<<i+1<<" clone"<<endl;
       cin>>parName;
       obj->w[i].getname(parName);
       cout<<"Enter the TIME COUNTER of "<<i+1<<" clone"<<endl;
       cin>>parTimeCounter;
       obj->w[i].getTimeCounter(parTimeCounter);
   }
}