Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <fstream>
- #include <cmath>
- using namespace std;
- void Z1(float *mass, int size, int i);
- void Z2(float *mass, int size, int i);
- void Z3(float *mass, int size, int i);
- void Z4(float *mass, int size, int i);
- void Z5(float *mass, int size, int i);
- void Z6(float *mass, int size, int i);
- void Z7(float *mass, int size, int i);
- void Z8(float *mass, int size, int i);
- void Z9(float *mass, int size, int i);
- void Z10(float *mass, int size, int i);
- float *mass;
- int main()
- {
- int size, i, key;
- cout << "enter size mass: "; cin >> size;
- mass = new float[size];
- fstream file("random.txt");
- if (!file.is_open()) { cout << "error: no file\n"; return false; }
- for (i = 0; i < size; i++) {
- file >> mass[i];
- }
- file.close();
- cout << "choice 1-10 : "; cin >> key;
- switch (key) {
- case 1: Z1(mass, size, i); break;
- case 2: Z2(mass, size, i); break;
- case 3: Z3(mass, size, i); break;
- case 4: Z4(mass, size, i); break;
- case 5: Z5(mass, size, i); break;
- case 6: Z6(mass, size, i); break;
- case 7: Z7(mass, size, i); break;
- case 8: Z8(mass, size, i); break;
- case 9: Z9(mass, size, i); break;
- case 10: Z10(mass, size, i); break;
- default: cout << "error"; break;
- }
- delete []mass;
- return 0;
- }
- void Z1(float *mass, int size, int i) {
- int max, min, max_n, min_n;
- max = mass[0]; min = mass[0]; i = 0;
- do {
- if (max < mass[i]) { max = mass[i]; max_n = i; }
- if (min > mass[i]) { min = mass[i]; min_n = i; }
- i++;
- } while (i < size);
- cout << "max[" << max_n << "]=" << max << endl <<
- "min[" << min_n << "]=" << min << endl;
- }
- void Z2(float *mass, int size, int i) {
- int quantity=0, a, b;
- i = 0;
- cout << "a: "; cin >> a;
- cout << "\nb: "; cin >> b;
- if (b < a) {
- b = b + a;
- a = b - a;
- b = b - a;
- }
- do {
- if (mass[i] >= a && mass[i] <= b) quantity++;
- i++;
- } while (i < size);
- cout << "quantity: " << quantity << endl;
- }
- void Z3(float *mass, int size, int i) {
- int sum=0, multiplication=1;
- i = 1;
- sum += mass[0];
- do {
- if (i % 2 == 0) { sum += mass[i]; }
- else multiplication *= mass[i];
- i++;
- } while (i < size);
- cout << "sum: " << sum << endl <<
- "multiplication: " << multiplication << endl;
- }
- void Z4(float *mass, int size, int i) {
- int sum = 0, max=0, max_n=0;
- max = mass[0]; i = 1;
- do {
- if (max <= mass[i]) {
- max = mass[i];
- max_n = i;
- }
- i++;
- } while (i < size);
- max_n++;
- for (; max_n < size; max_n++) {
- sum += mass[max_n];
- }
- cout << "sum: " << sum << endl;
- }
- void Z5(float *mass, int size, int i) {
- int number, quantity=0;
- i = 0;
- cout << "enter number: "; cin >> number;
- do {
- if (mass[i] == number) quantity++;
- i++;
- } while (i < size);
- cout << "quantity: " << quantity << endl;
- }
- void Z6(float *mass, int size, int i) {
- int multiplication = 1, max, max_n = 0;
- max = abs (mass[0]);
- for (i = 0; i < size; i++) {
- if (max <= abs(mass[i])) { max=abs(mass[i]); max_n = i;}
- }
- max_n++;
- do {
- multiplication*= mass[max_n];
- max_n++;
- }while(max_n < size);
- cout << "muitiplication: " << multiplication << endl;
- }
- void Z7(float *mass, int size, int i) {
- int quantity = 0;
- for (i = 0; i < size; i++) {
- if (mass[i] < 0) quantity++;
- }
- cout << "quantity: " << quantity << endl;
- }
- void Z8(float *mass, int size, int i) {
- int sum = 0, number_nul;
- for (i = 0; i < size; i++) {
- if (mass[i] == 0) number_nul = i;
- }
- for (; number_nul < size; number_nul++) {
- sum += mass[number_nul];
- }
- cout << "sum: " << sum << endl;
- }
- void Z9(float *mass, int size, int i) {
- int number_n, sum=0;//y-дробn. х-целая
- double y, x=0;
- i = 0;
- for (; i < size; i++){
- if (mass[i] < 0) {
- number_n = i; x = mass[i];
- }
- }
- number_n++;
- for (; number_n < size; number_n++) {
- y = modf (mass[number_n], &x);
- sum += x;
- x = 0;
- }
- cout << "sum: " << sum << endl;
- }
- void Z10(float *mass, int size, int i) {
- int sum = 0, max_n=0, max;
- max = mass[0];
- for (i=1; i < size; i++) {
- if (mass[i] >= max) { max = mass[i]; max_n = i; }
- }
- cout << "max: " << max << endl;
- for (i = 0; i < max_n; i++) {
- if (mass[i] > 0) sum += mass[i];
- }
- cout << "sum: " << sum << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement