Write a menu controlled program with the functions below. Note: call the functio
ID: 3635305 • Letter: W
Question
Write a menu controlled program with the functions below. Note: call the function input_array(a,n)prior to the menu, then display the following menu:
1- Read array (a)
2- Display array (a)
3- Reverse array (a) starting from n
4- Copy array (a1) to (a2)
5- Rotate array (a) from n1 to n2
6- Quit
For each menu option the following function will be called.
1- A function "input_array(a,n)" which allows the user to input a string
2- A function "display_array(a,n)" which displays the values of the first n elements of
the array a on the screen.
3- A function "reverse_display_array(a,n)" which displays the values of the first n
elements of the array a on the screen in reverse order.
4- A function "copy_array(a1,a2,n)" which copies the first n elements of a1 to the
respective first n elements in a2.
5- A function "rotate_array(a,n1,r,n2)" which rotates r elements starting from the
position n1 of array a to the position starting from n2 in the same array a. EX:
rotate_array(a1,10,3,1)
C
S
1
4
0
P
R
O
G
R
A
M
R
A
M
C
S
1
4
0
P
R
O
G
Explanation / Answer
#include<iostream.h>
input array(a,n);
void main()
{
int a[n];
input array(a,n);
}
input array(a,n)
{
int ans,b[100],n;
cout<<"ENTER THE CHOICE"
cout<<"1. READ 2.DISPLAY 3.REVERSE 4.COPY 5. QUIT"
while(ans<=6)
{
if(ans==1)
cout<<"ENTER THE SIZE"
cin>>n;
cout<<"ENTER ELEMENTS IN ARRAY"
for(int i=0;i<n;i++)
{
cin>>a[i]
}
}
if(ans==2)
{
for(int i=0;i<n;i++)
{cout<<a[i];
}
}
if(ans==3)
{
for(int i=n;i>1;i--)
cout<<a[i];
}
if(ans==4)
{for(int i=0;i<n;i++)
{
b[i]=a[i];}
if(ans==5)
{exit 0;
}
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.