Answer to Question #227687 in C++ for Ayesha

Question #227687

Write a c++ program that makes a dynamic array and uses an integer to checks its size. Enter numbers in it until the user presses 4. Create another array and copy the contents of first array into the new array and delete the memory of 1st array. Also print as you insert the values.


1
Expert's answer
2021-08-22T07:16:08-0400
#include<iostream>
using namespace std;
int main()
{
  int size,n,i,a,m;
  int finA[17]={};
  int initA[]={10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170};
  n = sizeof(initA)/sizeof(initA[0]);
  cout << "The size of the array is: " << n<<endl;
  cout<<"Input the elements of the first array: "<<endl;
  for(i=0;i<n;i++)
        {
        	  cin>>a;
               if(a==4){
               	break;
			   }
        }
     for(m=0;m<n;m++)
       {
            finA[m]=initA[m];
        }
      cout<<"The final array is\n";
      for(m=0;m<=n;m++)
       cout<<finA[m]<<" "<<endl;


  delete [] initA;


  return 0;
}

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