Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Лабораторная работа 4 Пантелеева БСТ1904.docx
Скачиваний:
67
Добавлен:
04.03.2022
Размер:
348.78 Кб
Скачать

Int* divide(int* arr, int X, int* b)

{

int max = arr[0], min = arr[0];

for (int i = 1; i < siz; i++)

{

if (max < arr[i]) max = arr[i];

if (min > arr[i]) min = arr[i];

}

int bucket = siz - 2;

int divider = ceil((double)(max + 1) / bucket);

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

{

if (arr[i] / x >= 1 && arr[i] / x <= 9) b[i] = arr[i];

}

return b;

cout << endl << endl;

}

void printArray(int arr[siz])

{

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

{

cout << arr[i] << " ";

}

cout << endl << endl;

}

secondary1.cpp

#include "header.h"

#include <Windows.h>

#include <iostream>

#include <string>

#include <cstdlib>

#include <sstream>

#include <cmath>

#include <fstream>

#include <stdlib.h>

#include <cstdio>

#include <tchar.h>

using namespace std;

CRITICAL_SECTION cs;

const int siz = 10;

void printArray(int[siz]);

void single_int_to_char(int a, char *c);

void char_to_mas_int(char* c, int *mas);

int char_to_int(char* c);

void int_to_char(int *a, char *c);

void string_to_char(string s, char *c);

bool read_message(HANDLE transmitter);

void send_message(HANDLE receiver, char *message);

bool join_mail(LPCTSTR name, HANDLE &handle);

HANDLE create_mail(LPCTSTR name);

void parent(LPCTSTR parent_mail, LPCTSTR child_mail);

void child(HANDLE parent_handle, LPCTSTR parent_mail, LPCTSTR child_mail);

int* divide(int* arr, int x, int* b);

int _tmain(int argc, _TCHAR* argv[])

{

setlocale(LC_ALL, "Russian");

LPCTSTR parent_mail = "\\\\.\\mailslot\\$Input$";

LPCTSTR child_mail = "\\\\.\\mailslot\\$Output$";

HANDLE parent_handle;

if (!join_mail(parent_mail, parent_handle))

{

parent(parent_mail, child_mail);

}

else

{

child(parent_handle, parent_mail, child_mail);

CloseHandle(parent_handle);

}

system("pause");

return 0;

}

void single_int_to_char(int a, char *c)

{

size_t size = 64;

_itoa_s(a, c, size, 10);

}

void char_to_mas_int(char* c, int *mas)

{

int count = 0;

string list = "0123456789";

string str = "";

for (int i = 0; i < strlen(c); i++)

{

if (c[i] != ' ')

{

bool check = false;

for (int j = 0; j < 10; j++)

{

if (c[i] == list[j])

{

str += c[i];

check = true;

}

}

if (!check)

{

return;

}

}

else

{

mas[count] = atoi(str.c_str());

count++;

str = "";

}

}

}

Int char_to_int(char* c)

{

return atoi(c);

}

Void int_to_char(int *a, char *c)

{

string str = "";

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

{

ostringstream s;

s << a[i];

str += s.str();

str += ' ';

}

string_to_char(str, c);

}

Void string_to_char(string s, char *c)

{

int i;

for (i = 0; i < s.size(); i++)

{

c[i] = s[i];

}

c[i] = '\0';

}

bool read_message(HANDLE my_handle, char *message)

{

DWORD count;

GetMailslotInfo(my_handle, NULL, NULL, &count, NULL);

if (count != 0)

{

ReadFile(my_handle, message, 512, NULL, NULL);

return true;

}

return false;

}

void send_message(HANDLE other_handle, char *message)

{

WriteFile(other_handle, message, strlen(message) + 1, NULL, NULL);

}

bool join_mail(LPCTSTR name, HANDLE &handle)

{

handle = CreateFileA(name, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);

if (!GetMailslotInfo(handle, NULL, NULL, NULL, NULL))

{

return false;

}

return true;

}

HANDLE create_mail(LPCTSTR name)

{

return CreateMailslotA(name, 0, MAILSLOT_WAIT_FOREVER, NULL);

}