From 7a46da3b3ff36b75ec3aa80e52d2677fbd133ecb Mon Sep 17 00:00:00 2001 From: Yash Raj Mani <72155985+yashrajmani@users.noreply.github.com> Date: Thu, 28 Oct 2021 21:17:02 +0530 Subject: [PATCH] Added object oriented programming concept codes C++ Pls merge! Happy hacktoberfest Thanks! --- 01_class_obj.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 02_constructor.cpp | 24 ++++++++++++++++++++++++ 03_destructor.cpp | 28 ++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 01_class_obj.cpp create mode 100644 02_constructor.cpp create mode 100644 03_destructor.cpp diff --git a/01_class_obj.cpp b/01_class_obj.cpp new file mode 100644 index 0000000..60fa487 --- /dev/null +++ b/01_class_obj.cpp @@ -0,0 +1,40 @@ +#include +using namespace std; + +class car +{ + char col[10]; +public: + int speed; + void get(int distance, int fuel) + { + cout << "the car has DISTANCE :" << distance << "FUEL :" << fuel << endl; + } + void milage(float distance, float fuel); + + void carspeed() + { + cout << "SPEED " << speed; + } + +} audi; + +void car ::milage(float d, float f) +{ + float carmil = d / f; + cout << "MILAGE IS :" << carmil << endl; +} + +int main() +{ + car swift; + swift.get(10, 10); + audi.get(19, 20); + audi.milage(1900, 20); + swift.speed = 10; + swift.carspeed(); + return 0; +} + + +//This program is contributed by YASH RAJ MANI \ No newline at end of file diff --git a/02_constructor.cpp b/02_constructor.cpp new file mode 100644 index 0000000..c7d82bc --- /dev/null +++ b/02_constructor.cpp @@ -0,0 +1,24 @@ +#include +using namespace std; + +class constructordemo +{ + public: + constructordemo() + { + cout<<"I AM THE CONSTRUCTOR "< +using namespace std; + +class destructordemo +{ +public: + destructordemo() + { + cout << "i am at begining I AM CONSTRUCTOR " << endl; + } + ~destructordemo() + { + cout << "no matter where i am after all ends, I AM destructor " << endl; + } + void disp() + { + cout << "helloo i am member function " << endl; + } +}; + +int main() +{ + destructordemo d1; + d1.disp(); + + return 0; +} +//This program is contributed by YASH RAJ MANI \ No newline at end of file