daily pastebin goal
2%
SHARE
TWEET

Untitled

a guest Feb 17th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. // Nattapong Aphayavong
  3. //
  4. // Chapter 6 & 7 Assignment
  5. //
  6. // February 15,2019
  7.  
  8. #include "pch.h"
  9. #include <iostream>
  10. #include <iomanip>
  11. using namespace std;
  12.  
  13.  
  14. //GLOBAL CONSTANTS
  15. const int COLS = 5;
  16. const int ROWS = 5;
  17.  
  18.  
  19. //MAX ARRAY SIZE
  20. const int SIZE = 25;
  21.  
  22. //prototype functions
  23. int menu();
  24. void change(char naArray[][COLS]);
  25. void count(char naArray[]);
  26. void display(char naArray[][COLS]);
  27. void search(char naArray[]);
  28.  
  29. const int swap = 1,
  30. vowels = 2,
  31. show = 3,
  32. searchArray = 4,
  33. leave = 5;
  34.  
  35.  
  36. int main()
  37. {
  38.     //Variables
  39.     char charArray[ROWS][COLS] = { {'s','l','o','a','n'},
  40.                                 {'h','o','r','s','e'},
  41.                                 {'e','g','r','i','t'},
  42.                                 {'h','o','u','s','e'},
  43.                                 {'w','a','t','e','r'} };
  44.  
  45.     int choice;
  46.     int count = 0;
  47.  
  48.     do
  49.     {
  50.         choice = menu();
  51.        
  52.         switch (choice)
  53.         {
  54.         case show:
  55.  
  56.             display(charArray);
  57.  
  58.             break;
  59.  
  60.         case 1:
  61.  
  62.             change(charArray);
  63.             break;
  64.         }
  65.        
  66.  
  67.  
  68.     } while (choice != leave);
  69.  
  70.  
  71.  
  72. }
  73.  
  74.  
  75. int menu()
  76. {
  77.     int choice = 0;
  78.  
  79.     cout << "-----------------------------------------" << endl;
  80.     cout << "Array Display: " << endl << endl;
  81.  
  82.     cout << "1. Swap Arrays" << endl;
  83.     cout << "2. Total numbers of vowels" << endl;
  84.     cout << "3.Diplay array" << endl;
  85.     cout << "4.Search within the array" << endl;
  86.     cout << "5. EXIT " << endl;
  87.  
  88.     cout << endl;
  89.     cout << "Enter a option from 1-5: ";
  90.     cin >> choice;
  91.  
  92.     return choice;
  93.  
  94.  
  95. }
  96.  
  97. void change(char naArray[][COLS])
  98. {
  99.  
  100.  
  101.         for (int y = COLS; y > 0; y--)
  102.     {
  103.         char exchange= naArray[y][2];
  104.         naArray[y][2] = naArray[y][5];
  105.         naArray[y][5] = exchange;
  106.  
  107.     }
  108.    
  109.     cout << endl;
  110.  
  111. }
  112.  
  113. void display(char naArray[][COLS])
  114. {
  115.  
  116.     for (int x = 0; x < ROWS; x++)
  117.     {
  118.         for (int y = 0; y < COLS; y++)
  119.         {
  120.             cout << setw(4) << naArray[x][y] << "  ";
  121.         }
  122.         cout << endl;
  123.     }
  124.  
  125. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top