You are on page 1of 12

ASSIGNMENT 1

Paper Code: BCA - 301


Paper Title: Object Oriented Programming using C++

Q1. What is procedure-oriented programming? What are its main characteristics?


Ans.
Ans:Conventional programming, using high level language such as COBOL, FORTAN and C is commonly known as
procedure oriented programming.
Characteristics :
a) Emphasis is on doing things (algorithms)
b) Large programs are divided into small programs known as function.
c) Most of the function share global data.
d) Data move openly around the system from function to function.
e) Function transform data from one form to another.

Q2. Differentiate between the fundamental and derive data types.


Ans.
Fundamental datatypes: These data types are those that are not composed of other data types.
These are of 5 types:
1.int data type(for integers).
2.char data type(for characters).
3.float data type(for floating point numbers).
4.double data type(for double precision floating-point numbers).
5.void data type(for empty set of values and non-returning functions).

Derived data types: From fundamental types other types can be derived by using the declaration operators.
These are of 5 types:
1.Arrays.
2.Functions.
3.Pointers.
4.References.
5.Constants.

Q3. Write the structure of a C++ program.


Ans.
Q4. Write the syntax of all looping statements.
Ans.

For Loop - syntax


for (<initial statement(s)>; <Condition expression>; <Repeat step(s)>)
{
<Loop statement(s)>;
}

While Loop - syntax


while (<Condition expression>)
{
<Loop statement(s)>;
}

Do-While Loop - syntax


do
{
<Loop statement(s)>;

}while (<Condition expression>);

Q5. What are the decision making and branching?


Ans.
Decision making is about deciding the order of execution of statements based on certain conditions or
repeat a group of statements until certain specified conditions are met. C language handles decision-
making by supporting the following statements,
• if statement

• switch statement

• conditional operator statement (? : operator)


• goto statement

SECTION B

Q1. Describe in details about the basic concepts of Object-oriented Programming


Ans.
Object Oriented programming is a programming style that is associated with the concept of Class, Objects
and various other concepts revolving around these two, like Inheritance, Polymorphism, Abstraction,
Encapsulation etc.

OOPS Concept Definitions


Now, let us discuss some of the main features of Object Oriented Programming which you will be using in
C++(technically).

1. Objects
2. Classes
3. Abstraction
4. Encapsulation
5. Inheritance
6. Overloading
7. Exception Handling
Objects
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
Q2. What is Compiler? Discuss the various C++ compilers
Ans.
A compiler is a special program that processes statements written in a particular programming language and turns them
into machine language or "code" that a computer's processor uses. Typically, a programmer writes language statements
in a language such as Pascal or C one line at a time using an editor.

Various C++ compilers


Solbourne
Solbourne C++ Cfront Translator and Native Compiler.
Microsoft
Microsoft C7 Compiler.
Lucid
Lucid C++ Compiler and Energize Programming System.
GNU
Gnu C++ Compiler.
AT&T
AT&T C++ Cfront Translator.
Zortech
Zortech C++ Compiler.
SCO
SCO C++ Cfront Translator.
Comeau
Comeau Computing C++.
Sun
SunPro's C++.
ObjectCenter
CenterLine Software Inc.
EDG
Edison Design Group.
Borland
Borland C++ Compiler.
Turbo
Turbo C++ Compiler.
LIANT
LIANT LPI-C++ Compiler.
Objectworks
Objectworks\C++ 2.4a from ParcPlace.
Oregon
C++ compiler marketed by Taumetric Corporation.
IBM
Some IBM C++ Compiler.
JPI
JPI Topspeed from Jensen and Partners Int.
ASSIGNMENT 2
SECTION 1
Q1. What is the array and initializing arrays?
Ans.

An array is a collection of a fixed number of values of a single type. For example: if you want to store
100 integers in sequence, you can create an array for it.

int data[100];

The size and type of arrays cannot be changed after its declaration.

Arrays are of two types:

1. One-dimensional arrays
2. Multidimensional arrays

Q2. What are class and function?


Ans.
Class

In the real world, you often have many objects of the same kind.

In object-oriented software, it's also possible to have many objects of the same kind that share
characteristics: rectangles, employee records, video clips, and so on. Like the bicycle
manufacturers, you can take advantage of the fact that objects of the same kind are similar and you
can create a blueprint for those objects. A software blueprint for objects is called aclass .

Method
A method is a member function of a class, but in C++ they are more commonly called member functions
than methods (some programmers coming from other languages like Java call them methods). A function is
usually meant to mean a free-function, which is not the member of a class

Q3. What is Pointer? Explain with examples.


Ans.
A pointer is a variable whose value is the address of another variable. Like any variable
or constant, you must declare a pointer before you can work with it. The general form of
a pointer variable declaration is −
type *var-name;

Here, type is the pointer's base type; it must be a valid C++ type and var-name is the
name of the pointer variable.
Q4. What are constructor and copy constructor?
Ans.
A constructor is a special method of a class or structure in object-oriented programming that initializes an
object of that type. A constructor is an instance method that usually has the same name as the class, and can
be used to set the values of the members of an object, either to default or to user-defined values.

The copy constructor is a constructor which creates an object by initializing it with an


object of the same class, which has been created previously. The copy constructor is used
to −

• Initialize one object from another of the same type.

• Copy an object to pass it as an argument to a function.

• Copy an object to return it from a function.

Q5. What are the function overloading and operator overloading?


Ans.
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++.

n C++, we can make operators to work for user defined classes. This means C++ has the ability to provide the
operators with a special meaning for a data type, this ability is known as operator overloading.
For example, we can overload an operator ‘+’ in a class like String so that we can concatenate two strings by
just using +.
Other example classes where arithmetic operators may be overloaded are Complex Number, Fractional
Number, Big Integer, etc.

SECTION 2

Q1.
(a) Write a program uses a nested for loop to find the prime numbers from 2 to 100.
(b) Define the do-while loop statements.

Ans.
a)
int i,j,s=0,d=0;

for(i=1;i<100;i++)

s=0;

for(j=1;j<=i;j++)

{
if(i%j==0)

s=s+1;

if(s==2)

Cout<<i<<endl;

d=d+1;

Cout<<”the no. of prime no. are = “<<d;

b)
A do...while loop is similar to a while loop, except that a do...while loop is guaranteed
to execute at least one time.

Syntax
The syntax of a do...while loop in C++ is −
do {
statement(s);
}
while( condition );

Q2.
What are the difference forms of inheritance? Explains with an example program.
Ans.
C++ supports six types of inheritance as follows:

• Single Inheritance
• Multilevel Inheritance
• Multiple Inheritance
• Heirarchical Inheritance
• Hybrid Inheritance
• Multipath Inheritance

Single Inheritance
A derived class with only one base class is called single inheritance.
Multilevel Inheritance
A derived class with one base class and that base class is a derived class of another is
called multilevel inheritance.

Multiple Inheritance
A derived class with multiple base class is called multiple inheritance.
Heirarchical Inheritance
Multiple derived classes with same base class is called hierarchical inheritance.

Hybrid Inheritance
Combination of multiple and hierarchical inheritance is called hybrid inheritance.
Multipath Inheritance
A derived class with two base classes and these two base classes have one common base class is
called multipath inheritance.More info.

Example
Class one
{
Void displayone()
{
Cout<<”This Is display of class one”<<endl;
}
}
Class two : public one
{
Void displaytwo()
{
Cout<<”this is display function of class two”<<endl;
}
}

Void main()
{
Two k;
k.displayone();
k.displaytwo();
}

You might also like