Sie sind auf Seite 1von 6

Name : Salman zulfiqar

Dept: BS-Cyber Security


Submitted To: Intructor Salman Khan
ENROLLMENT ID: 181241
ASSIGNMENT #1

OBJECT ORIENTED PROGRAMMING

DUE DATE:15/4/2019
QUESTION#1:
i. Encapsulation is a process of combining data members and functions in a single unit
called class. This is to prevent the access to the data directly, the access to them is
provided through the functions of the class
ii. Polymorphism is a feature of OOPs that allows the object to behave differently in
different conditions. In C++ we have two types of polymorphism:
1) Compile time Polymorphism – This is also known as static (or early) binding.
2) Runtime Polymorphism – This is also known as dynamic (or late) binding.
Iii) Inheritance is one of the feature of Object Oriented Programming System(OOPs), it
allows the child class to acquire the properties (the data members) and functionality (the
member functions) of parent class.

QUESTION #2:
A function is a block of statements that performs a specific task. Suppose you are building
an application in C language and in one of your program, you need to perform a same task
more than once.
return_type function_name (argument list)
{ Set of statements – Block of code
}

QUESTION#3:
return_type function_name (argument list)
{Set of statements – Block of code
}
1:
DIFFERENT return_type function_name (argument list)
{ Set of statements – Block of code
}
3:
return_type function_name (different argument list)
{
Set of statements – Block of code
}

QUESTION#4:
This pointer is used when the public member of a pointer is pointing towards the private
function with the same name.
Class a {
Private b;
Public:
b=4;
This b=b;
};

QUESTION#5:
Object-oriented programming is a programming paradigm that uses abstraction (in the form of
classes and objects) to create models based on the real world environment. An object-oriented
application uses a collection of objects, which communicate by passing messages to request
services. Objects are capable of passing messages, receiving messages, and processing data. The
aim of object-oriented programming is to try to increase the flexibility and maintainability of
programs. Because programs created using an OO language are modular, they can be easier to
develop, and simpler to understand after development

In procedural languages (i.e. C) these modules are procedures, where a procedure is a sequence of
statements. In C for example, procedures are a sequence of imperative statements, such as
assignments, tests, loops and invocations of sub procedures. These procedures are functions, which
map arguments to return statements.

QUESTION#6:
A reference variable allows us to create an alternative name for already defined variable.
It is introduced in C++. Once you define a reference variable that references already defined
variable then you can use any of them alternatively in the program. Both refer to the same
memory location. Thus if you change value of any of the variable it will affect both variables
because one variable reference to another variable.The general syntax of creating reference
variable is given below: Data-type & Referace_Name = Variable_Name;
QUESTION#7:
1) C is a structural or procedural programming language But C++ is an object oriented
programming language.
2) Emphasis is on procedure or steps to solve any problem and Emphasis is on objects
rather than procedure.
3) Functions are the fundamental building blocks but Objects are the fundamental
building blocks
4) C uses scanf() and printf() function for standard input and output but C++ uses cin>>
and cout<< for standard input and output.
5) C is a middle level language and C++ is a high level language.
6) C program file is saved with .C extension but C++ program file is saved with .CPP
extension.

QUESTION#8:
Pointers are used in C++ program to access the memory and manipulate the address.
#include <iostream>
using namespace std;
int main()
{ int var1 = 3;
int var2 = 24;
int var3 = 17;
cout << &var1 << endl;
cout << &var2 << endl;
cout << &var3 << endl;}

QUESTION#9:
Function overloading is a feature in C++ where two or more functions can have the same
name but different parameters. Function overloading can be considered as an example of
polymorphism feature in C++.Following is a simple C++ example to demonstrate function
overloading.
Example:
#include <iostream>
using namespace std;
void print(int i) {
cout << " Here is int " << i << endl;
}
void print(double f) {
cout << " Here is float " << f << endl;

}
void print(char const *c) {
cout << " Here is char* " << c << endl;
}
int main() {
print(10);
print(10.10);
print("ten");
return 0; }

QUESTION#10:
QUESTION#11:
The inline functions are a C++ enhancement feature to increase the execution time of a
program. Functions can be instructed to compiler to make them inline so that compiler can
replace those function definition wherever those are being called. Compiler replaces the
definition of inline functions at compile time instead of referring function definition at
runtime.
EXAMPLE:
Class A
{
Public:
inline int add(int a, int b)
{ return (a + b);
};
}Class A
{public:
int add(int a, int b);
};
inline int A::add(int a, int b)
{ return (a + b);
}

Das könnte Ihnen auch gefallen