Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- using namespace std;
- int enterArr(int[], int);
- int reverseArr(int[], int, int[]);
- int uptobot(int[], int);
- void showArr(int[], int);
- int main() {
- int Arr[30], Arr2[30], n, ch;
- cout << "Enter Size of Array ";
- cin >> n;
- if (n > 30 || !cin || n < 0) {
- cout << "Error: Invalid input!";
- return 0;
- }
- do
- {
- cout << " MENU \n";
- cout << "1. Create array \n";
- cout << "2. Overwrite the array into another array \n";
- cout << "3. Listed in descending order \n";
- cout << "4. Display the arrays \n";
- cout << "5. Exit \n";
- do {
- cout << "\n Make your choice: ";
- cin >> ch;
- } while (ch < 1 || ch>5);
- switch (ch) {
- case 1:
- enterArr(Arr, n);
- system("cls");
- break;
- case 2:
- reverseArr(Arr, n, Arr2);
- cout << "\n Array copied to another array!\n";
- _getch();
- system("cls");
- break;
- case 3:
- uptobot(Arr2, n);
- cout << "\n Array reversed!";
- _getch();
- system("cls");
- break;
- case 4:
- cout << "Original Array:\n\n";
- showArr(Arr, n);
- cout << "\n\nCopied & Reversed Array:\n\n";
- showArr(Arr2, n);
- _getch();
- system("cls");
- break;
- }
- } while (ch != 5);
- return 0;
- }
- int enterArr(int arr[], int size) {
- for (int i = 0; i < size; i++) {
- cout << "Array[" << i << "] = ";
- cin >> arr[i];
- }
- return *arr;
- }
- int reverseArr(int arr[], int size, int arr2[]) {
- for (int i = 0; i < size; i++)
- arr2[i] = arr[i];
- return *arr2;
- }
- int uptobot(int arr[], int size) {
- for (int i = 0; i < size / 2; ++i) {
- int temp = arr[i];
- arr[i] = arr[size - i - 1];
- arr[size - i - 1] = temp;
- }
- return *arr;
- }
- void showArr(int arr[], int size) {
- for (int i = 0; i < size; i++)
- cout << "Array[" << i << "] = " << arr[i] << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement