Dynamic
initialization of Objects
When
the initial values are provided during runtime then it is called dynamic
initialization.
#include<iostream>
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;
}
Enter the Roll Number 1201
Enter the Average 98.6
Roll numbe:- 1201
Average :- 98.6
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.