Advertisement
Guest User

main.cpp

a guest
Feb 20th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #include "header.h"
  2. #include <iostream>
  3. #include <exception>
  4.  
  5. using namespace std;
  6.  
  7. int chooseType();
  8.  
  9. int main()
  10. {
  11.     cout << setw(13) << "Name: " << "LAB 1.1\n";
  12.     cout << setw(13) << "Student: " << "Ocheretnyi Viacheslav\n";
  13.     cout << setw(13) << "Group: " << "K - 15\n";
  14.     cout << setw(13) << "Description: " << "Variant 20 (insert a value before the first prime element)\n\n";
  15.  
  16.     const int N = 15;
  17.     int a[N], n, value, type;
  18.     while((type = chooseType()) != 9)
  19.     {
  20.         try
  21.         {
  22.             switch(type)
  23.             {
  24.                 case 1:
  25.                     cout << "Enter array size: ";
  26.                     if (!(cin >> n))
  27.                     {
  28.                         cout << "INVALID DATA\n";
  29.                         return 0;
  30.                     }
  31.                     generateRandomArray(a, N, n);
  32.                     cout << "Generated array:\n";
  33.                     break;
  34.                 case 2:
  35.                     cout << "Please, enter elements of array (finish input with q): \n";
  36.                     readArray(a, N, n);
  37.                     cout << "Your array: \n";
  38.                     break;
  39.             }
  40.             printArray(a, n);
  41.             cout << "Enter a number to insert into the array:\n";
  42.             if (!(cin >> value))
  43.             {
  44.                 cout << "INVALID DATA\n";
  45.                 return 0;
  46.             }
  47.             processing(a, n, N, value);
  48.             cout << "Result of processing array: \n";
  49.             printArray(a, n);
  50.         }
  51.         catch(length_error e)
  52.         {
  53.             cout << e.what() << "\n";
  54.         }
  55.         catch(exception e)
  56.         {
  57.             cout << e.what() << "\n";
  58.         }
  59.     }
  60.     cout << "End of work";
  61.     return 0;
  62. }
  63.  
  64. int chooseType()
  65. {
  66.     cout << "\nSelect option:\n" <<
  67.             "1 - generate random array\n" <<
  68.             "2 - read array from console\n" <<
  69.             "9 - finish work\n";
  70.  
  71.     int option = -1;
  72.     if (!(cin >> option))
  73.     {
  74.         cout << "Invalid option\n";
  75.         return option = 9;
  76.     }
  77.     if (!(option == 1 || option == 2 || option == 9))
  78.     {
  79.         cout << "Invalid option\n";
  80.         option = 9;
  81.     }
  82.     return option;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement