68 {
+
69 int mode = 0;
70
-
71 std::cin >> mode;
-
72
-
73 if (mode == 2) {
-
74 int size = 0;
-
75 std::cout << "\nEnter the size of the array [in range 1-30 ]: ";
-
76 std::cin >> size;
-
77
-
78 while (size <= 0 || size > 30) {
-
79 std::cout << "Size can only be 1-30. Please choose another value: ";
-
80 std::cin >> size;
-
81 }
-
82
-
83 int *array = new int[size];
-
84 int key = 0;
+
71 std::cout << "Choose mode\n";
+
72 std::cout << "Self-test mode (1), interactive mode (2): ";
+
73
+
74 std::cin >> mode;
+
75
+
76 if (mode == 2) {
+
77 int size = 0;
+
78 std::cout << "\nEnter the size of the array [in range 1-30 ]: ";
+
79 std::cin >> size;
+
80
+
81 while (size <= 0 || size > 30) {
+
82 std::cout << "Size can only be 1-30. Please choose another value: ";
+
83 std::cin >> size;
+
84 }
85
-
86
-
87 std::cout << "Enter the array of " << size << " numbers: ";
-
88 for (int i = 0; i < size; i++) {
-
89 std::cin >> array[i];
-
90 }
-
91
-
92 std::cout << "\nEnter the number to be searched: ";
-
93 std::cin >> key;
+
86 int *array = new int[size];
+
87 int key = 0;
+
88
+
89
+
90 std::cout << "Enter the array of " << size << " numbers: ";
+
91 for (int i = 0; i < size; i++) {
+
92 std::cin >> array[i];
+
93 }
94
-
-
96 if (index != -1) {
-
97 std::cout << "Number found at index: " << index << "\n";
-
98 } else {
-
99 std::cout << "Array element not found";
-
100 }
-
101 delete[] array;
-
102 } else {
-
-
104 }
-
105 return 0;
-
106}
+
95 std::cout << "\nEnter the number to be searched: ";
+
96 std::cin >> key;
+
97
+
+
99 if (index != -1) {
+
100 std::cout << "Number found at index: " << index << "\n";
+
101 } else {
+
102 std::cout << "Array element not found";
+
103 }
+
104 delete[] array;
+
105 } else {
+
+
107 }
+
108 return 0;
+
109}
static void tests()
Self-test implementations.
int LinearSearch(int *array, int size, int key)
for IO operations