You are on page 1of 13

DAYANANDA SAGAR COLLEGE OF ENGINEERING

Shavige Malleshwara Hills, Kumaraswamy Layout, Bengaluru, Karnataka 560078


DEPARTMENT OF MEDICAL ELECTRONICS

Scheme & Solution


Date: 01.10.2018
Semester : V Subject: OOPs Using C++
Faculty Name: Prof. Pushpa Latha B G Subject Code : ML54
IA No: 01 Maximum Marks : 50

Q No Solution Marks

1. i. C
ii. The capability of a class to derive properties and characteristics from another class 1*10
is called Inheritance. =10
iii. A
iv. B
v. B
vi. C
vii. B
viii. B
ix. An Object is an instance of a Class
x. C

2. The main features of Object Oriented Programming in C++ are:


1. Objects
2. Classes
3. Abstraction
4. Encapsulation
5. Inheritance
6. Overloading
7. Exception Handling

Objects
Signature of the Faculty
Page No
Objects are the basic unit of OOP. They are instances of class, which have data members
and uses various member functions to perform tasks.
Class
It is similar to structures in C language. Class can also be defined as user defined data type
but it also contains functions in it. So, class is basically a blueprint for object. It declare &
defines what data variables the object will have and what operations can be performed on
the class's object.
Abstraction
Abstraction refers to showing only the essential features of the application and hiding the
details. In C++, classes can provide methods to the outside world to access & use the data
variables, keeping the variables hidden from direct access, or classes can even declare
everything accessible to everyone, or maybe just to the classes inheriting it. This can be
done using access specifiers.
Encapsulation
It can also be said data binding. Encapsulation is all about binding the data variables and
functions together in class.
Inheritance
Inheritance is a way to reuse once written code again and again. The class which is inherited
is called the Base class & the class which inherits is called the Derived class. They are also
called parent and child class.
So when, a derived class inherits a base class, the derived class can use all the functions
which are defined in base class, hence making code reusable.
Polymorphism
It is a feature, which lets us create functions with same name but different arguments, which
will perform different actions. That means, functions with same name, but functioning in
different ways. Or, it also allows us to redefine a function to provide it with a completely
new definition. You will learn how to do this in details soon in coming lessons.

3. The basic data types in C++ are listed below

Type Keyword
Boolean bool
Character char
Integer int
Signature of the Faculty
Page No
Floating point float
Double floating point double
Valueless void
Wide character wchar_t

Basis Of
Sl.No C C++
Distinction
C++ is an object-oriented programming
C is a structural or language and supports Polymorphism,
4. A Nature Of procedural type of Abstract Data Types, Encapsulation, among
1
Language programming others. Even though C++ derives basic
language. syntax from C, it cannot be classified as a
structural or a procedural language.
C lays emphasis on
the steps or C++ emphasizes the objects and not the
Point Of
2 procedures that are steps or procedures. It has higher abstraction
Emphasis
followed to solve a level.
problem.
Compatibility C++ supports function overloading,
C does not support
3 With implying that one can have name of
function overloading.
Overloading functions with varying parameters.
C does not provide
String or Boolean C++ provides Boolean or String data types.
4 Data Types data types. It It supports both user-defined and built-in
supports primitive & data types.
built-in data types.
C does not support
Compatibility
Exception Handling
With C++ supports Exception Exception:Handling
5 directly. It can be
Exception can be done through try & catch block.
done through some
Handling
other functions.
Compatibility C does not support
C++ supports functions with default
6 With functions with
arrangements.
Functions default arrangements

Signature of the Faculty


Page No
Compatibility
C++ is compatible with generic
7 With Generic C is not compatible
programming
Programming
Pointers And C supports only
8 C++ supports both pointers and references.
References Pointers
Inline C does not have
9 C++ has inline function.
Function inline function.
In C programming
Data is hidden in C++ and is not accessible
10 Data Security language, the data is
to external functions. Hence, is more secure
unsecured.
C follows the top-
11 Approach C++ follows the bottom-up approach.
down approach.

The following phases are essential for the execution of C++ program
1. Create
2. Save
3. Compile
4. Execute

1. Create : editor, write the program


2. Save: save using .cpp extension. It includes preprocessor directives
3. Compile: errors are identified, successful compilation – progam will be stored
4. B using .obj file
4. Execute: Links all the necessary library functions, executes the program
Operators are special type of functions, that takes one or more arguments and produces a
new value. For example : addition (+), substraction (-), multiplication (*) etc, are all
operators. Operators are used to perform various operations on variables and constants.

Scope resolution operator (::) in C++ programming language is used to define a function
5. A outside a class or when we want to use a global variable but also has a local variable with

Signature of the Faculty


Page No
the same name.
#include <iostream>
using namespace std;
class programming
{
public:
void output(); //function declaration
};
// function definition outside the class
void programming::output()
{
cout << "Function defined outside the class.\n";
}
int main()
{
programming x;
x.output();
return 0;
}
Output of program:

/*C++ program to create student class, read and print N student's details
(Example of array of objects).*/
#include <iostream>
using namespace std;
#define MAX 10
class student
{
private:
5. B
char name[30];
Signature of the Faculty
Page No
int rollNo;
int total;
float perc;
public:
//member function to get student's details
void getDetails(void);
//member function to print student's details
void putDetails(void);
};

//member function definition, outside of the class


void student::getDetails(void){
cout << "Enter name: " ;
cin >> name;
cout << "Enter roll number: ";
cin >> rollNo;
cout << "Enter total marks outof 500: ";
cin >> total;
perc=(float)total/500*100;
}//member function definition, outside of the class
void student::putDetails(void){
cout << "Student details:\n";
cout << "Name:"<< name << ",Roll Number:" << rollNo << ",Total:" << total <<
",Percentage:" << perc;
}
int main()
{
student std[MAX]; //array of objects creation
int n,loop;
cout << "Enter total number of students: ";
cin >> n;
for(loop=0;loop< n; loop++){
cout << "Enter details of student " << loop+1 << ":\n";

Signature of the Faculty


Page No
std[loop].getDetails();
}
cout << endl;
for(loop=0;loop< n; loop++){
cout << "Details of student " << (loop+1) << ":\n";
std[loop].putDetails();
}
return 0;
}
Output
Enter total number of students: 2
Enter details of student 1:
Enter name: Mike
Enter roll number: 101
Enter total marks outof 500: 456
Enter details of student 2:
Enter name: Mock
Enter roll number: 102
Enter total marks outof 500: 398
Details of student 1:
Student details:
Name:Mike,Roll Number:101,Total:456,Percentage:91.2Details of student 2:
Student details:
Name:Mock,Roll Number:102,Total:398,Percentage:79.6

Signature of the Faculty


Page No
Signature of the Faculty
Page No
5. B

Signature of the Faculty


Page No
Q no Solution Marks

Signature of the Faculty


Page No
Q no Solution Marks

Signature of the Faculty


Page No
Questi
on
Solution Marks
Numb
er

Signature of the Faculty


Page No
Signature of the Faculty
Page No

You might also like