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

first activity #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
68 changes: 68 additions & 0 deletions Basic/question_1_another_example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
Question: Difference between encapsulation and abstraction ?


Answer:

Encapsulation:
Encapsulation is about bundling data (attributes) and methods (functions) together, and restricting access to certain parts of the object. This helps in hiding the internal details and providing a clean interface for interacting with the object.
Comment on lines +1 to +7
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use proper comment syntax



#include <iostream>
using namespace std;
Comment on lines +10 to +11
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move it at the top of file


class EncapsulationExample {
private:
// we declare a as private to hide it from outside
int a;

public:
// set() function to set the value of a
void set(int x)
{
a = x;
}

// get() function to return the value of a
int get()
{
return a;
}
};

// main function
int main()
{
EncapsulationExample e1;

e1.set(10);

cout<<e1.get();
return 0;
}


The concept of abstraction only shows necessary information to the users. It reduces the complexity of the program by hiding the implementation complexities of programs.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use proper comment syntax



class Sum {
private:
// private variables
int a, b, c;
public:
void sum(int x, int y)
{
a = x;
b = y;
c = a + b;
cout<<"Sum of the two number is : "<<c<<endl;
}
};
int main()
{
Sum s;
s.sum(5, 4);
return 0;
}



Comment on lines +66 to +68
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unnecessary extra lines