Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
21 views

CPP File Complete

The document describes 12 experiments on object-oriented programming concepts in C++. The experiments cover topics like classes, objects, member functions, constructors, inheritance, operator overloading, templates and exception handling.

Uploaded by

Gaurav Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

CPP File Complete

The document describes 12 experiments on object-oriented programming concepts in C++. The experiments cover topics like classes, objects, member functions, constructors, inheritance, operator overloading, templates and exception handling.

Uploaded by

Gaurav Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 27

EXPERIMENT 1

OBJECTIVE:

Write a program that uses a class where the member functions are defined inside a
class.

BRIEF DESCRIPTION:

Member functions are defined inside a class and provide the behavior or actions that objects of
that class can perform. They are also referred to as methods. Member functions can access and
manipulate the data members (variables) of the class and can interact with other objects of the
same or different classes.

PRE-EXPERIMENT QUESTIONS:

1. What is Class and Object?


2. What is global variables.?
3. Difference between normal function and member function of the class?

CODE :
OUTPUT :

POST EXPERIMENT QUESTIONS:

1. Explain the oops, how it is used?


2. Explain the concepts of data members in class . ?
3.Explain object ?
EXPERIMENT 2

OBJECTIVE:
Write a program that uses a class where the member functions are defined outside a
class.

BRIEF DESCRIPTION:

Defining member functions outside the class in C++ is a way to separate the
declaration and implementation of the functions. This approach provides modularity
and improves code organization, especially when dealing with large classes.

To define a member function outside the class ,you need to follow these steps:-
1. Declare the member function inside the class declaration, including the
function's return type, name, and parameters.
2. Outside the class declaration, use the scope resolution operator followed by the
class name and the member function's name to indicate that you are defining
the function belonging to that class.
3. Provide the function definition, including the return type, name, and
parameters, just as you would for any other function.
4. Implement the function's logic within the definition. You can access the class's
private members and perform any necessary operations.

PRE EXPERIMENT QUESTIONS:

1. Explain the member function?


2. Difference between global and local variables of the class?
3. What are different member function in c++?

POST EXPERIMENT QUESTIONS:

1. Enumerate the difference between c++ and java. ?

2. What are various data types in c++

3.What is data hiding ?

4. What is Encapsulation.?
CODE :

OUTPUT :
EXPERIMENT : 3

OBJECTIVE:

Write a program to demonstrate the use of static data members.

BRIEF DESCRIPTION:

C++, a static data member is a class member that is shared among all instances
(objects) of the class. It is associated with the class itself rather than with individual
objects. Here's an overview of static data members in C++.

PRE-EXPERIMENT QUESTIONS:

l. What is Static Data Member?

2. What are the different ways of define data members?

CODE :
OUTPUT :

POST EXPERIMENT QUESTIONS:

1.How to define static data member .?

2.What is static ?
EXPERIMENT : 4

OBJECTIVE:

Write a program to demonstrate the use of const data members..

BRIEF DESCRIPTION:

In C++, a const data member is a class member whose value cannot be modified once
it is initialized. Here's an overview of const data members in cpp.

Declaration and Initialization:


A const data member is declared in the class declaration and must be initialized at the
point of declaration or in the constructor's initializer list. It is typically declared as
private to ensure that its value remains constant.

PRE EXPERIMENT QUESTIONS:

1. What are const?


2. what are the different types data members?
3. How to declare const data member in c++?

CODE :
OUTPUT :

POST EXPERIMENT QUESTIONS :

1. How to declare a const data type ?


2. What is the difference between static and const data members ?
EXPERIMENT: 5

OBJECTIVE:

Write a program to demonstrate the use of zero argument and parameterized


constructors.

BRIEF DESCRIPTION:
In C++, a parameterized constructor is a special member function of a class that is used to
initialize objects of that class with specific values. It accepts parameters as arguments,
allowing the caller to provide values during object creation. Here's an overview of
parameterized constructors:
Declaration and Definition: A parameterized constructor is declared within the class
declaration like any other member function. It has parameters corresponding to the
values needed to initialize the object. The constructor definition provides the
implementation for the constructor.

PRE EXPERIMENT QUESTIONS:


1. What is an constructor?
2. What are the various types of constructors in c+
+?

3.How can we determine the width and height of a


triangle using constructor ?

CODE:
OUTPUT :

POST EXPERIMENT QUESTIONS :

l. Explain how to set the constructor.


2. What is the difference between an constructor and destructor?
EXPERIMENT 6
OBJECTIVE :

Write a program to demonstrate the use of dynamic constructor.

BRIEF DESCRIPTION:
C++ provides different types of constructors, such as default constructors, parameterized
constructors, copy constructors, and move constructors. These constructors are called
implicitly based on the object creation syntax or specific scenarios.
Dynamic memory allocation in C++ involves the use of operators like new and delete to
allocate and deallocate memory at runtime. However, this is not directly related to
constructor.

PRE EXPERIMENT QUESTIONS:


l. What is the correct syntax of new and delete operator?

2. What id dynamic memory allocation?

3. What is memory management concepts?

CODE :
OUTPUT :

POST EXPERIMENT QUESTIONS :

1.What is pointer ?
2.What are steps to define pointer to pointer ?

EXPERIMENT : 7
OBJECTIVE:

Write a program to demonstrate the use of explicit constructor

BRIEF DESCRIPTION:

In C++, the explicit keyword is used to qualify a constructor declaration. It affects the
way the constructor is used for implicit type conversions. Here's an overview of
explicit constructors:

Implicit Type Conversions: By default, constructors that can be called with a single
argument can also be used for implicit type conversions. For example, if a class has a
constructor that takes an int parameter, it can be used to implicitly convert an int value to
an object of the class
PRE EXPERIMENT QUESTIONS:

1. How call a member function in c++?


2. What is explicit call?
3. How do we define constructor in c++?

CODE :

OUTPUT :

POST EXPERIMENT QUESTIONS :

1.What is implicit call?


2.Difference between implicit and explicit call in c++?
EXPERIMENT : 8

OBJECTIVE:

Write a program to demonstrate the use of initializer list

BRIEF DESCRIPTION:

In C++, the initializer list is a special syntax used in constructors to initialize the data
members of a class. It provides a concise and efficient way to initialize member variables
when an object is created. Here's an overview of the initializer list:
Syntax: The initializer list is placed after the constructor's parameter list and is
enclosed within parentheses. Each member variable is initialized using a comma-
separated list of member initializations.

Constructor(datatype value1,datatype value 2): datamember(value 1),


datamember(value 2);{
Body of function

PRE EXPERIMENT QUESTIONS:

1. What is data members?


2. What is an initializer list?

CODE :

OUTPUT :

POST EXPERIMENT QUESTIONS :

1. How to define data members in a constructor ?


2. What is an initializer list?
3. What are the features initializer list in c++?
EXPERIMENT : 9

OBJECTIVE:

Write a program to demonstrate the overloading of increment and decrement


operators.

BRIEF DESCRIPTION:

Operator overloading in C++ allows you to define the behavior of operators when
applied to user-defined types. It enables you to extend the functionality of operators
beyond their built-in capabilities. Here's an overview of operator overloading:

Syntax: Operator overloading is performed by defining a function ora method that is


associated with a specific operator. The function or method is invoked when the
corresponding operator is used with operands of the user-defined type.

PRE EXPERIMENT QUESTIONS:

Q1. What is operator overloading?

Q2. What isthe binary and unary operator?

CODE :
OUTPUT:

POST EXPERIMENT QUESTIONS :

Q1.Write a program to overload unary operators.

Q2. What is overloading?


EXPERIMENT : 10

OBJECTIVE:

Write a program to demonstrate the multilevel inheritance..

BRIEF DESCRIPTION:

In C++, multilevel inheritance is a type of inheritance where a derived class is derived


from another derived class. It involves creating a class hierarchy with multiple levels
of derived classes. Here's an overview of multilevel inheritance:

Syntax: In multilevel inheritance, each derived class serves as the base class for the
next level of derived class.

class A{

………

class B: public A {

………

Class C: public B {
……..

PRE EXPERIMENT QUESTIONS:

Q1. What is Inheritance ?

Q2. Which inheritance is most important explain.

CODE :

OUTPUT:
POST EXPERIMENT QUESTIONS :

Q1. Different types ofinheritance?

Q2. What is hybrid inheritance?

EXPERIMENT : 11
OBJECTIVE:

Write a program to demonstrate the exception handling..

PRE EXPERIMENT QUESTIONS:

1 What is an exception?

2. How to handle exception in c++?

.3 What is a try block?

CODE :
OUTPUT:

POST EXPERIMENT QUESTIONS:

1 What are the try and catch block?

2 How to find error?

3. What are the advantages of throw block?


EXPERIMENT : 12
OBJECTIVE:

Write a program to demonstrate the use of function template.

BRIEF DESCRIPTION:

Function templates in C++ provide a mechanism for writing generic functions that can
operate on different data types without explicitly specifying each type. They allow you
to define a blueprint for a function that can be instantiated with different types at
compile time.

PRE EXPERIMENT QUESTIONS:

1 What is generic programming?

2. Why do we need templates?

3. What is a class template?

CODE :
OUTPUT:

POST EXPERIMENT QUESTIONS:

1 Write a program to add int float values using template function?

2. Difference between class and function templates in c++.

3. What is STL in c++

4. What is an algorithm.h in STL.

You might also like