this is the mock up test for my final. I have to be able to explain how these kind of code works. But to be honest, I do not understand this code quite well. Can you guys please explain my how this works? I will be so glad to be prepared for my final if I can understand it perfectly. Thank you.
#include <iostream>
using namespace std;
class Wind {
int category;
public:
Wind(int cat = 3) {
category = cat;
cout << "1." << cat << endl;
}
virtual void increase(int amount) {
category += amount;
cout << "A. " << category << endl;
}
void operator++() {
++category;
cout << "B. " << category << endl;
}
virtual ~Wind() {
cout << "C. " << category << endl;
}
};
class Tornado : public Wind {
double velocity;
public:
Tornado(int cat, double vel) : Wind(cat) {
velocity = vel;
cout << "2. " << vel << endl;
}
virtual void increase(int value) {
velocity += value;
cout << "X. " << velocity << endl;
}
void operator++() {
Wind::operator++();
velocity += 20;
cout << "Y. " << endl;
}
~Tornado() {
cout << "Z. " << velocity << endl;
}
};
int main() {
Wind* wind_array[2];
wind_array[0] = new Tornado(7, 66.5);
wind_array[1] = new Wind(5);
for (int i = 0; i < 2; i++) {
wind_array[i]->increase(5);
++(*wind_array[i]);
}
for (int i = 0; i < 2; i++)
delete wind_array[i];
return 0;
}
This is the output.
1.7
2. 66.5
1.5
X. 71.5
B. 8
A. 10
B. 11
Z. 71.5
C. 8
C. 11