
Листинг dll библиотеки
#include "pch.h"
#include<cmath>;
#include "SomeProjectDLL.h"
#include <string>
namespace SomeProjectDLL {
using namespace System::Windows::Forms;
void Class1::Lab_tree(double a, double b, double h1, double c, double d, double h2, double& f, double& h, DataGridView^ dgv1)
{
SomeProjectDLL::Class1::CIKLICH(a, b, h1, c, d, h2, dgv1, h);
f = ceil(((b - a) / h1 + 1) * ((d - c) / h2 + 1));
}
void Class1::CIKLICH(double a, double b, double h1, double c, double d, double h2, DataGridView^ dgv3, double& h)
{
double s, g, x = a, y = c, z;
s = Convert::ToInt32(ceil((d - c) / h2 + 1));
g = Convert::ToInt32(ceil((b - a) / h1 + 1));
int i, j;
for (i = 1; i <= g; i++)
{
for (j = 1; j <= s; j++)
{
z = SomeProjectDLL::Class1::funct(x, y);
SomeProjectDLL::Class1::VivodDataGrid3(dgv3, x, y, z);
if (h < z)
{
h = z;
}
y += h2;
}
x += h1;
}
}
double Class1::funct(double x, double y)
{
double z = y + exp(-x) + 2.8 * pow(x, 2) - x;
return z;
}
double Class1::Vvod(TextBox^ t)// Указатель на класс ТекстБокс
{
return Convert::ToDouble(t->Text);//В скобках входной и выходной поток информации
}
void Class1::Vivod(double x, TextBox^ t) {
t->Text = Convert::ToString(x);
}
void Class1::VivodList(ListBox^ L, double n1, double s1) {
L->Items->Add(n1.ToString() + " " + s1.ToString());
}
void Class1::VivodDataGrid3(DataGridView^ L, double n1, double s1, double s2) {
L->Rows->Add(n1.ToString(), s1.ToString(), s2.ToString());
}
void Class1::VivodDataGrid2(DataGridView^ L, double n1, double s1) {
L->Rows->Add(n1.ToString(), s1.ToString());
}
void Class1::outputmas(int* a, int len, DataGridView^ dgv1) {
dgv1->ColumnCount = len;
dgv1->RowCount = 2;
for (int i = 0; i < len; i++) {
dgv1->Rows[0]->Cells[i]->Value = "[" + i + "]";
dgv1->Rows[1]->Cells[i]->Value = a[i];
}
dgv1->AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode::AllCells;
int width = 0;
for (int s = 0; s < dgv1->ColumnCount; s++) {
width += dgv1->Columns[s]->Width;
if (width > 890)
{
dgv1->Width = 890;
}
else
{
dgv1->Width = width;
}
}
}
void Class1::outputmas1(int** arr, int n, int m, DataGridView^ dgv1) {
dgv1->RowCount = n + 1;
dgv1->ColumnCount = m + 1;
dgv1->Rows[0]->Cells[0]->Value = "[" + n + "]" + "[" + m + "]";
for (int i = 0; i < n; i++)
{
dgv1->Rows[i + 1]->Cells[0]->Value = "[" + i + "]";
}
for (int i = 0; i < m; i++)
{
dgv1->Rows[0]->Cells[i + 1]->Value = "[" + i + "]";
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
dgv1->Rows[i + 1]->Cells[j + 1]->Value = arr[i][j];
}
}
dgv1->AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode::AllCells;
int width = 0;
for (int s = 0; s < dgv1->ColumnCount; s++) {
width += dgv1->Columns[s]->Width;
if (width > 890)
{
dgv1->Width = 890;
}
else
{
dgv1->Width = width;
}
}
}
void Class1::kiks(int* a, int len, TextBox^ s, TextBox^ k, TextBox^ d, TextBox^ n) {
int i = 0;
int CH = 1, NCH = 1, countCH = 0, countNCH = 0;
for (i = 0; i < len; i++)
{
if (abs(a[i]) % 2 == 1)
{
countNCH++;
NCH *= a[i];
}
else {
countCH++;
CH *= a[i];
}
}
abs(NCH);
abs(CH);
if (NCH > CH) {
for (i = 0; i < len; i++)
{
if (a[i] % 2 != 1)
{
a[i] = CH;
}
}
}
else
{
for (i = 0; i < len; i++)
{
if (a[i] % 2 == 1)
{
a[i] = NCH;
}
}
}
SomeProjectDLL::Class1::Vivod(CH, s);
SomeProjectDLL::Class1::Vivod(NCH, k);
SomeProjectDLL::Class1::Vivod(countCH, d);
SomeProjectDLL::Class1::Vivod(countNCH, n);
}
void Class1::Del(int** arr, int m)
{
for (int i = 0; i < m; i++)
delete[] * (arr + i);
delete[] arr;
}
void Class1::kiks1(int** a, int n, int m) {
int j = 0, i = 0;
int CH = 1, NCH = 1, countCH = 0, countNCH = 0;
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
if (abs(a[i][j]) % 2 == 1)
{
countNCH++;
NCH *= a[i][j];
}
else {
countCH++;
CH *= a[i][j];
}
}
abs(NCH);
abs(CH);
if (NCH > CH) {
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
if (a[i][j] % 2 != 1)
{
a[i][j] = CH;
}
}
}
else
{
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
if (a[i][j] % 2 == 1)
{
a[i][j] = NCH;
}
}
}
// SomeProjectDLL::Class1::Vivod(CH, s);
//SomeProjectDLL::Class1::Vivod(NCH, k);
//SomeProjectDLL::Class1::Vivod(countCH, d);
///SomeProjectDLL::Class1::Vivod(countNCH, n);
}
void Class1::entermas(int* mas, int n) {
for (int i = 0; i < n; i++) {
mas[i] = (int)(rand() % 900) / 20 - 20;
}
}
void Class1::entermas1(int** arr, int n, int m) {
srand(time(NULL));
for (int i = 0; i < n; i++) {
arr[i] = new int[m];
for (int j = 0; j < m; j++) {
arr[i][j] = (rand() % 900) / 20 - 20;
}
}
}
void Class1::VSTAVKA(int k, int* mas, int n, int m) {
int i;
for (i = n; i > (k - 1); i--) {
mas[i + 1] = mas[i];
}
mas[k] = m;
n++;
}
void Class1::PROSOYVSTAVKA(int* mas, int n) {
int x, j;
for (int i = 2; i < n; i++) {
x = mas[i];
mas[0] = x;
j = i - 1;
while (x < mas[j]) {
mas[j + 1] = mas[j];
j = j - 1;
}
mas[j + 1] = x;
}
}
//void Class1::add(void)
// {
// throw gcnew System::NotImplementedException();
// }
void Class1::add(void) {
ADOX::Catalog^ k = gcnew ADOX::CatalogClass();
try
{
k->Create("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " + Application::StartupPath + "\\Databasesssss.mdb");
MessageBox::Show("База данных успешно создана", "База данных");
}
catch (System::Runtime::InteropServices::COMException ^ situation)
{
MessageBox::Show(situation->Message);
}
finally
{
k = nullptr;
}
}
void Class1::add_struct(void)
{
auto p = gcnew OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source =" + Application::StartupPath + "\\Databasesssss.mdb");
p->Open();
auto c = gcnew OleDbCommand("CREATE TABLE [Labaratory6] (Nomber_element counter,ishod_mass char(200),vstavka_mass char(200),sort_vstavkoy char(200))", p);
try {
c->ExecuteNonQuery();
MessageBox::Show("База данных успешно создана", "База данных");
}
catch (System::Runtime::InteropServices::COMException ^ situation) {
MessageBox::Show(situation->Message);
}
p->Close();
}
void Class1::add_zap(int* mass, int* rezmas, int* rezmas1, int len) {
for (int i = 0; i < len; i++) {
auto p = gcnew OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source =" + Application::StartupPath + "\\Databasesssss.mdb");
p->Open();
auto c = gcnew OleDbCommand("INSERT INTO [Labaratory6](" + "[ishod_mass],[vstavka_mass],[sort_vstavkoy])VALUES('" + mass[i] + "','" + rezmas[i] + "','" + rezmas1[i] + "')");
c->Connection = p;
c->ExecuteNonQuery();
p->Close();
}
MessageBox::Show("", "База данных");
}
void Class1::Zapis(DataGridView^ grid)
{
String^ f = Interaction::InputBox("Введите путь" + "\nНапример C:Users\Agent\source\repos", "ввод", "C:\\Users\\Agent\\source\\repos\\Otvet", -1, -1);
String^ filename = f + ".txt";
try
{
auto fk = System::Text::Encoding::GetEncoding(1251);
auto Z = gcnew IO::StreamWriter(filename, false, fk);
for (int i = 0; i < grid->ColumnCount; i++)
{
Z->WriteLine(Convert::ToString(grid->Rows[1]->Cells[i]->Value));
}
Z->Close();
MessageBox::Show("Запись успешна", "Запись в текстовый файл");
}
catch (System::Exception ^ E)
{
MessageBox::Show(E->Message + "\nОшибка", "Ошибка");
}
}
void Class1::ZapisWordIsx(int* arr, int len) {
auto Wrd = gcnew Microsoft::Office::Interop::Word::ApplicationClass();
Wrd->Visible = true;
auto inf = Type::Missing;
String^ str;
auto Doc = Wrd->Documents->Add(inf, inf, inf, inf);
Wrd->Selection->TypeText("Исходный массив");
Object^ t1 = Microsoft::Office::Interop::Word::WdDefaultTableBehavior::wdWord9TableBehavior;
Object^ t2 = Microsoft::Office::Interop::Word::WdAutoFitBehavior::wdAutoFitContent;
Microsoft::Office::Interop::Word::Table^ tbl = Wrd->ActiveDocument->Tables->Add(Wrd->Selection->Range, 2, len, t1, t2);
for (int i = 0; i < len; i++) {
tbl->Cell(1, i + 1)->Range->InsertAfter("[" + Convert::ToString(i) + "]");
str = String::Format("{0:f0}", arr[i]);
tbl->Cell(2, i + 1)->Range->InsertAfter(str);
}
MessageBox::Show("Запись исходного массива в Word прошла успешно", "Запись в Micorosft Word");
}
void Class1::ZapisWordrez(int* arr, int len) {
auto Wrd = gcnew Microsoft::Office::Interop::Word::ApplicationClass();
Wrd->Visible = true;
auto inf = Type::Missing;
String^ str;
auto Doc = Wrd->Documents->Add(inf, inf, inf, inf);
Wrd->Selection->TypeText("Результирующий");
Object^ t1 = Microsoft::Office::Interop::Word::WdDefaultTableBehavior::wdWord9TableBehavior;
Object^ t2 = Microsoft::Office::Interop::Word::WdAutoFitBehavior::wdAutoFitContent;
Microsoft::Office::Interop::Word::Table^ tbl = Wrd->ActiveDocument->Tables->Add(Wrd->Selection->Range, 2, len, t1, t2);
for (int i = 0; i < len; i++) {
tbl->Cell(1, i + 1)->Range->InsertAfter("[" + Convert::ToString(i) + "]");
str = String::Format("{0:f0}", arr[i]);
tbl->Cell(2, i + 1)->Range->InsertAfter(str);
}
MessageBox::Show("Запись результирующего массива в Word прошла успешно", "Запись в Microsoft Word");
}
void Class1::MaxMatrix(int** arr, int len, int len1, int& ki, int& kj) {
int im = 0;
int jm = 0;
int xm = arr[1][0];
for (int i = 0; i < len; ++i){
for (int j = 0; j < len1; ++j)
if (arr[i][j] > arr[im][jm]){
im = i;
jm = j;
xm = arr[i][j];
}
}
ki = im;
kj = jm;
}
void Class1::ProizvDvuhMatrix(int** arr, int** arr1, int** rezmas, int len, int len2) {
int s;
for (int i = 0; i < len; i++) {
for (int j = 0; j < len2; j++) {
s = 0;
for (int r = 0; r < len2; r++) {
s = s + arr[i][j] * arr1[r][i];
}
rezmas[i][j] = s;
}
}
}
void Class1::NahodNumberMin(int** arr, int m, int n, int& f) {
f = 0;
int minitem = arr[0][0];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (arr[i][j] < minitem) {
minitem = arr[i][j];
f = j;
}
}
}
}
void Class1::SmenColumn(int** mass, int** mass3, int rowCount, int columnCount, int d, int f) {
int n = 0;
for (int i = 0; i < rowCount; i++) {
//mass3[i] = new int[columnCount];
for (int j = 0; j < columnCount; j++) {
if (j == d)
{
n = mass[i][d];
mass3[i][d] = mass[i][f];
mass3[i][f] = n;
}
else if (j != f)
{
mass3[i][j] = mass[i][j];
}
}
}
} }