Снітко Анна ІТУ-21-3 ПЗ 4 АПр

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Міністерство освіти і науки України

Харківський національний університет радіоелектроніки

Кафедра системотехніки

Дисципліна: «Алгоритмізація та програмування»

ПРАКТИЧНЕ ЗАНЯТТЯ № 4

«ДИНАМІЧНІ МАСИВИ ТА ФУНКЦІЇ»

Виконав: Прийняла: к.т.н., доц. каф. СТ


ст. гр. ІТУ-21-1 Білова Тетяна Георгіївна
Снітко Анна Олександрівна
з оцінкою «____________»
«____»_______________

2021р.
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>

#include <fstream>

#include <stdlib.h>

#include <ctime>

#include <cmath>

using namespace std;

void read_files(fstream&, fstream&);

void fillFile(const int, fstream&, fstream&);

void fillFile(const int, fstream&);

const int NotUsed = system("color 70");

int main()

setlocale(LC_ALL, "rus");

srand(time(0));

const char* f_name1 = "myfile1";

const char* f_name2 = "myfile2";

int col = rand() % 30 + 30;

fstream stream1(f_name1, ios::in | ios::out | ios::trunc | ios::binary);

fstream stream2(f_name2, ios::in | ios::out | ios::trunc | ios::binary);

if (!stream1)

cout << "The file hasn't been opened";

return 0;

fillFile(col, stream1);

fillFile(col, stream1, stream2);

read_files(stream1, stream2);

}
void fillFile(const int col, fstream& stream1, fstream& stream2) {

int min = INT_MAX, max = INT_MIN, countMax{}, countMin{}, val{};

stream1.seekg(0);

for (int i = 0; stream1.peek() != -1; i++)

stream1.read((char*)&val, sizeof(val));

if (val > 0)

stream2.write((char*)&val, sizeof(val));

stream1.seekg(0);

for (int i = 0; stream1.peek() != -1; i++)

stream1.read((char*)&val, sizeof(val));

if (val == 0)

stream2.write((char*)&val, sizeof(val));

stream1.seekg(0);

for (int i = 0; stream1.peek() != -1; i++)

stream1.read((char*)&val, sizeof(val));

if (val < 0)

stream2.write((char*)&val, sizeof(val));

void fillFile(const int col, fstream& stream)

for (int i = 0; i < col; i++)

int val = rand() % 40 - 20;

stream.write((char*)&val, sizeof(val));

}
void read_files(fstream& stream1, fstream& stream2)

cout << "Первый файл:" << endl;

stream1.clear();

stream1.seekg(0);

while (stream1.peek() != -1)

int valRead1;

stream1.read((char*)&valRead1, sizeof(int));

cout << valRead1 << " ";

cout << endl;

cout << "Второй файл:" << endl;

stream2.clear();

stream2.seekg(0);

while (stream2.peek() != -1)

int valRead2;

stream2.read((char*)&valRead2, sizeof(int));

cout << valRead2 << " ";

You might also like