Answer to Question #239528 in C++ for Brand

Question #239528

WAP to create a class which stores a dynamic integer array and its size. Include all

the constructors and destructor in the class. Store two arrays of different size in

two objects. Join the two arrays and and store it in another object using a member

function.


1
Expert's answer
2021-09-20T03:00:17-0400
#include<iostream>
using namespace std;
class dynamicArray{
	private:
		int arr[];
		int limit;
	public:
		dynamicArray(){
			
		}
		
		dynamicArray(int max){
			limit = max;
			arr[limit];
		}
		int getLimit(){
			return limit;
		}
		void join_2_arrays(){
		  cout<<"Enter the size of the first array:\n";
		  int n;
		  cin>>n;
		  cout<<"Enter the size of the second array:\n";
		  int m;
		  cin>>m;
		  
		   int arr1[n];
		cout<<"Enter elements of the first array: ";
			for(int i=0; i<n; i++){
				cout<<"Element: "<<(i+1)<<endl;
				cin>>arr1[i];
			}
			int arr2[m];
			cout<<"Enter elements of the second array: \n";
			for(int i=0; i<m; i++){
				cout<<"Element: "<<(i+1)<<endl;
				cin>>arr2[i];
			}
			cout<<"Elements of the first array are: \n";
			for(int i=0; i<n; i++){
				cout<<"Element "<<(i+1)<<" :"<<arr1[i]<<endl;
			}
			cout<<"Elements of the second array are: \n";
			for(int i=0; i<m; i++){
				cout<<"Element "<<(i+1)<<" :"<<arr2[i]<<endl;
			}
			int a =m+ n;
			int arr3[a];
			for(int i=0; i<n; i++){
				arr3[i] = arr1[i];
			}
			int x = a- 1;
			
			for(int i=0, j=x; i<m; i++, j-- ){
				arr3[j] = arr2[i];
			}
			cout<<"Elements of the third array are: \n";
			for(int i=0; i<a; i++){
				cout<<"Element "<<(i+1)<<" :"<<arr3[i]<<endl;	
			}
			
		}
		
	
	
		~dynamicArray(){
			cout<<"Destructor called\n";
		}
};


int main(){
	
	dynamicArray d;


	d.join_2_arrays();
	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS