daily pastebin goal
45%
SHARE
TWEET

Untitled

a guest Mar 26th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include "pch.h"
  3. #include <iostream>
  4. #include <fstream>
  5. #include <cmath>
  6.  
  7. using namespace std;
  8.  
  9. void Z1(float *mass, int size, int i);
  10. void Z2(float *mass, int size, int i);
  11. void Z3(float *mass, int size, int i);
  12. void Z4(float *mass, int size, int i);
  13. void Z5(float *mass, int size, int i);
  14. void Z6(float *mass, int size, int i);
  15. void Z7(float *mass, int size, int i);
  16. void Z8(float *mass, int size, int i);
  17. void Z9(float *mass, int size, int i);
  18. void Z10(float *mass, int size, int i);
  19.  
  20. float *mass;
  21.  
  22. int main()
  23. {
  24.     int  size, i, key;
  25.     cout << "enter size mass: "; cin >> size;
  26.     mass = new float[size];
  27.     fstream file("random.txt");
  28.     if (!file.is_open()) { cout << "error: no file\n"; return false; }
  29.     for (i = 0; i < size; i++) {
  30.         file >> mass[i];
  31.     }
  32.     file.close();
  33.     cout << "choice 1-10 : "; cin >> key;
  34.     switch (key) {
  35.     case 1: Z1(mass, size, i); break;
  36.     case 2: Z2(mass, size, i); break;
  37.     case 3: Z3(mass, size, i); break;
  38.     case 4: Z4(mass, size, i); break;
  39.     case 5: Z5(mass, size, i); break;
  40.     case 6: Z6(mass, size, i); break;
  41.     case 7: Z7(mass, size, i); break;
  42.     case 8: Z8(mass, size, i); break;
  43.     case 9: Z9(mass, size, i); break;
  44.     case 10: Z10(mass, size, i); break;
  45.     default: cout << "error"; break;
  46.     }
  47.         delete []mass;
  48.     return 0;
  49. }
  50.  
  51. void Z1(float *mass, int size, int i) {
  52.     int max, min, max_n, min_n;
  53.     max = mass[0]; min = mass[0]; i = 0;
  54.     do {
  55.         if (max < mass[i]) { max = mass[i]; max_n = i; }
  56.         if (min > mass[i]) { min = mass[i]; min_n = i; }
  57.         i++;
  58.     } while (i < size);
  59.     cout << "max[" << max_n << "]=" << max << endl <<
  60.     "min[" << min_n << "]=" << min << endl;
  61. }
  62.  
  63. void Z2(float *mass, int size, int i) {
  64.     int quantity=0, a, b;
  65.     i = 0;
  66.     cout << "a: "; cin >> a;
  67.     cout << "\nb: "; cin >> b;
  68.     if (b < a) {
  69.         b = b + a;
  70.         a = b - a;
  71.         b = b - a;
  72.     }
  73.     do {
  74.         if (mass[i] >= a && mass[i] <= b) quantity++;
  75.         i++;
  76.     } while (i < size);
  77.     cout << "quantity: " << quantity << endl;
  78. }
  79.  
  80. void Z3(float *mass, int size, int i) {
  81.     int sum=0, multiplication=1;
  82.     i = 1;
  83.     sum += mass[0];
  84.     do {
  85.         if (i % 2 == 0) { sum += mass[i]; }
  86.         else multiplication *= mass[i];
  87.         i++;
  88.     } while (i < size);
  89.     cout << "sum: " << sum << endl <<
  90.             "multiplication: " << multiplication << endl;
  91. }
  92.  
  93. void Z4(float *mass, int size, int i) {
  94.     int sum = 0, max=0, max_n=0;
  95.     max = mass[0]; i = 1;
  96.  
  97.     do {
  98.         if (max <= mass[i]) {
  99.             max = mass[i];
  100.             max_n = i;
  101.         }
  102.         i++;
  103.     } while (i < size);
  104.     max_n++;
  105.     for (; max_n < size; max_n++) {
  106.         sum += mass[max_n];
  107.     }
  108.     cout << "sum: " << sum << endl;
  109. }
  110.  
  111. void Z5(float *mass, int size, int i) {
  112.     int number, quantity=0;
  113.     i = 0;
  114.     cout << "enter number: "; cin >> number;
  115.     do {
  116.         if (mass[i] == number) quantity++;
  117.         i++;
  118.     } while (i < size);
  119.     cout << "quantity: " << quantity << endl;
  120. }
  121.  
  122. void Z6(float *mass, int size, int i) {
  123.     int multiplication = 1, max, max_n = 0;
  124.     max = abs (mass[0]);
  125.     for (i = 0; i < size; i++) {
  126.         if (max <= abs(mass[i])) { max=abs(mass[i]); max_n = i;}
  127.     }
  128.     max_n++;
  129.         do {
  130.             multiplication*= mass[max_n];
  131.             max_n++;
  132.         }while(max_n < size);
  133.     cout << "muitiplication: " << multiplication << endl;
  134. }
  135.  
  136. void Z7(float *mass, int size, int i) {
  137.     int quantity = 0;
  138.     for (i = 0; i < size; i++) {
  139.         if (mass[i] < 0) quantity++;
  140.     }
  141.     cout << "quantity: " << quantity << endl;
  142. }
  143.  
  144. void Z8(float *mass, int size, int i) {
  145.     int sum = 0, number_nul;
  146.         for (i = 0; i < size; i++) {
  147.             if (mass[i] == 0) number_nul = i;
  148.  
  149.         }
  150.         for (; number_nul < size; number_nul++) {
  151.             sum += mass[number_nul];
  152.         }
  153.         cout << "sum: " << sum << endl;
  154. }
  155.  
  156. void Z9(float *mass, int size, int i) {
  157.     int  number_n, sum=0;//y-дробn. х-целая
  158.     double y, x=0;
  159.     i = 0;
  160.     for (; i < size; i++){
  161.         if (mass[i] < 0) {
  162.             number_n = i; x = mass[i];
  163.         }
  164.     }
  165.     number_n++;
  166.     for (; number_n < size; number_n++) {
  167.         y = modf (mass[number_n], &x);
  168.         sum += x;
  169.         x = 0;
  170.     }
  171.     cout << "sum: " << sum << endl;
  172. }
  173.  
  174. void Z10(float *mass, int size, int i) {
  175.     int sum = 0, max_n=0, max;
  176.     max = mass[0];
  177.     for (i=1; i < size; i++) {
  178.         if (mass[i] >= max) { max = mass[i]; max_n = i; }
  179.     }
  180.     cout << "max: " << max << endl;
  181.     for (i = 0; i < max_n; i++) {
  182.         if (mass[i] > 0) sum += mass[i];
  183.     }
  184.     cout << "sum: " << sum << endl;
  185. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top