Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Nattapong Aphayavong
- //
- // Chapter 6 & 7 Assignment
- //
- // February 15,2019
- #include "pch.h"
- #include <iostream>
- #include <iomanip>
- using namespace std;
- //GLOBAL CONSTANTS
- const int COLS = 5;
- const int ROWS = 5;
- //MAX ARRAY SIZE
- const int SIZE = 25;
- //prototype functions
- int menu();
- void change(char naArray[][COLS]);
- void count(char naArray[]);
- void display(char naArray[][COLS]);
- void search(char naArray[]);
- const int swap = 1,
- vowels = 2,
- show = 3,
- searchArray = 4,
- leave = 5;
- int main()
- {
- //Variables
- char charArray[ROWS][COLS] = { {'s','l','o','a','n'},
- {'h','o','r','s','e'},
- {'e','g','r','i','t'},
- {'h','o','u','s','e'},
- {'w','a','t','e','r'} };
- int choice;
- int count = 0;
- do
- {
- choice = menu();
- switch (choice)
- {
- case show:
- display(charArray);
- break;
- case 1:
- change(charArray);
- break;
- }
- } while (choice != leave);
- }
- int menu()
- {
- int choice = 0;
- cout << "-----------------------------------------" << endl;
- cout << "Array Display: " << endl << endl;
- cout << "1. Swap Arrays" << endl;
- cout << "2. Total numbers of vowels" << endl;
- cout << "3.Diplay array" << endl;
- cout << "4.Search within the array" << endl;
- cout << "5. EXIT " << endl;
- cout << endl;
- cout << "Enter a option from 1-5: ";
- cin >> choice;
- return choice;
- }
- void change(char naArray[][COLS])
- {
- for (int y = COLS; y > 0; y--)
- {
- char exchange= naArray[y][2];
- naArray[y][2] = naArray[y][5];
- naArray[y][5] = exchange;
- }
- cout << endl;
- }
- void display(char naArray[][COLS])
- {
- for (int x = 0; x < ROWS; x++)
- {
- for (int y = 0; y < COLS; y++)
- {
- cout << setw(4) << naArray[x][y] << " ";
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement