Code :
#include <iostream>
using namespace std;
void printMenu()
{
cout << "\n\nplease choose from the
following Menu :\n";
cout << "1. Populate array with 5
elements.\n";
cout << "2. Print Array.\n";
cout << "3. Reverse Array.\n";
cout << "0. Exit\n\n";
cout << "Enter choice : ";
}
void Swap(int *a, int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}
void populateArray(int * A, int
n)
{
cout << "\nEnter the values of the array :
";
for(int i = 0; i < n; i ++)
{
cin >> A[i];
}
}
void printArray(int *A, int n)
{
for(int i = 0; i < n; i++)
{
cout << A[i]
<< " ";
}
cout << "\n";
}
void reverseArray(int *A, int n)
{
for(int i = 0; i < n/2; i++)
{
Swap(&A[i],
&A[n-1-i]);
}
}
int main()
{
int choice;
int *A = (int *)malloc(5*sizeof(int));
do
{
printMenu();
cin >>
choice;
if(choice == 1)
{
populateArray(A, 5);
}
else if(choice ==
2)
{
printArray(A, 5);
}
else if(choice ==
3)
{
reverseArray(A, 5);
}
}while(choice != 0);
return 0;
}
Output :


******************NOTE******************
If there is any problem with the code.. or If you have some
doubts... please ask in the comments. :)
If everything is good, please rate positively ... as it directly
affects our payscale :)
dont use switch E) 120 pts.] Write another function int main ) in C++(and comment the...
Write a program that will do the following. The main function should ask the user how many numbers it will read in. It will then create an array of that size. Next, it will call a function that will read in the numbers and fill the array (fillArray). Pass the array that was made in themain function as a parameter to this function. Use a loop that will read numbers from the keyboard and store them in the array. This...
Done in C++ using visual studio 1. Write a program with one additional function called int[] reverseArray(int array). This function will receive an array from main and then reverse and should return the reversed array to the main to print out. Use a single array and a single loop, you’re are neither allowed to print out just in reverse order nor allowed to use another array variable to store the original array in reverse order. 2. Write a program which...
You will create a program with two methods, the main() method of course and another method called printArray(). The main method will define an array of 5 elements. A loop will be used to prompt the user to enter 5 numeric values which will go into the 5 array elements. The main() method will then call the printArray() method passing the array by reference, and the array length by value. The printArray() method will then print the contents of the...
C++ Write a function called reverseArray(char[] , int) that accepts in an array of chars and the size of the array.as parameters. The function should then create a new array that is the same size as the original array. The function should copy the elements from the first array into the second array in reverse order. So if the initial array is {'a' , 'b', 'c'} then the new array will be {'c', 'b', 'a'} Then in your main(), create...
in c++ please Assignment Instructions: MAIN FUNCTION: Ask the user how many students were surveyed. Call a function called makeArray to define an array of integers with the number of elements equal to the number of students surveyed. Call a function called getStudentData to allow the user to enter the number of hours each student spent watching Netflix into the array. Call a function called getAverage to calculate and display the average of the hours entered. Call a function called...
Write a C Program that inputs an array of integers from the user along-with the length of array. The program then prints out the array of integers in reverse. (You do not need to change (re-assign) the elements in the array, only print the array in reverse.) The program uses a function call with array passed as call by reference. Part of the Program has been given here. You need to complete the Program by writing the function. #include<stdio.h> void...
C++: Write a recursive function that displays the contents of an array in reverse order (from the bottom up). The function declaration may look something like this: void displayReverse(char list[], int size, int startingIndex); The parameters are described as follows: list: The array to be displayed. size: The number of elements in the array. startingIndex: The element of the array currently being examined by the algorithm. The call to the function from main should look something like this, assuming that...
Programming Fundamental (C++) Lab C++ Lab Ra'fat Amareh Faculty of Engineering and Information Technology Assignment Write a C++ program that performs the following: Prints on screen a selection menu as follow: a. Sin (x), Series b. Sum odd digit, Print Digits, Print Shape c. Array d. Exit If user presses a or A, the following sub menu should be displayed 1- Sin (x) (Program should solve the following series x - x'/3! + x®/5! – x/7...x"m!) 2- F (Program should...
Please design, write the code and create the requisite submission files in C++ for the following problem: A menu-driven program that offers the user 5 options as follows: Menu: 1. Display array 2. Add up all elements in the array and display that number. 3. Add 1 to each element in the array. 4. Swap the values in row one with the values in row three. 5. Exit In main(), declare and initialize a 2-dimensional array that contains 5 x...
C++ Program Int Main First Please Write one program that does the following: 1. 1. Ask the user for ten (10) grades, and store the data in an array. Compute the average of all the grades. Print the original ten grades and the average. a. Declare an integer array with the name of “grades” of size 10 in the main function. b. Create a function called “getGrades” that prompts the User for the grades and puts them in an integer array. i. The function will receive...