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
|
#include <iostream>
#include <fstream>
using namespace std;
const int MAX_SIZE=25;
ifstream infile;
void initialize(int numbers[], int length);
void print(int numbers[], int length);
void removeAll(int numbers[], int length, int num2remove);
int main()
{
int numbers[MAX_SIZE], length=0, num2remove;
initialize(numbers, length);
print(numbers, length);
cout<<"Enter a number to remove"<<endl;
cin>>num2remove;
removeAll(numbers, length, num2remove);
print(numbers, length);
system("PAUSE");
return 0;
}
void initialize(int numbers[], int length)
{
infile.open("pr5.txt");
for(int i=0; i<MAX_SIZE; i++)
{
infile>>numbers[i];
length++;
}
}
void print(int numbers[], int length)
{
for(int i=0; i<MAX_SIZE; i++)
cout<<numbers[i]<<endl;
}
void removeALL(int numbers[], int length, int num2remove)
{
for(int i=0; i<MAX_SIZE; i++)
{
if(numbers[i] == num2remove)
length-1;
for(int i=0;i<MAX_SIZE;i++)
numbers[i]=numbers[i+1];
}
}
|