diff options
Added todays oop practice
6 files changed, 123 insertions, 0 deletions
diff --git a/Year 1/Object-oriented Programming/05-Practice-29.03.2022/ex1-Entity.cpp b/Year 1/Object-oriented Programming/05-Practice-29.03.2022/ex1-Entity.cpp new file mode 100644 index 0000000..0252a13 --- /dev/null +++ b/Year 1/Object-oriented Programming/05-Practice-29.03.2022/ex1-Entity.cpp @@ -0,0 +1,14 @@ +#include "ex1-Entity.h" +#include <iostream> + +Entity::Entity() { + x = 0; + std::cout << "Entity created!"; +} +Entity::Entity(int xVal) { + x = xVal; +} + +Entity::~Entity() { + std::cout << "Entity destroyed"; +} diff --git a/Year 1/Object-oriented Programming/05-Practice-29.03.2022/ex1-Entity.h b/Year 1/Object-oriented Programming/05-Practice-29.03.2022/ex1-Entity.h new file mode 100644 index 0000000..89c8d3f --- /dev/null +++ b/Year 1/Object-oriented Programming/05-Practice-29.03.2022/ex1-Entity.h @@ -0,0 +1,13 @@ +#ifndef ENTITY_HEADER +#define ENTITY_HEADER + +class Entity { +private: + int x; +public: + Entity(); + Entity(int xVal); + ~Entity(); +}; + +#endif // !ENTITY_HEADER diff --git a/Year 1/Object-oriented Programming/05-Practice-29.03.2022/ex1-Source.cpp b/Year 1/Object-oriented Programming/05-Practice-29.03.2022/ex1-Source.cpp new file mode 100644 index 0000000..fbf5934 --- /dev/null +++ b/Year 1/Object-oriented Programming/05-Practice-29.03.2022/ex1-Source.cpp @@ -0,0 +1,8 @@ +#include "ex1-Entity.h" + +int main() { + Entity f; + Entity s(10); + Entity* t = new Entity; + Entity x(); +} diff --git a/Year 1/Object-oriented Programming/05-Practice-29.03.2022/ex2-Rational.cpp b/Year 1/Object-oriented Programming/05-Practice-29.03.2022/ex2-Rational.cpp new file mode 100644 index 0000000..05794b5 --- /dev/null +++ b/Year 1/Object-oriented Programming/05-Practice-29.03.2022/ex2-Rational.cpp @@ -0,0 +1,47 @@ +#include "ex2-Rational.h" + +Rational::Rational(int numerator, int denumerator) { + set_numerator(numerator); + set_denumerator(denumerator); +} + +int Rational::get_numerator() const { + return numerator; +} +void Rational::set_numerator(int numerator) { + this->numerator = numerator; +} + +int Rational::get_denumerator() const { + return denumerator; +} +void Rational::set_denumerator(int denumerator) { + this->denumerator = denumerator; +} + +void canonize() { + +} + +Rational Rational::operator+(const Rational& other) { + return Rational(numerator * other.denumerator + other.numerator * denumerator, denumerator * other.denumerator); +} + +//x a = x*b + y*a +//y b y*b + +Rational Rational::operator-(const Rational& other) { + return Rational(numerator * other.denumerator - other.numerator * denumerator, denumerator * other.denumerator); +} + +Rational Rational::operator*(const Rational& other) { + return Rational(numerator * other.numerator, denumerator * other.denumerator); +} + +Rational Rational::operator/(const Rational& other) { + return Rational(numerator / other.numerator, denumerator / other.denumerator); +} + +int Rational::numcmp(const Rational& arg) const { + +} diff --git a/Year 1/Object-oriented Programming/05-Practice-29.03.2022/ex2-Rational.h b/Year 1/Object-oriented Programming/05-Practice-29.03.2022/ex2-Rational.h new file mode 100644 index 0000000..f95e520 --- /dev/null +++ b/Year 1/Object-oriented Programming/05-Practice-29.03.2022/ex2-Rational.h @@ -0,0 +1,24 @@ +class Rational { + int numerator; + int denumerator; + +public: + Rational(int numerator, int denumerator); + + int get_numerator() const; + void set_numerator(int numerator); + + int get_denumerator() const; + void set_denumerator(int denumerator); + + void canonize(); + + Rational operator+(const Rational& other); + Rational operator-(const Rational& other); + Rational operator*(const Rational& other); + Rational operator/(const Rational& other); + + int numcmp(const Rational& arg) const; + + void print() const; +}; diff --git a/Year 1/Object-oriented Programming/05-Practice-29.03.2022/ex2-Source.cpp b/Year 1/Object-oriented Programming/05-Practice-29.03.2022/ex2-Source.cpp new file mode 100644 index 0000000..906ce83 --- /dev/null +++ b/Year 1/Object-oriented Programming/05-Practice-29.03.2022/ex2-Source.cpp @@ -0,0 +1,17 @@ +#include "ex2-Rational.h" + +int main() { + +} +/* + +5 - 1 = 4 +5 / 1 = 5 + +5 - 9 = -4 +5 / 9 = 0... + +5 - 5 = 0 +5 / 5 = 1 + +*/ |
