-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
114 lines (100 loc) · 2.82 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
Copyright (c) 2017 Maxim Teryokhin
This code is licensed under MIT. See LICENSE file for more details.
*/
#undef UNICODE
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include "resource.h"
#include "KPolynomial.h"
using namespace std;
/// CHOOSE COEFFICIENT TYPE^
#define C_TYPE int
HINSTANCE hInst;
KPolynomial<C_TYPE> POLY = {{1, 2}, {-2, 1}, {1, 0}};
KPolynomial<C_TYPE> POLY2;
void UpdateFields(HWND hwndDlg)
{
SetDlgItemText(hwndDlg, ID_POLY, POLY.toString().c_str());
SetDlgItemText(hwndDlg, ID_DEGREE, (string("Ñòåïåíü: ")+to_string(POLY.Degree())).c_str());
SetDlgItemText(hwndDlg, ID_COUNT, (string("Êîë-âî ÷ë.: ")+to_string(POLY.Count())).c_str());
}
void GetPoly2(HWND hwndDlg)
{
char buf[100];
GetDlgItemText(hwndDlg, ID_POLY2, buf, sizeof(buf));
POLY2.fromString(string(buf));
}
BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
{
UpdateFields(hwndDlg);
}
return TRUE;
case WM_CLOSE:
{
EndDialog(hwndDlg, 0);
}
return TRUE;
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case ID_CLEAR: {
POLY.Clear();
POLY2.Clear();
UpdateFields(hwndDlg);
SetDlgItemText(hwndDlg, ID_POLY2, "");
break;
}
case ID_SWAP: {
POLY.Swap(POLY2);
UpdateFields(hwndDlg);
SetDlgItemText(hwndDlg, ID_POLY2, POLY2.toString().c_str());
break;
}
case ID_PLUS: {
GetPoly2(hwndDlg);
POLY += POLY2;
UpdateFields(hwndDlg);
break;
}
case ID_MINUS: {
GetPoly2(hwndDlg);
POLY -= POLY2;
UpdateFields(hwndDlg);
break;
}
case ID_MULT: {
GetPoly2(hwndDlg);
POLY *= POLY2;
UpdateFields(hwndDlg);
break;
}
}
}
return TRUE;
}
return FALSE;
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
hInst=hInstance;
InitCommonControls();
//cin >> POLY;
// KPolynomial<int> poly = {{1, 2}, {-2, 1}, {1, 0}};
// KPolynomial<int> poly2 = string("1^2 2^1 1^0");
//cin >> poly;
// cout << '(' << poly << ") * (" << poly2 << ") == ";
// cout << poly*poly2 << endl;
//cout << "Coef at x^2 == " << poly[2].Coeff() << endl;
// for (auto it = poly.begin(); it != poly.end(); it++)
// cout << (*it).Coeff() << "x^" << (*it).Degree() << endl;
return DialogBox(hInst, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DlgMain);
}