1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
#include <iostream>
#include <fstream>
using namespace std;
void ReadFromFile(int arrayF[]);
void Print(int arrayA[]);
void Copy(int arrayA[], int arrayB[],int& num);
int Find80To100(int arrayA[]);
int FindDivisibleBy5(int arrayA[]);
void PrintIndexDivisibleBy5(int arrayA[]);
float FindAverage(int arrayA[],int& sum,float& avg);
int FindMin(int arrayA[],int min);
bool Search(int arrayA[],int x);
int main()
{
int arrayA[10];
int arrayB[10];
int min=INT_MAX;
int num=10;
int sum = 0;
float avg=0;
int x=0;
ReadFromFile(arrayA);
Print(arrayA);
Copy(arrayA, arrayB, num);
Print(arrayB);
Find80To100(arrayA);
FindDivisibleBy5(arrayA);
PrintIndexDivisibleBy5(arrayA);
FindAverage(arrayA, sum, avg);
FindMin(arrayA, min);
Search(arrayA,x);
system("pause");
}
void ReadFromFile(int arrayA[])
{
ifstream fin;
fin.open("data.txt");
for (int i = 0; i < 10; i++)
fin >> arrayA[i];
}
void Copy(int arrayA[], int arrayB[],int& num)
{
for (int i=0;i <= num; i++)
arrayB[num-i-1] = arrayA[i];
}
void Print(int arrayA[])
{
for (int i = 0; i < 10; i++)
cout << arrayA[i]<<"\t";
cout << endl;
}
int Find80To100(int arrayA[])
{
for (int i = 0; i < 10; i++)
if ((arrayA[i] >= 80) && (arrayA[i] <= 100))
cout << arrayA[i]<< "\t";
cout << "\n" <<endl;
return 0;
}
int FindDivisibleBy5(int arrayA[])
{
for (int i = 0; i < 10; i++)
if ((arrayA[i] % 5) == 0)
cout << arrayA[i] << "\t";
cout << "\n" << endl;
return 0;
}
void PrintIndexDivisibleBy5(int arrayA[])
{
for (int i = 0; i < 10; i++)
if ((arrayA[i] % 5) == 0)
cout << i << "\t";
cout << "\n" << endl;
}
float FindAverage(int arrayA[],int& sum,float& avg)
{
for (int i = 0; i < 10; i++)
sum += arrayA[i];
avg = sum / 10;
cout << avg << "\n"<< endl;
return 0;
}
int FindMin(int arrayA[],int min)
{
for (int i = 0; i < 10; i++)
if (arrayA[i] < min)
min = arrayA[i];
cout << min <<"\n" << endl;
return 0;
}
bool Search(int arrayA[], int x)
{
cout << "Please enter an integer:";
cin >> x;
for (int i = 0; i < 10; i++)
{
{
if (x == arrayA[i])
return true;
}
}
return false;
}
|