Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7. void vvodbin(FILE *output, int x, int y, float **n, float *z) {
  8.     int i, j;
  9.     for (i = 0; i <= x-1; i++) {
  10.         n[i] = new float[y];
  11.         z[i] = 0;
  12.         for (j = 0; j <= y-1; j++) {
  13.             n[i][j]=rand()%1000/100.0-5;
  14.             fwrite(&n[i][j], sizeof(float), 1, output);
  15.             if (n[i][j] < 0) {
  16.                 z[i]++;
  17.             }
  18.         }
  19.     }
  20. }
  21.  
  22. void readbin(FILE *output, int x, int y, float **fred) {
  23.     FILE *outbin=fopen("outbin.djs5", "wb");
  24.     int i, j;
  25.     float z;
  26.     for (i = 0; i <= x-1; i++) {
  27.         fred[i] = new float[y];
  28.         cout << "Massiv #" << i+1 << ": ";
  29.         for (j = 0; j <= y-1; j++) {
  30.             fread(&fred[i][j], sizeof(float), 1, output);
  31.             cout << fred[i][j] << " ";
  32.             if (fred[i][j] < 0) {
  33.                 //z=fred[i][j];
  34.                 fwrite(&fred[i][j], sizeof(float), 1, outbin);
  35.             }
  36.         } cout << endl;
  37.     }
  38. }
  39.  
  40. int main() {
  41.     srand(time(NULL));
  42.     float **n, **fred, *z, *newz;
  43.     int x, y, i, j;
  44.     cout << "Kol-vo massivov: "; cin >> x;
  45.     cout << "Razmer massivov: "; cin >> y;
  46.     n = new float*[x];
  47.     fred = new float*[x];
  48.     z = new float[x];
  49.     newz = new float[x];
  50.     FILE *output, *output1;
  51.     output = fopen("input.djs5", "wb");
  52.     vvodbin(output, x, y, n, z);
  53.     fclose(output);
  54.    
  55.     FILE *input = fopen("input.djs5", "rb");
  56.     readbin(output, x, y, fred);
  57.     fclose(input);
  58.    
  59.     output = fopen("output.djs5", "wb");
  60.     output1 = fopen("output.txt", "wb");
  61.     for (i = 0; i <= x-1; i++) {
  62.         fwrite(&z[i], sizeof(float), 1, output);
  63.     }
  64.     fclose(output);
  65.  
  66.     input = fopen("output.djs5", "rb");
  67.     for (i = 0; i <= x-1; i++) {
  68.         fread(&newz[i], sizeof(float), 1, input);
  69.         cout << newz[i] << " ";
  70.     } cout << endl;
  71.     fclose(input);
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement