Write a program that lets you know if you can have a key or not, based on your role at the school.
First ask for the user’s role at the school. They can be a student, administrator, or a teacher. (And remember that capitalization is important! ‘Student’ is not the same as ‘student’.)
Example 1: Administrator or Teacher
For example, if this was the input:
Are you an administrator, teacher, or student?: teacher
This should be the output:
Administrators and teachers get keys!
Example 2: Student
And if this was the input:
Are you an administrator, teacher, or student?: student
This should be the output:
Students do not get keys!
(Note: You should also be able to handle a situation where the user enters a value other than administrator, teacher or student and tell them they must be one of the three choices!)
Example 3: Other
If they input anything else:
Are you an administrator, teacher, or student?: secretary
This should be the output:
You can only be an administrator, teacher, or student!
#include#include
void push_pack(int *&arr, int& size, const int val)
void bubbleSort(int* arr, const int size)
int getRandomNumber(const int min, const int max)
int main()
{
using namespace std;
setlocale(LC_ALL, «ru»);
srand(time(NULL));
int N = 10, M = 0;
int* parr_1 = new int[N];
int* parr_2 = new int[M];
cout << «Начальный массив: » << endl;
for (int i = 0; i < N; i++)
{
parr_1[i] = getRandomNumber(-30, 30);
cout << parr_1[i] << ‘t’;
if (parr_1[i] < 0) push_pack(parr_2, M, parr_1[i]);
}
cout << «nnОтсортированный массив: » << endl;
bubbleSort(parr_1, N);
for (int i = 0; i < N; i++)
cout << parr_1[i] << ‘t’;
cout << «nnМассив с отрицательными числами: » << endl;
for (int i = 0; i < M; i++)
cout << parr_2[i] << ‘t’;
delete[] parr_1;
delete[] parr_2;
return 0;
}
void push_back(int *&arr, int& size, const int val)
{
int *newArr = new int[size + 1];
for (int i = 0; i < size; i++)
newArr[i] = arr[i];
newArr[size++] = val;
delete[] arr;
arr = newArr;
}
int getRandomNumber(const int min, const int max)
{
static const double fraction = 1.0 / (static_cast<double>(RAND_MAX) + 1.0);
return static_cast<int>(rand() * fraction * (max — min + 1) + min);
}
void bubbleSort(int* arr, const int size)
{
int temp = 0;
for (int i = 0; i < size — 1; i++)
{
for (int j = 0; j < size — 1; j++)
{
if (arr[j + 1] < arr[j])
{
temp = arr[j + 1];
arr[j + 1] = arr[j];
arr[j] = temp;
}
}
}
}