some more content
This commit is contained in:
BIN
OOP/access_specifier/ex2
Executable file
BIN
OOP/access_specifier/ex2
Executable file
Binary file not shown.
33
OOP/access_specifier/ex2.cpp
Normal file
33
OOP/access_specifier/ex2.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
Here we have the protected specifier which lets a class inherit a variable (in this example it is salary!)
|
||||
*/
|
||||
|
||||
class Employee {
|
||||
protected:
|
||||
int salary;
|
||||
};
|
||||
|
||||
class Programmer: public Employee {
|
||||
public:
|
||||
int bonus;
|
||||
void setSalary(int s) {
|
||||
salary = s;
|
||||
}
|
||||
int getSalary() {
|
||||
return salary;
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
Programmer classobj;
|
||||
classobj.setSalary(1000);
|
||||
classobj.bonus = 200;
|
||||
|
||||
cout << "Salary for Programmer Class: " << classobj.getSalary() << "\n";
|
||||
cout << "Bonus for Programmer Class: " << classobj.bonus << "\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
BIN
OOP/constructor/car_outside
Executable file
BIN
OOP/constructor/car_outside
Executable file
Binary file not shown.
BIN
OOP/encapsulation/main
Executable file
BIN
OOP/encapsulation/main
Executable file
Binary file not shown.
24
OOP/encapsulation/main.cpp
Normal file
24
OOP/encapsulation/main.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Employee {
|
||||
private:
|
||||
int salary;
|
||||
public:
|
||||
// Setter
|
||||
void setSalary(int s) {
|
||||
salary = s;
|
||||
}
|
||||
int getSalary() {
|
||||
return salary;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
int main() {
|
||||
Employee myObj;
|
||||
myObj.setSalary(123000);
|
||||
cout << myObj.getSalary();
|
||||
return 0;
|
||||
}
|
||||
BIN
OOP/inheritance/Vehicle
Executable file
BIN
OOP/inheritance/Vehicle
Executable file
Binary file not shown.
23
OOP/inheritance/Vehicle.cpp
Normal file
23
OOP/inheritance/Vehicle.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Vehicle {
|
||||
public:
|
||||
string brand = "Ford";
|
||||
void honk() {
|
||||
cout << "Honk Honk!";
|
||||
}
|
||||
};
|
||||
|
||||
class Car: public Vehicle {
|
||||
public:
|
||||
string model = "Mustang";
|
||||
};
|
||||
|
||||
int main() {
|
||||
Car myCar;
|
||||
myCar.honk();
|
||||
cout << myCar.brand + " " + myCar.model << "\n";
|
||||
return 0;
|
||||
}
|
||||
BIN
OOP/inheritance/multilevel
Executable file
BIN
OOP/inheritance/multilevel
Executable file
Binary file not shown.
24
OOP/inheritance/multilevel.cpp
Normal file
24
OOP/inheritance/multilevel.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Parent {
|
||||
public:
|
||||
void function() {
|
||||
cout << "Parent Class!";
|
||||
}
|
||||
};
|
||||
|
||||
class MyChild: public Parent {
|
||||
// Child Function here
|
||||
};
|
||||
|
||||
class MyGrandChild: public MyChild {
|
||||
// Grandchild Function here
|
||||
};
|
||||
|
||||
int main() {
|
||||
MyGrandChild classobj;
|
||||
classobj.function();
|
||||
return 0;
|
||||
}
|
||||
BIN
OOP/inheritance/multiple_inheritance
Executable file
BIN
OOP/inheritance/multiple_inheritance
Executable file
Binary file not shown.
27
OOP/inheritance/multiple_inheritance.cpp
Normal file
27
OOP/inheritance/multiple_inheritance.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class myClass {
|
||||
public:
|
||||
void myClass_one() {
|
||||
cout << "Hello World!";
|
||||
}
|
||||
};
|
||||
|
||||
class MyOtherClass {
|
||||
public:
|
||||
void MyOtherClass_Function() {
|
||||
cout << "Hello, I am a other Function!";
|
||||
}
|
||||
};
|
||||
|
||||
class myChildClass: public myClass, public MyOtherClass {
|
||||
};
|
||||
|
||||
int main() {
|
||||
myChildClass classobj;
|
||||
classobj.myClass_one();
|
||||
classobj.MyOtherClass_Function();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user