Advertisement
JewishCat

odmas_26v

Dec 18th, 2015
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <fstream>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. /*
  8.  *
  9.  */
  10. bool rw(char *f_io, int *oi_mas, bool flag);
  11. void i_f(int *mas, int *o_mas, int el);
  12.  
  13. int main() {
  14.    
  15.     char f_in[15]  = "input.txt";
  16.     char f_out[15] = "output.txt";
  17.     int *mas = new int[90];
  18.     int *o_mas = new int[90];
  19.     if(rw(f_in,mas,1)){
  20.         cout << "Enter a value Element:" << endl;
  21.         int element;
  22.         cin >> element;
  23.         i_f(mas,o_mas,element);
  24.         rw(f_out,o_mas,0);
  25.     }
  26.    
  27.     return 0;
  28. }
  29. void i_f(int *mas, int *o_mas, int el){
  30.     int n=0;
  31.     int i=0;
  32.     while(mas[i]!='\0'){
  33.         if(el>mas[i]){
  34.             o_mas[n]=mas[i];
  35.             n++;
  36.         }
  37.         i++;
  38.     }
  39. }
  40.  
  41. bool rw(char *f_io, int *oi_mas, bool flag){
  42.     int n=0;
  43.     if(flag){
  44.         ifstream fin(f_io);
  45.         if(fin){
  46.             while(!fin.eof()){
  47.             fin >> oi_mas[n];
  48.             n++;
  49.             }
  50.             fin.close();
  51.             return 1;
  52.         }else cout << "ERROR: DON'T OPEN " << f_io << "!"<< endl; return 0;
  53.     }else{
  54.         ofstream fout(f_io);
  55.         if(fout){
  56.             int i=0;
  57.             while(oi_mas[i]!='\0'){
  58.             fout << oi_mas[i] << " ";
  59.             i++;
  60.             }
  61.             return 1;
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement