Write a program that has an Asteroid class The class has pri
Write a program that has an Asteroid class. The class has private data members of size and speed. It has set functions for the size and speed data members. The class also has a displayStats function that outputs the size and the speed. The main should create two asteroids. Once they are created, set the asteroids values. Have Asteroid 1 and size 1 but speed 20 and Asteroid 2 be size 4 and speed 3. Then, call displayStats on each asteroid.
Example execution:
Asteroid: has size of 1 speed of 20
Asteroid: has size of 4 speed of 3
Also, in the final example in the lecture notes, setSize was modified to check if main was trying to change the size greater than 20. Modify setSize again to also check to see if the size is less than one. If it is, set it to one and output a message that the size was too small.
2) Write the UML class diagram for the Asteroid program you wrote in the previous problem
Solution
Code:
#include <iostream> // std:s:cin, std::cout
#include <fstream> // std::ifstream
#include <map>
#include<cstdlib>
#include<ctime>
using namespace std;
class Asteroid
{
private:
int size,speed;
public:
Asteroid(int si,int sp)
{
speed =sp;
size =si;
}
void setspeed(int sp)
{
speed =sp;
}
void setsize(int si)
{
size =si;
}
int getsize()
{
return size;
}
int getspeed()
{
return speed;
}
void displayStats()
{
cout<<\"Asteroid: has size of \"<<size<<\" speed of \"<<speed<<endl;
}
};
int main () {
Asteroid* ob1 = new Asteroid(1,20);
Asteroid* ob2 = new Asteroid(4,3);
ob1->displayStats();
ob2->displayStats();
return 0;
}

