dynamic constructor in c 2b 2b

Solutions on MaxInterview for dynamic constructor in c 2b 2b by the best coders in the world

showing results for - "dynamic constructor in c 2b 2b"
Ann
08 Sep 2017
1//dynamic constructor and application
2//code by Soumyadeep Ghosh
3//insta : @soumyadepp
4//linked in: https://www.linkedin.com/in/soumyadeep-ghosh-90a1951b6/
5
6#include <bits/stdc++.h>
7
8using namespace std;
9
10class Array
11{
12  int *a;
13  int size;
14  public:
15    Array(int n)
16    {
17      a=new int[n]; //dynamic constructor allocating memory for n integers
18      size=n;
19    }
20  void getarr()
21  {
22    for(int i=0;i<size;i++)
23    {
24      cin>>a[i];
25    }
26  }
27  void putarr()
28  {
29    for(int i = 0; i < size ; i++ )
30    {
31      cout<<a[i]<<" "<<;
32    }
33    cout<<endl;
34  }
35};
36
37
38int main()
39{
40  Array a(10);   //array of 10 integers
41  a.getarr();  //to accept 10 integers
42  a.putarr();  //to display 10 integers
43  return 0;
44}
45
46//thank you!