CPP File Complete
CPP File Complete
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:
CODE :
OUTPUT :
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.
4. What is Encapsulation.?
CODE :
OUTPUT :
EXPERIMENT : 3
OBJECTIVE:
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:
CODE :
OUTPUT :
2.What is static ?
EXPERIMENT : 4
OBJECTIVE:
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.
CODE :
OUTPUT :
OBJECTIVE:
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.
CODE:
OUTPUT :
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.
CODE :
OUTPUT :
1.What is pointer ?
2.What are steps to define pointer to pointer ?
EXPERIMENT : 7
OBJECTIVE:
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:
CODE :
OUTPUT :
OBJECTIVE:
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.
CODE :
OUTPUT :
OBJECTIVE:
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:
CODE :
OUTPUT:
OBJECTIVE:
BRIEF DESCRIPTION:
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 {
……..
CODE :
OUTPUT:
POST EXPERIMENT QUESTIONS :
EXPERIMENT : 11
OBJECTIVE:
1 What is an exception?
CODE :
OUTPUT:
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.
CODE :
OUTPUT: