Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "header.h"
- #include <iostream>
- #include <exception>
- using namespace std;
- int chooseType();
- int main()
- {
- cout << setw(13) << "Name: " << "LAB 1.1\n";
- cout << setw(13) << "Student: " << "Ocheretnyi Viacheslav\n";
- cout << setw(13) << "Group: " << "K - 15\n";
- cout << setw(13) << "Description: " << "Variant 20 (insert a value before the first prime element)\n\n";
- const int N = 15;
- int a[N], n, value, type;
- while((type = chooseType()) != 9)
- {
- try
- {
- switch(type)
- {
- case 1:
- cout << "Enter array size: ";
- if (!(cin >> n))
- {
- cout << "INVALID DATA\n";
- return 0;
- }
- generateRandomArray(a, N, n);
- cout << "Generated array:\n";
- break;
- case 2:
- cout << "Please, enter elements of array (finish input with q): \n";
- readArray(a, N, n);
- cout << "Your array: \n";
- break;
- }
- printArray(a, n);
- cout << "Enter a number to insert into the array:\n";
- if (!(cin >> value))
- {
- cout << "INVALID DATA\n";
- return 0;
- }
- processing(a, n, N, value);
- cout << "Result of processing array: \n";
- printArray(a, n);
- }
- catch(length_error e)
- {
- cout << e.what() << "\n";
- }
- catch(exception e)
- {
- cout << e.what() << "\n";
- }
- }
- cout << "End of work";
- return 0;
- }
- int chooseType()
- {
- cout << "\nSelect option:\n" <<
- "1 - generate random array\n" <<
- "2 - read array from console\n" <<
- "9 - finish work\n";
- int option = -1;
- if (!(cin >> option))
- {
- cout << "Invalid option\n";
- return option = 9;
- }
- if (!(option == 1 || option == 2 || option == 9))
- {
- cout << "Invalid option\n";
- option = 9;
- }
- return option;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement