Lab 12
Lab 12
CLASS EEE-3
REG NO FA23-EEE-017
ASSIGNMENT-1
1. Answer these
A. Explain with suitable example, syntax of for loop in C++. And discuss
how it is di erent from C syntax.
B. Explain concept of abstract class.
C. State the use of scope resolution operator and its use in C++.
D. State use of new operator.
E. List and explain use of any four file mode parameters
F. Explain use of friend function with the help of suitable example.
G. Write a C++ program to swap two numbers using pointer
ANSWER
A. For Loop in C++:
Syntax:
Statements to be executed}
Example:
Di erences from C:
* Empty Body: C requires a semicolon after an empty loop body, while C++ doesn't.
* Range-Based for Loops: C++ has range-based for loops for iterating over containers,
which C lacks.
B) . Explain concept of abstract class
An abstract class is a class that cannot be instantiated directly. It serves as a blueprint for
other classes, defining common methods and attributes that derived classes must
implement. Abstract classes contain at least one pure virtual function, a function declared
with the virtual keyword and assigned the value 0. Derived classes must provide concrete
implementations for all inherited pure virtual functions
EXAMPLE
class Shape {
public:
};
public:
};
C. State the use of scope resolution operator and its use in C++.
ANSWER
The scope resolution operator (:) is used to access members of a class that are hidden by
other declarations within the same scope. It also allows you to access static members of a
class without creating an instance of the class.
Example:
int* ptr = new int;
*ptr = 10;
delete ptr;
class Human
{ private:
EyeColor IColor;
NAME personname;
public:
Output:
4.
class person
char name[20];
int id;
public:
void getdetails(){}
};
Program:
5. Write a C++ program to display number of objects created using static member.