3. NAME KRISHAN KUMAR CHAUHAN
ROLL NO 215/ICS/054
PROGRAMME NAME INTEGRATED B.TECH-M.TECH (CSE)
COURSE NAME PROBLEM SOLVING USING C++
COURSE CODE CS207
4. TABLE OF CONTANTS
4
1. TOPIC
2. INTRODUCTION
3. SYNTAX
4. PROGRAM
5. APPLICATION
6. CONSEQUENCES
5. TOPIC
5
ABSTRACTION
Abstraction refers to the act of representing the crucial requisite
features without including the additional explanations of such
features. Hence, it means providing the end-user with their needs but
without the details of how the needs were fulfilled.
For instance, we know how the switches at our houses work. Say for
the fans, we just simply turn on the switch if we want to switch it on,
or turn off the switch if we want to switch it off. In the case of fans,
we can even use the regulator to adjust the speed according to our
needs.Thus, we know all the features but we don’t know what the
background implementation is.This is a real-life example of data
abstraction.
6. INTRODUCTION
Abstraction is a process that is important to the creation of
computer programs.
In this presentation we are going to talk about the nature of abstraction with
regards to Object Orientation.
There are 2 types of abstraction in C++:
1. Data Abstraction: It hides the information about the data.
2. Control Abstraction: It hides the information about the implementation.
7. Abstract Classes
# In C++ we can make use of abstract classes to provide structure with no possibility of
implementation.
#These classes provide the necessary contract for C++ to make use of dynamic binding
in a system.
#These classes known as concrete class.
8. Abstraction:
# Process of successively filtering out low level details.
# Replace with a high level view of system interactions.
# Helped by the use of diagrams and other notations (URL and such).
# Important skill in gaining big picture understanding of how classes interact.
9. Abstract Classes
In C++ abstract classes created using special syntax for class
declaration:
abstract class Student {
private String matriculationCode;
private String name;
private String address;
public Student (String m. String n, String a) {
matriculation Code = m;
name = n;
address = a;
}
public String getName() { return name:
{
public String getCode() { return mainculationCode.
}
public String getAddress() { return address,
}
}
10. Abstract Classes
Individual methods all possible to declare as abstract:
abstract class Student {
private String matriculation Code;
Private String name;
private String address;
public Student (String m, Sting n, String a) {
matriculation Code=m;
name=n;
address=a;
}
public String getName() { return name:
}
public String getCode()
return matriculationCode;
}
public String getAddress() {
return address;
}
abstract public int getLoan(): abstract public String getStatus():
}
11. PROGRAM USING ABSTRACTION CLASS
// C++ Program to Demonsate the
// working of Abstraction
#include <iostream>
using namespace std;
class implementAbstraction {
private:
int a, b;
public:
// method to set values of
// private members
void set(int x, int y)
{
a = x;
b = y;
}
12. void display()
{
cout << "a = " << a << endl;
cout << "b = " << b << endl;
}
};
int main()
{
implementAbstraction obj;
obj.set(10, 20);
obj.display();
return 0;
}
Output
a = 10
b = 20
13. ….You can see in the above program we are not allowed to access the
variables a and b directly, however, one can call the function set() to set
the values in a and b and the function display() to display the values of a
and b.
14. APPLICATIONS OF ABSTRACTION
1. Abstraction increases the reusability of the code because of the proper
partitioning.
2. It reduces the complexity as well as the redundancy of the code, hence increasing
the readability.
3. Using classes and objects increases the security of the code.We can declare the
parts of the code as private to keep them secure.
4. Due to abstraction, the important parts of the code are secure as only the
essential features are provided to the user and they don’t know the background
details.
5. Since the programmer can use the same code repeatedly, it helps us perform
similar tasks for similar operations.
6. Abstraction allows changing internal implementations without affecting its user-
level code.
15. CONSIQUENCIES OF ABSTRACTION
Naturally, abstractions are a "good thing" for the most part, but if they're badly done,
they can be disasterous. Even if they're well-done, they have a cost as relates to raw
performance:
• Simple speed. In order to execute an abstraction, the code implementing needs to
handle cases and situations which may not always be needed - or often aren't
needed - by many usage scenarios.This will typically make code using the
abstractions slower than it would be if the code directly implemented the operation
without using the abstraction.
• Code size.This rarely matters on larger systems nowadays, but it can be a significant
problem in small devices or constrained environments.The extra code needed to
fully implement an abstraction adds linecount and ultimately code size, and if the
code isn't carefully implemented, can end up "pulling in" lots of extra code, leading to
overlarge runtime executables and ultimately making the device itself more
expensive.