Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added object oriented programming concept codes C++ #214

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions 01_class_obj.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <iostream>
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
24 changes: 24 additions & 0 deletions 02_constructor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <iostream>
using namespace std;

class constructordemo
{
public:
constructordemo()
{
cout<<"I AM THE CONSTRUCTOR "<<endl;
cout<<"no one calls me ! i get auto called when u declare class object! "<<endl;
}

};

int main()
{
constructordemo obj;


return 0;
}


//This program is contributed by YASH RAJ MANI
28 changes: 28 additions & 0 deletions 03_destructor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <iostream>
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