0% found this document useful (0 votes)
3 views7 pages

Object Oriented Programming Imp

The document outlines the differences between C and C++, features of object-oriented programming (OOP), applications of OOP, differences between OOP and procedural programming (POP), access specifiers in C++, rules for naming variables, and includes example programs for checking even/odd numbers, computing factorials, and solving arithmetic operations. It emphasizes the object-oriented nature of C++ compared to the procedural approach of C. Key concepts such as classes, objects, encapsulation, and data abstraction are also discussed.

Uploaded by

mp8587247
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

Object Oriented Programming Imp

The document outlines the differences between C and C++, features of object-oriented programming (OOP), applications of OOP, differences between OOP and procedural programming (POP), access specifiers in C++, rules for naming variables, and includes example programs for checking even/odd numbers, computing factorials, and solving arithmetic operations. It emphasizes the object-oriented nature of C++ compared to the procedural approach of C. Key concepts such as classes, objects, encapsulation, and data abstraction are also discussed.

Uploaded by

mp8587247
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

OBJECT ORIENTED PROGRAMMING USING C++

Unit - 1 IMP
Difference between C and C++ marks : 4
Ans :
Sr. C C++
no
1. C language is a top-down structured C++ is bottom-up object oriented
programming language. programming language.
2. C language programs are saved with C++ programs are saved with .cpp file
.C file extension. extension.
3. When compared to C++, C is a subset of C++ is a superset of C. C++ can run most of
C++ C code while C cannot run C++ code.
4. In C language, scanf() and printf() are used In C++ language, cout and cin are used as
as I/O functions. The header file required Input/Output (I/O) facility. The header file
to include for this purpose is, "stdio.h". required to include for this purpose is
"iostream.h".
5. C language requires format specifier for C++ language does not require format
printing and scanning variables. specifier for printing and scanning
variables.

6. C is a function-driven language. C++ is object-driven language.


7. C language is a middle level language. C++ is a higher level language.

8. C does not support function and operator c++ supports function and operator
overloading. overloading

FEATURES OF OOP MARKS : 4


Ans :
OBJECTS : Objects are the basic run-time entities in an OOP environment. Any real-world
object can be treated as an object in the OOP, such as a car, a person, a university building, a
table, a computer etc.
An object is an instance of a class. An object consists of two characteristics namely, state
(attribute) and behavior (operation).

Classes : a class is a way of grouping objects having similar characteristics. A class is a user-
defined data type, which represents a group of similar objects. A class provides a template or
plan or blue prints to create objects of particular type.

Data encapsulation : Encapsulation is the way to implement data abstraction in OOP. A well-
encapsulated object acts as a 'black box' for other parts of the program i.e., it provides services
to the external functions or other objects that interact with it.

Data Abstraction : each object will have external interfaces through which it can be used.
There is no need to look into its inner details. So, the user needs to know the external interfaces
only, to make use of an object.
APPLICATIONS OF OOP Marks : 4
Ans :
1. Simulations and Modelling (S&M): Simulation and Modelling is the technique of
representing the real-world entities with the help of a computer program.

2. Scripting: OOP has also been used for developing HTML, XHTML and XML documents
for the Internet, Python, Ruby and Java are the languages based on object-oriented principles
which are used for scripting.

3. User Interface Design: This is the popular application of OOP in the area of designing
Graphical User Interfaces (GUIs) such as Windows. C++ is mainly used for developing User
Interfaces (UIs).

4. Object Databases: These databases store the data directly in the form of objects, however,
these OOP databases are not as popular as the traditional RDBMS.

5. Developing Computer Games and Virtual Reality: OOP is also used for developing
computer games such as Diablo and WarCraft III. Those games offer virtual reality
environments in which a number of objects interact with each other in complex ways to give
the desired result.

Difference between OOP and POP MARKS : 4


Ans :
SR. OOP POP
NO
1 Object oriented programming language is Procedural programming languages action
object oriented. oriented.
2 OOP trace on data. POP trace on procedures.
3 OOP follow Bottom-up approach in POP follow Top-down approach in program
program design. design.

4 Basic building block of OOP is object. In Basic building block of POP is function. In
OOP program is decomposed into a POP program is decomposed into a number of
number of meaningful units known as functions or procedures.
objects.
5 In OOP object is collection of data and In POP function is a collection of instruction
members. that performs a specific task.
6 OOP provides data hiding so provides POP does not have any proper way for hiding
more security. data so it is less secure.
7 Examples of OOP includes C++, JAVA, Examples of POP includes C,VB,
VB.NET, C#.NET etc. FORTRAN, COBOL, PASCAL etc.
8 In OOP, objects communicate through In POP functions communicates each other
member functions. through arguments.
9 OOP is a data centric language. POP is procedure centric language.
Explain the access specifiers in C++ Marks : 4
Ans :
1. Public
The public keyword is an access specifier.
The members are public - which means that they can be accessed and modified from outside the
code:
Example: class MyClass //the class
{
public: //access specifier
};
2. Private‍
Private members are accessible only within the class they are declared in. They cannot be
accessed by derived classes or other parts of the program, ensuring data hiding and
encapsulation.

Example: class MyClass //the class


{
Private: //access specifier
};

3. Protected‍
Protected members are like members but can also be accessed by classes that inherit from them.
They are kept hidden from the rest of the program.

Write the syntax for Declaration of a class marks : 2

Ans : The keyword 'class' is used to declare a class in C++. The declaration of a class always
ends with the semicolon (;). All data members and member functions are declared within the
braces (and) which are called the body a class.

 General syntax for declaration of a class is given below :


Explain the Structure of c++ Program. Marks : 4

Ans : A computer program is a sequence of instructions or statements that tells the computer
what to do.

These statements/instructions form the structure of a C++ program.

A C++ program is a text file containing a sequence of C++ commands (instructions) put
together according to the laws of C++ grammar or syntax rules.

C++ text file is known as the source file. A C++ source file carries the file extension.cpp.

Explain the rules for naming variables in C++ marks : 4

Ans : 1. The name of a variable should be a unique and a valid C++ identifier.

2. Variables name can be as short as a single letter and first 32 characters can be considered.

3. Do not use keywords as variable names.

4. Variable names must begin with a letter of the alphabet or an underscore ().

5. No blank space is allowed in a variable name.


Program to check whether number is Even or Odd using if...else statement.

#include <iostream> Marks : 4

using namespace std;

int main()

int n;

cout << "Enter an integer: ";

cin >> n;

if (n % 2 == 0)

cout << n << " is even.";

else

cout << n << " is odd.";

return 0;

}
Program to compute factorial of a number using for loop. Marks : 4

#include <iostream>

using namespace std;

int main()

int number, i = 1, factorial = 1;

cout << "Enter a positive integer: ";

cin >> number;

while (i <= number)

factorial*= i;

++i;

cout<<"Factorial of "<< number <<" = "<< factorial;

return 0;

}
Write program to solve arithmetic operators. Marks : 4

#include <iostream>

using namespace std;

int main()

int a = 21;

int b = 10;

int c;

c = a+b;

cout << "Value of c is :"<<c<<endl;

c = a - b;

cout << "Value of c is :"<<c<<endl;

c = a*b;

cout << "Value of c is :"<<c<<endl;

c = a/b;

cout << "Value of c is :"<<c<<endl;

c = a%b;

cout << "Value of c is :"<<c<<endl;

c = a++;

cout << "Value of c is :"<<c<<endl;

c = a--;

cout << "Value of c is :"<<c<<endl;

return 0;

You might also like