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

In C++ take the Asteroid program Add a constructor below and split it into 3 fil

ID: 3824943 • Letter: I

Question

In C++ take the Asteroid program Add a constructor below and split it into 3 files -- Asteroid.cpp, Asteroid.h and main.cpp

In addition -- write the UML class diagram for this class.

#include <iostream>
using namespace std;
class Asteroid {
private:
int size , speed;
public:
Asteroid() {
  
}
void setSize(int s){
   if(s < 1){
   size = 1;
   }
   else if(size > 20){
       size = 20;
   }
   else{
       size = s;
   }
}

void setSpeed(int s){
   speed = s;
}
};

int main()
{

   Asteroid a1;

   a1.setSpeed(45);
   a1.setSize(34);


   Asteroid a2;

   a2.setSpeed(34);
   a2.setSize(5);
  
   return 0;
  
}

Explanation / Answer

Hi, Please find my implementation.

################### Asteroid.h #############

class Asteroid {
private:
int size , speed;
public:
Asteroid();
void setSize(int s);
void setSpeed(int s);
};

################### Asteroid.cpp #############


#include "Asteroid.h"

Asteroid::Asteroid() {
  
}
void Asteroid::setSize(int s){
   if(s < 1){
   size = 1;
   }
   else if(size > 20){
       size = 20;
   }
   else{
       size = s;
   }
}

void Asteroid::setSpeed(int s){
   speed = s;
}

############ main.cpp ########

#include <iostream>
#include "Asteroid.h"
using namespace std;

int main()
{
Asteroid a1;
a1.setSpeed(45);
a1.setSize(34);

Asteroid a2;
a2.setSpeed(34);
a2.setSize(5);
  
return 0;
  
}