diff --git a/CM2005 Object Oriented Programming/Topic 5/5.2.1/a.exe b/CM2005 Object Oriented Programming/Topic 5/5.2.1/a.exe new file mode 100644 index 0000000..b787f7a Binary files /dev/null and b/CM2005 Object Oriented Programming/Topic 5/5.2.1/a.exe differ diff --git a/CM2005 Object Oriented Programming/Topic 5/5.2.1/test.cpp b/CM2005 Object Oriented Programming/Topic 5/5.2.1/test.cpp new file mode 100644 index 0000000..ff5e5aa --- /dev/null +++ b/CM2005 Object Oriented Programming/Topic 5/5.2.1/test.cpp @@ -0,0 +1,40 @@ +class Car +{ + public: + Car(); + void accelerate(); + static int whichIsFaster(Car carA, Car carB); + private: + float speed; +}; + +Car::Car() : speed(0.0f) +{ + +} + +void Car::accelerate() +{ + speed += 0.5f; +} + +int Car::whichIsFaster(Car carA, Car carB) +{ + if(carA.speed > carB.speed) + { + return 0; + } + return 1; +} + +int main() +{ + Car car1{}; + car1.accelerate(); + // state of car1 - speed is 1.5 + Car car2; + car2.accelerate(); + car2.accelerate(); + // static functions don't need to remember or access the state of the function + Car::whichIsFaster(car1, car2); +} \ No newline at end of file