Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int count;
- using namespace std;
- void array_input(double array[]) {
- system("cls");
- cout << "Enter the array size: ";
- cin >> count;
- if(!cin || count > 25)
- cout << "Error: Try again";
- else {
- for (size_t i = 0; i < count; i++) {
- cout << "Enter number: ";
- cin >> array[i];
- }
- }
- system("cls");
- }
- void array_output(double array[]) {
- system("cls");
- for (size_t i = 0; i < count; i++)
- cout << "Index: " << i << " | Value: " << array[i] << endl;
- cout << endl << endl << endl;
- }
- void calculate_average(double array[]) {
- system("cls");
- double sum = 0;
- int min, max, ticks = 0;
- cout << "Enter minimum range to check array: " << endl;
- cin >> min;
- cout << "Enter maximum range to check array: " << endl;
- cin >> max;
- for (size_t i = 0; i < count; i++) {
- if(array[i] >= min && array[i] <= max) {
- sum += array[i];
- ticks++;
- }
- }
- cout << "Average number: " << sum / ticks << endl << endl << endl;
- }
- void calculate_diff_than_zero_and_zero(double array[]) {
- system("cls");
- int zeros_count = 0, non_zeros_sum = 0;
- for (size_t i = 0; i < count; i++) {
- array[i] == 0 ? zeros_count++ : non_zeros_sum += array[i];
- }
- cout << "Zeros count in the array: " << zeros_count << " | Different than zeros sum: " << non_zeros_sum << endl << endl << endl;
- }
- void find_minimum_positive_number(double array[]) {
- system("cls");
- int min = array[0] >= 0 ? array[0] : 0;
- int array_index = 0;
- for (size_t i = 0; i < count; i++) {
- if(array[i] <= min && array[i] >=0) {
- min = array[i];
- array_index = i;
- }
- }
- cout << "Minimum positive integer: " << min << " | Index: " << array_index << endl << endl << endl;
- }
- int main() {
- double arr[5];
- int choice;
- do {
- cout << "Menu:" << endl;
- cout << "1. Enter array and its size" << endl;
- cout << "2. Calculate the average of all the numbers in the array" << endl;
- cout << "3. Calculate the summary of the numbers different than zero and the count of the zero numbers" << endl;
- cout << "4. Find the minimum positive number in hte massive and his index" << endl;
- cout << "5. Show me the array" << endl;
- cout << "6. Exit" << endl << endl;
- cout << "Make your choice: ";
- cin >> choice;
- switch (choice) {
- case 1:
- array_input(arr);
- break;
- case 2:
- calculate_average(arr);
- break;
- case 3:
- calculate_diff_than_zero_and_zero(arr);
- break;
- case 4:
- find_minimum_positive_number(arr);
- break;
- case 5:
- array_output(arr);
- break;
- }
- } while(choice != 6);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement