Home | | Computer Science 11th std | C++: Dynamic initialization of Objects

Example Program in C++ - C++: Dynamic initialization of Objects | 11th Computer Science : Chapter 14 : Classes and objects

Chapter: 11th Computer Science : Chapter 14 : Classes and objects

C++: Dynamic initialization of Objects

When the initial values are provided during runtime then it is called dynamic initialization.

Dynamic initialization of Objects

 

When the initial values are provided during runtime then it is called dynamic initialization.

 

Illustration14.28 to illustrate 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;

}

Output:

Enter the Roll Number 1201

Enter the Average 98.6

Roll numbe:- 1201

Average :- 98.6

 

Tags : Example Program in C++ , 11th Computer Science : Chapter 14 : Classes and objects
Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
11th Computer Science : Chapter 14 : Classes and objects : C++: Dynamic initialization of Objects | Example Program in C++

Related Topics

11th Computer Science : Chapter 14 : Classes and objects


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.