//Program to Implement variable size array #include<iostream> using namespace std; class intern { int s,*arr,i; //s is size of an array public: intern() { s=0; //Initializing value of size equal to zero } void getvalue() //Function for taking value of size from user { cout<<"Enter the size of an array: "; //Taking value of size from user cin>>s; } void putvalue() //Function for displaying the size of an array entered by user { cout<<"Your array size is "<<s<<endl; } void create() //Function for creating memory block { arr=new int[s]; // Creating a variable length array using dynamic memory allocation operator "new" cout<<"Your array of size "<<s<<" is created"<<endl; } void getdata() //Function for taking values of an array { for(i=0;i<s;i++) { cout<<"\nEnter element to be inserted: "; //taking value from user cin>>arr[i]; } } void putdata() //Function for displaying array { for(i=0;i<s;i++) { cout<<"Your "<<i+1<<" element is "<<arr[i]<<endl; } } void destroy() //Function for destroying memory block { delete []arr; cout<<"Your memory block is destroyed"<<endl; } }; main() { intern i; i.getvalue(); i.putvalue(); i.create(); i.getdata(); i.putdata(); i.destroy(); return 0; }
Comments
Sagar
19-Oct-2019 01:14:17 PMSagar
19-Oct-2019 01:08:04 PM