diff --git a/OOP/a.out b/OOP/a.out deleted file mode 100755 index 2ee7394..0000000 Binary files a/OOP/a.out and /dev/null differ diff --git a/OOP/access_specifier/ex1.cpp b/OOP/access_specifier/ex1.cpp new file mode 100644 index 0000000..5cb1198 --- /dev/null +++ b/OOP/access_specifier/ex1.cpp @@ -0,0 +1,24 @@ +#include +using namespace std; + +class MyClass { + public: + int x; + private: + int y; +}; + +int main() { + MyClass classObject; + + /* + Here we try to access the y variable ; + But that is not accessible to us cause its a private Value ; + If that y were accessed inside of that function everything would be fine! + */ + + classObject.x = 25; + classObject.y = 50; + + return 0; +} \ No newline at end of file diff --git a/OOP/constructor/a.out b/OOP/constructor/a.out new file mode 100755 index 0000000..02e3385 Binary files /dev/null and b/OOP/constructor/a.out differ diff --git a/OOP/constructor/car_constructor.cpp b/OOP/constructor/car_constructor.cpp new file mode 100644 index 0000000..faa76e6 --- /dev/null +++ b/OOP/constructor/car_constructor.cpp @@ -0,0 +1,31 @@ +#include + +/* + Here we have a more "practical" approach to Constructors ; + We use the constructor here to print out some predefined data from a Class Object +*/ + +using namespace std; + +class Car { + public: + string brand; + string model; + int year; + + Car (string x , string y , int z) { + brand = x; + model = y; + year = z; + } +}; + +int main() { + Car volvo("Volvo", "VolvoAuto", 1989); + Car volkswagen("Volkswagen", "Golf", 2004); + + cout << volvo.brand << " " << volvo.model << " " << volvo.year << "\n"; + cout << volkswagen.brand << " " << volkswagen.model << " " << volkswagen.year << "\n"; + + return 0; +} \ No newline at end of file diff --git a/OOP/constructor/car_outside.cpp b/OOP/constructor/car_outside.cpp new file mode 100644 index 0000000..93b8d29 --- /dev/null +++ b/OOP/constructor/car_outside.cpp @@ -0,0 +1,34 @@ +#include + +/* + We copied the main function from the last example , but here we just have the Constructor outside of the class definition; + So the Constructor then gets defined like: + class::constructor + Like that you can make it more "readable"; +*/ + +using namespace std; + +class Car { + public: + string brand; + string model; + int year; + Car(string x , string y, int z); +}; + +Car::Car(string x, string y, int z) { + brand = x; + model = y; + year = z; +} + +int main() { + Car volvo("Volvo", "VolvoAuto", 1989); + Car volkswagen("Volkswagen", "Golf", 2004); + + cout << volvo.brand << " " << volvo.model << " " << volvo.year << "\n"; + cout << volkswagen.brand << " " << volkswagen.model << " " << volkswagen.year << "\n"; + + return 0; +} \ No newline at end of file diff --git a/OOP/constructor/constructor.cpp b/OOP/constructor/constructor.cpp new file mode 100644 index 0000000..0d4ee43 --- /dev/null +++ b/OOP/constructor/constructor.cpp @@ -0,0 +1,20 @@ +#include + +/* + Here we have a example of a Constructor ; + When we create a Class Object we auto-call the Constructor +*/ + +using namespace std; + +class MyClass { + public: + MyClass() { // This is the constructor! + cout << "Construct!"; + } +}; + +int main() { + MyClass classobj; // When we create this the Constructor autocalls! + return 0; +} \ No newline at end of file diff --git a/OOP/methodes/car_speed.cpp b/OOP/methodes/car_speed.cpp new file mode 100644 index 0000000..79e23f1 --- /dev/null +++ b/OOP/methodes/car_speed.cpp @@ -0,0 +1,22 @@ +#include + +/* + This here that we have is just another demo of the OOP in c++ ; we have the function that we have in the last example and then we usefully do something + with this function ; +*/ + +using namespace std; + +class Car { + public: + int speed(int max_speed); +}; + +int Car::speed(int max_speed) { + return max_speed; +} + +int main() { + Car volvo; + volvo.speed(600); +} \ No newline at end of file diff --git a/OOP/class_methode_outside.cpp b/OOP/methodes/class_methode_outside.cpp similarity index 100% rename from OOP/class_methode_outside.cpp rename to OOP/methodes/class_methode_outside.cpp diff --git a/OOP/class_methodes.cpp b/OOP/methodes/class_methodes.cpp similarity index 100% rename from OOP/class_methodes.cpp rename to OOP/methodes/class_methodes.cpp diff --git a/OOP/simple.cpp b/OOP/methodes/simple.cpp similarity index 100% rename from OOP/simple.cpp rename to OOP/methodes/simple.cpp