g Write a method named mirror that accepts an ArrayList of strings as a parameter and produces a mirrored copy of the list as output, with the original values followed by those same values in the opposite order. For example, if an ArrayList variable named list contains the values ["a", "b", "c"], after a call of mirror(list); it should contain ["a", "b", "c", "c", "b", "a"]. You may assume that the list is not null and that no element of the array is null

Respuesta :

Answer:

#include<iostream>

#include<conio.h>

using namespace std;

void mirrorarray(char a[5],int n);

main()

{

int n;

cout<<"enter the size of array"<<endl;

cin>>n;

char a[n], b[n],c[2*n];

 

for (int i=0;i<=4;i++)

{

 cout<<"\nenter the characters in array";

 cin>>a[i];

}

mirrorarray(a,n);

getch();  

}

void mirrorarray(char a[5],int n)

{

char b[n],c[2*n];

int k=0;

for (int j=4; j>=0; j--)

{

b[j]=a[k];  

k=k+1;

 

}

 

for (int k=0;k<=4;k++)

{

 c[k]=a[k];

 c[k+5]=b[k];

 

}

 for (int l=0;l<=9;l++)

{

 cout<<c[l];

}

 

}

Explanation:

In this program, an array of variable length n is taken. A function (method) is named as mirrorarray is designed to reverse the order of array and combine it with original array to make its mirror.

All arrays are considered as character data type, to full fill the requirement of question that elements should be string or character as parameter. The original array and mirror array are combined together in the end and displayed on output.

ACCESS MORE