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

Void string_to_char(string s, char *c)

{

int i;

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

{

c[i] = s[i];

}

c[i] = '\0';

}

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);

}

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);

}

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* 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;

}

sec2.cpp

#include "header.h"

#include <iostream>

#include <Windows.h>

#include <string>

#include <cstdlib>

#include <sstream>

using namespace std;

const int siz = 10;

void printArray(int[siz]);

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

void string_to_char(string s, char *c);

void single_int_to_char(int a, char *c);

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

bool read_message(HANDLE my_handle, char *message);

void send_message(HANDLE other_handle, char *message);

int main()

{

setlocale(LC_ALL, "Russian");

HANDLE pipe_handle;

PCTSTR pipe_name = "\\\\.\\pipe\\$Pipe$";

pipe_handle = CreateFileA(pipe_name, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

char message[512];

while (!read_message(pipe_handle, message)) {}

int b[siz];

char_to_mas_int(message, b);

cout << "Received massiv:" << endl;

for (int i = 0; i < siz; i++) cout << b[i] << " ";

cout << endl << endl;

int temp;

for (int i = 0; i < siz - 1; i++) {

for (int j = 0; j < siz - i - 1; j++) {

if (b[j] > b[j + 1]) {

temp = b[j];

b[j] = b[j + 1];

b[j + 1] = temp;

}

}

}

cout << "Result = " << endl;

printArray(b);

cout << endl;

int_to_char(b, message);

send_message(pipe_handle, message);

cout << "Done" << endl;

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 = "";

}

}

}

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);

}