Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <time.h>
- using namespace std;
- void vvodbin(FILE *output, int x, int y, float **n, float *z) {
- int i, j;
- for (i = 0; i <= x-1; i++) {
- n[i] = new float[y];
- z[i] = 0;
- for (j = 0; j <= y-1; j++) {
- n[i][j]=rand()%1000/100.0-5;
- fwrite(&n[i][j], sizeof(float), 1, output);
- if (n[i][j] < 0) {
- z[i]++;
- }
- }
- }
- }
- void readbin(FILE *output, int x, int y, float **fred) {
- FILE *outbin=fopen("outbin.djs5", "wb");
- int i, j;
- float z;
- for (i = 0; i <= x-1; i++) {
- fred[i] = new float[y];
- cout << "Massiv #" << i+1 << ": ";
- for (j = 0; j <= y-1; j++) {
- fread(&fred[i][j], sizeof(float), 1, output);
- cout << fred[i][j] << " ";
- if (fred[i][j] < 0) {
- //z=fred[i][j];
- fwrite(&fred[i][j], sizeof(float), 1, outbin);
- }
- } cout << endl;
- }
- }
- int main() {
- srand(time(NULL));
- float **n, **fred, *z, *newz;
- int x, y, i, j;
- cout << "Kol-vo massivov: "; cin >> x;
- cout << "Razmer massivov: "; cin >> y;
- n = new float*[x];
- fred = new float*[x];
- z = new float[x];
- newz = new float[x];
- FILE *output, *output1;
- output = fopen("input.djs5", "wb");
- vvodbin(output, x, y, n, z);
- fclose(output);
- FILE *input = fopen("input.djs5", "rb");
- readbin(output, x, y, fred);
- fclose(input);
- output = fopen("output.djs5", "wb");
- output1 = fopen("output.txt", "wb");
- for (i = 0; i <= x-1; i++) {
- fwrite(&z[i], sizeof(float), 1, output);
- }
- fclose(output);
- input = fopen("output.djs5", "rb");
- for (i = 0; i <= x-1; i++) {
- fread(&newz[i], sizeof(float), 1, input);
- cout << newz[i] << " ";
- } cout << endl;
- fclose(input);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement