मराठी
तामिळनाडू बोर्ड ऑफ सेकेंडरी एज्युकेशनएचएससी विज्ञान इयत्ता ११

Write with example how will you dynamically initialize objects?

Advertisements
Advertisements

प्रश्न

Write with example how will you dynamically initialize objects?

थोडक्यात उत्तर
Advertisements

उत्तर

Dynamic initialization of Objects:

When the initial values are provided during runtime then it is called dynamic initialization.
Program to illustrate dynamic initialization
#include
using namespace std;
class X
{
int n;
float avg;
public:
X(int p,float q)
{
n=p;
avg=q;
}
void disp( )
{
cout<<“\n Roll numbe:-” <<n;
cout<<“\nAverage :-“<<avg;
}
};
int main( )
{
int a ; float b;
cout<<“\nEnter the Roll Number”;
cin>>a; .
cout<<“\nEnter the Average”;
cin>>b;
X x(a,b); // dynamic initialization
x.disp( );
return 0;
}
Output:

Enter the Roll Number 1201
Enter the Average 98.6
Roll number:- 1201
Average :- 98.6

shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 14: Classes and objects - Evaluation - Section - C [पृष्ठ २४७]

APPEARS IN

सामाचीर कलवी Computer Science [English] Class 11 TN Board
पाठ 14 Classes and objects
Evaluation - Section - C | Q 2. | पृष्ठ २४७
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×