#include <iostream>
#include <iomanip>
using namespace std;
void task4()
{
cout << "Height of 12 people:\n";
int height[12];
for (int i = 0; i < 12; i++)
{
height[i] = rand() % 28 + 163;
cout << height[i] << " ";
}
cout << endl << endl;
}
void task39()
{
int Amount;
cout << "Enter amount of studnts (amount > 0)...\n";
cin >> Amount;
if (Amount > 0)
{
int* AmountOfStudents = new int[Amount];
cout << "Enter marks of students (0 < mark <= 5)...\n";
for (int i = 0; i < Amount; i++)
{
cin >> AmountOfStudents[i];
}
cout << "Marks:\n";
for (int j = 0; j < Amount; j++)
{
cout << AmountOfStudents[j];
if (AmountOfStudents[j] > 0 && AmountOfStudents[j] <= 5)
if (AmountOfStudents[j] < 3)
cout << " Student isn't allowed\n";
else cout << endl;
else cout << " Mark is incorrect\n";
}
}
else cout << "Incorrect amount" << endl;
cout << endl;
}
void task74()
{
int Order, Counter = 1;
double Sequence[15];
for (int i = 0; i < 15; i++)
{
Sequence[i] = rand() % 201 - 100;
cout << Sequence[i] << " ";
if (Sequence[i] < 0 && Counter == 1)
Order = i, Counter = 0;
}
if (Counter == 0)
cout << "\nNumber of the first negative numeral is " << Order << " (numeration from 0)";
else cout << "There is no negative numeral";
cout << endl << endl;
}
void task109()
{
int max = 0, k;
double RealNumbers[7];
cout << "The array is: ";
for (int i = 0; i < 6; i++)
{
RealNumbers[i] = rand() % 200 - 100;
cout << RealNumbers[i] << " ";
if (RealNumbers[i] > RealNumbers[max])
max = i;
}
cout << "(numeration from 0)\nMax element is: " << RealNumbers[max] << "\nEnter 'k' (0 <= k < 7)..." << endl;
cin >> k;
if (k >= 0 && k < 7)
{
RealNumbers[k] = RealNumbers[max];
for (int i = 0; i < 6; i++)
{
cout << RealNumbers[i] << " ";
}
}
else cout << "k is incorrect";
cout << endl << endl;
}
void task144()
{
int Sequence[15], min = 0, max = 0, sum = 0;
cout << "Sequence is:\n";
for (int i = 0; i < 15; i++)
{
Sequence[i] = rand() % 101;
cout << Sequence[i] << " ";
if (Sequence[i] < Sequence[min])
{
min = i;
}
if (Sequence[i] > Sequence[max])
{
max = i;
}
}
if (min < max)
{
cout << "\nSum of ";
for (int j = min; j <= max; j++)
{
cout << Sequence[j] << " ";
sum += Sequence[j];
}
}
else
{
cout << "\nSum of ";
for (int j = max; j <= min; j++)
{
cout << Sequence[j] << " ";
sum += Sequence[j];
}
}
cout << "is " << sum << endl << endl;
}
void task179()
{
cout << "\nR = 8, H = 4\nArray of real numerals:\n";
const int R = 8, H = 4;
double RealNumber[R];
int NaturalNumber[H], counter = 0;
for (int i = 0; i < R; i++)
{
RealNumber[i] = rand() % 17;
cout << RealNumber[i] << " ";
if (RealNumber[i] < int(R + H) && RealNumber[i] > int(R - H))
counter++;
}
int *Numbers = new int [counter];
counter = 0;
cout << "\nNumbers of elements which are 'R - H < Element < R + H:'\n";
for (int k = 0; k < R; k++)
{
if (RealNumber[k] < R + H && RealNumber[k] > R - H)
Numbers[counter] = k + 1, counter++;
}
for (int j = 0; j < counter; j++)
{
cout << Numbers[j] << " ";
}
cout << " (numeration from 1)";
cout << endl << endl;
}
void task215()
{
int height[25], number, counter = 0;
cout << "Height of 25 students is:\n";
for (int i = 0; i < 25; i++)
{
height[i] = rand() % 51 + 150;
}
for (int k = 0; k < 25; k++)
{
for (int j = 0; j < 25 - k; j++)
{
if (height[j] < height[j + 1])
swap (height[j], height[j + 1]);
}
if (k == 24)
for (int l = 0; l < 25; l++)
cout << height[l] << " ";
}
cout << "\nEnter number of a student who has to be excluded (numeration from 0)\n";
cin >> number;
if (number >= 0 && number < 25)
while (counter < 25)
{
if (counter != number)
cout << height[counter] << " ";
counter++;
}
else cout << "Incorrect number";
cout << endl << endl;
}
void task227()
{
cout << "Input amount of elements of sequence A, then of sequence B (amount > 0)\n";
int A = 0, B = 0, b = 0, a = 0;
cin >> A >> B;
if (A > 0 && B > 0)
{
int* sequenceA = new int[A], * sequenceB = new int[B];
cout << "Sequence A is:\n";
for (int i = 0; i < A; i++)
{
sequenceA[i] = rand() % 201 - 100;
}
for (int j = 0; j < A; j++)
{
for (int k = 0; k < A - 1; k++)
{
if (sequenceA[k] > sequenceA[k + 1])
swap(sequenceA[k], sequenceA[k + 1]);
}
if (j == A - 1)
{
for (int l = 0; l < A; l++)
{
cout << sequenceA[l] << " ";
}
}
}
cout << endl;
cout << "Sequence B is:\n";
for (int i = 0; i < B; i++)
{
sequenceB[i] = rand() % 271 - 170;
}
for (int j = 0; j < B; j++)
{
for (int k = 0; k < B - 1; k++)
{
if (sequenceB[k] > sequenceB[k + 1])
swap(sequenceB[k], sequenceB[k + 1]);
}
if (j == B - 1)
{
for (int l = 0; l < B; l++)
{
cout << sequenceB[l] << " ";
}
}
}
cout << endl;
cout << "Sequence AB is:\n";
while (a < A && b < B)
{
if (sequenceA[a] < sequenceB[b] && a < A && b < B)
cout << sequenceA[a] << " ", a++;
if (sequenceA[a] > sequenceB[b] && a < A && b < B)
cout << sequenceB[b] << " ", b++;
if (sequenceA[a] == sequenceB[b] && a < A && b < B)
cout << sequenceA[a] << " " << sequenceB[b] << " ", a++, b++;
}
if (a <= A - 1)
for (int i = a; i < A; i++)
cout << sequenceA[i] << " ";
if (b <= B - 1)
for (int i = b; i < B; i++)
cout << sequenceB[i] << " ";
}
else cout << "Incorrect amount";
cout << endl << endl;
}
void task216()
{
int size, firstNegative = -1, lastEven = -1, counter = 1, k = 0, f=0;
cout << "Enter the size of the array (size > 0)...\n";
cin >> size;
if (size > 0)
{
int* array = new int[size];
for (int i = 0; i < size; i++)
{
array[i] = rand() % 101 - 50;
cout << array[i] << " ";
if (array[i] < 0 && counter == 1)
firstNegative = i, counter = 0;
if (array[i] % 2 == 0)
lastEven = i;
}
if (firstNegative != -1)
cout << "\nNumber of the first negative numeral is " << firstNegative + 1 << " (numeration from 1)\n";
else cout << "\nThere is no negative numearal\n";
if (lastEven != -1)
cout << "Number of the last even numeral is " << lastEven + 1 << " (numeration from 1)";
else cout << "There is no even numeral";
cout << "\nDeleting first negative and last even element...\nResult:\n";
while (k < size)
{
if (k != firstNegative && k != lastEven)
cout << array[k] << " ", f++;
k++;
}
if (f == 0)
cout << "Nothing left";
}
else cout << "Incorrect number";
cout << endl << endl;
}
int main()
{
int number;
cout << "Numbers of tasks are 4, 39, 74, 109, 144, 179 (extra task 215, 227, 216)" << endl;
while (true)
{
cout << "Input the number of the task (0 to close the program)..." << endl;
cin >> number;
cout << endl;
switch (number)
{
case 4:
task4();
break;
case 39:
task39();
break;
case 74:
task74();
break;
case 109:
task109();
break;
case 144:
task144();
break;
case 179:
task179();
break;
case 215:
task215();
break;
case 227:
task227();
break;
case 216:
task216();
break;
case 0:
return 0;
break;
default:
cout << "Incorrect number, try again" << endl;
break;
}
}
}