Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- using namespace std;
- void test1(int arr[]) {
- arr[0] = arr[0] + 1;
- }
- void test2() {
- int b[]{ 3, 56 };
- cout << b[0] << endl;
- test1(b);
- cout << b[0] << endl;
- cout << b << " " << b[0] << " " << *b << endl;
- cout << b + 1 << " " << (b + 1)[0] << " " << *(b + 1) << endl;
- // arr[id] ~ *(arr + id)
- }
- void showArr(const int sz, const int arr[]) {
- for (int k = 0; k < sz; k++) {
- cout << arr[k] << " ";
- }
- cout << endl;
- }
- template<class Type>
- void showArr(const int sz, const Type arr[]) {
- for (int k = 0; k < sz; k++) {
- cout << arr[k] << " ";
- }
- cout << endl;
- }
- void task1() {
- const int sz1 = 5;
- int arr[]{ 1, 2, 3, 4, 5 };
- showArr(sz1, arr);
- int arr2[sz1];
- for (int k = 0; k < sz1; k++) {
- arr2[k] = arr[sz1 - k - 1];
- }
- showArr(sz1, arr2);
- }
- void test3() {
- int a = 12;
- int b = 23;
- swap(a, b);
- int b2 = 13;
- int b3 = 7;
- cout << b2 << " && "
- << b3 << " = "
- << (b2 & b3) << endl;
- cout << &b2 << endl;
- int *c = &b2;
- double verylongnameforme = 12.4;
- double& x = verylongnameforme;
- cout << x << " " << verylongnameforme << endl;
- x++;
- cout << x << " " << verylongnameforme << endl;
- verylongnameforme = -1.34234342;
- cout << x << " " << verylongnameforme << endl;
- }
- void test4() {
- srand(time(NULL));
- int sz = 10;
- int* pV = new int[sz];
- const int min = -10;
- const int max = 10;
- for (int k = 0; k < sz; k++) {
- pV[k] = min + rand() % (max - min + 1);
- }
- showArr(sz, pV);
- // считаем количество
- int sz_positive = 0, sz_negative = 0;
- for (int k = 0; k < sz; k++) {
- if (pV[k] > 0)
- sz_positive++;
- else if (pV[k] < 0) {
- sz_negative++;
- }
- }
- // выделяем память
- int* pPositive = new int[sz_positive];
- int* pNegative = new int[sz_negative];
- // заполняем
- int idPosit = 0, idNegat = 0;
- for (int k = 0; k < sz; k++) {
- if (pV[k] > 0)
- pPositive[idPosit++] = pV[k];
- else if (pV[k] < 0) {
- pNegative[idNegat++] = pV[k];
- }
- }
- cout << "Positive: ";
- showArr(sz_positive, pPositive);
- cout << "Negative: ";
- showArr(sz_negative, pNegative);
- /*
- for (int k = 0; k < sz; k++) {
- cout << pV[k] << " ";
- }
- */
- cout << endl;
- delete[] pPositive;
- delete[] pNegative;
- delete[] pV;
- }
- void test5() {
- const int sz = 5;
- int arr_int[sz]{ 1, 2, 3, 4, 5 };
- char arr_char[sz]{ 'a', 'b', 'c', 'd', 'e' };
- double arr_double[sz]{ 1.5, 1.6, 1.7, 1.8, 1.9 };
- showArr(sz, arr_int);
- showArr(sz, arr_char);
- showArr(sz, arr_double);
- }
- void main() {
- //task1();
- //test2();
- //task2();
- //test3();
- //test4();
- test5();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement