Sunteți pe pagina 1din 4

Listingul programului:

#include <windows.h>
#include <cmath>
const double pi = 3.1415926535;
// Function prototypes:
double w(double x);
int g(int x);
double f(double x);
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, INT
iCmdShow)
{
LPCWSTR szAppName = L"WinApp";
LPCWSTR szWndName = L"Afisarea unui sistem de coordonate cartezian cu 3 functii";
HWND hWnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if (!RegisterClass(&wndclass))
{
MessageBox(NULL, L"Could not create window.", L"Error", 0);
return 0;
}
hWnd = CreateWindow(szAppName, szWndName, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 1366, 768, NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, iCmdShow);
UpdateWindow(hWnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return (int)msg.wParam;

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
double x;
switch (message)
{
case WM_CREATE:
return 0;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
HPEN hOldPen, hNewPen;
hDC = BeginPaint(hWnd, &ps);
hNewPen = CreatePen(PS_SOLID, 1, RGB(0, 180, 180)); // aqua color
hOldPen = (HPEN)SelectObject(hDC, hNewPen);
// Print a message:
TextOut(hDC, 50, 50, L"Verde- g=2*cos(x)", 17);
TextOut(hDC, 50, 80, L"Rosu- f=ctg(k*x)", 20);
TextOut(hDC, 50, 110, L"Violet- w=arcctg(k*x)", 22);
// Draw the axes:
MoveToEx(hDC, 100, 384, NULL);
LineTo(hDC, 1266, 384);
MoveToEx(hDC, 668, 100, NULL);
LineTo(hDC, 668, 668);
MoveToEx(hDC, 568, 374, NULL);
LineTo(hDC, 568, 394);
TextOut(hDC, 550, 395, L"-3.14/2", 7);
MoveToEx(hDC, 768, 374, NULL);
LineTo(hDC, 768, 394);
TextOut(hDC, 755, 395, L"3.14/2", 7);
MoveToEx(hDC, 368, 374, NULL);
LineTo(hDC, 368, 394);
TextOut(hDC, 350, 395, L"-6.28/4", 7);
MoveToEx(hDC, 168, 374, NULL);
LineTo(hDC, 168, 394);
TextOut(hDC, 155, 395, L"-12.46/8", 11);
MoveToEx(hDC, 968, 374, NULL);
LineTo(hDC, 968, 394);
TextOut(hDC, 955, 395, L"12.46/8", 7);
MoveToEx(hDC, 1168, 374, NULL);
LineTo(hDC, 1168, 394);
TextOut(hDC, 1155, 395, L"6.28/4", 7);
MoveToEx(hDC, 658, 284, NULL);
LineTo(hDC, 678, 284);
TextOut(hDC, 638, 277, L"1", 1);
MoveToEx(hDC, 658, 484, NULL);
LineTo(hDC, 678, 484);
TextOut(hDC, 638, 477, L"-1", 2);

// Draw the graph of the function g:


for (x = -550; x <= 575; x++)
SetPixel(hDC, 668 + x, 384 + g(x), RGB(26,145,15)); // verde
// Draw th graph of the function f, the one that modulates the amplitude of g:
for (x = -550; x <= 575;)
{
227,18,219bordo

SetPixel(hDC, 668 + x, 384 + f(x), RGB(227, 18, 219)); //

x += 0.0025;
}
//*** Students: this is the end of the section that you might try to change. ***
for (x = -550; x <= 575;)
{
SetPixel(hDC, 668 + x, 384 + w(x), RGB(28, 237, 36)); // albastru
x += 0.0025;
}
//*** Students: this is the end of the section that you might try to change. ***
EndPaint(hWnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
}

return DefWindowProc(hWnd, message, wParam, lParam);

/* Given: x An integer value.


Task: To compute the nearest integer to the value of g at x where g is a modified sine function.
Return: In the function name we return this integer approximation to the value of g at x.
*/
double w(double x)
{
return 1 / (atan(0.1*pi * x/200.0 ));
}
/* Given: x An integer value.
Task: To compute the nearest integer to the value of f at x where f is a modified sine function.
Return: In the function name we return this integer approximation to the value of f at x.
*/
int g(int x)
{
return 100 * cos(pi * x / 200.0);
}
double f(double x)
{
return cos(0.1*pi * x / 20.0) / sin(0.1*pi * x / 20.0);
}

Rezultatul rularii programului: