vs2019导入easyx包 但是在使用easyx的line 函数却出现了c2660报错
#include <iostream>
#include <easyx.h>
#include <conio.h>
using namespace std;
void Init();
void changeX();
void changeY();
//倍数
const int mulx = 60;
const int muly = 60;
//坐标中心点
const int X = 100;
const int Y = 300;
int main()
{
Init();
return 0;
}
//sinx / x
void Sin()
{
setlinecolor(BLACK);
double t1 = changeX(0), t2 = changeY(1);
for (double i = 0.1; i <= 6; i += 0.1)
{
line((int)t1, (int)t2, (int)changeX(i), (int)changeY(sin(i) / i));
t1 = changeX(i);
t2 = changeY(sin(i) / i);
}
}
void StepIntegration()
{
setlinecolor(BLUE);
double a = 0, b = 6, e = 1e-5;
double h = b - a;
double T1 = h / 2 * (1 - sin(b) / b), T2 = 0;
double S, x;
S = 0;
x = a + h / 2;
while (true)
{
//S = 0;
//x = a = h / 2;
line(changeX(x), changeY(sin(x) / x), changeX(x), changeY(0));
S += (sin(x) / x);
x += h;
if (x >= b)
{
T2 = T1 / 2 + h / 2 * S;
if (fabs(T2 - T1) < e)
{
char t[10];
_gcvt_s(t, 10, T2, 8);
outtextxy(150, 100, t);
break;
}
else
{
h /= 2;
T1 = T2;
S = 0;
x = a + h / 2;
}
}
}
}
void Longberg()
{
double a = 0, b = 6, e = 1e-5;
int k = 1;
double h = b - a;
double T1 = h / 2 * (1 - sin(b) / b), T2 = 0;
double S = 0, x = 0;
double C1 = 0, C2 = 0, R2 = 0, R1 = 0, S2 = 0, S1 = 0;
S = 0;
x = a + h / 2;
while (true)
{
line(changeX(x), changeY(sin(x) / x), changeX(x), changeY(0));
S += (sin(x) / x);
x += h;
if (x >= b)
{
T2 = T1 / 2 + h / 2 * S;
S2 = T2 + 1.0 / 3.0 * (T2 - T1);
if (k != 1)
{
C2 = S2 + (1.0 / 15.0) * (S2 - S1);
if (k != 2)
{
R2 = C2 + (1.0 / 63.0) * (C2 - C1);
if (k != 3)
{
if (fabs(R2 - R1) < e)
{
char f[20];
_gcvt_s(f, 20, R2, 8);
outtextxy(320, 100, f);
break;
}
else
{
R1 = R2;
C1 = C2;
k++;
h /= 2;
T1 = T2;
S1 = S2;
S = 0;
x = a + h / 2;
} //fabs
}
else {
R1 = R2;
C1 = C2;
k++;
h /= 2;
T1 = T2;
S1 = S2;
S = 0;
x = a + h / 2;
}//k!=3
}
else
{
C1 = C2;
k++;
h /= 2;
T1 = T2;
S1 = S2;
S = 0;
x = a + h / 2;
}//k!=2
}
else
{
k += 1;
h /= 2;
T1 = T2;
S1 = S2;
S = 0;
x = a + h / 2;
}//k!=1
}
}
}
double changeX(double x)
{
return X + mulx * x;
}
double changeY(double y)
{
return Y - 2.0 * muly * y;
}
void Axis()
{
setlinecolor(BLACK);
//x轴 及其箭头
line(X - 50, Y, mulx * 6 + X + 30, Y);
line(mulx * 6 + X + 15, Y - 15, mulx * 6 + X + 30, Y);
line(mulx * 6 + X + 15, Y + 15, mulx * 6 + X + 30, Y);
//y轴
line(X, Y + 70, X, Y - 3 * muly - 40);
line(X - 15, Y - 3 * muly - 25, X, Y - 3 * muly - 40);
line(X + 15, Y - 3 * muly - 25, X, Y - 3 * muly - 40);
settextcolor(BLACK);
outtextxy(X - 10, Y + 10, "O");
char s[10];
//x轴刻度
for (int i = 1; i <= 6; ++i)
{
line((int)(X + i * mulx), (int)Y, (int)(X + i * mulx), (int)(Y - 3));
_gcvt_s(s, 10, i * 1.00, 3);
outtextxy(X + i * mulx - 3, Y + 3, s);
}
//y轴刻度
//double t = 0.5;
for (int i = 1; i <= 3; ++i)
{
line((int)X, (int)(Y - i * muly), (int)(X + 3), (int)(Y - i * muly));
_gcvt_s(s, 10, i * 0.5, 3);
outtextxy(X - 20, Y - i * muly - 8, s);
}
}
//按钮
void Button()
{
//x , y 为左上角点的位置
setlinecolor(BLACK);
settextcolor(BLACK);
//矩形的长度和高度
int l = 120, h = 40;
int r1[] = { 120,50 };
int r2[] = { 300,50 };
setbkmode(TRANSPARENT);
roundrect(r1[0], r1[1], r1[0] + l, r1[1] + h, 20, 20);
char strtemp[] = "StepIntegration";
int w = textwidth(strtemp);
int h1 = textheight(strtemp);
outtextxy(r1[0] + (l - w) / 2, r1[1] + (h - h1) / 2, strtemp);
roundrect(r2[0], r2[1], r2[0] + l, r2[1] + h, 20, 20);
char strtemp1[] = "Longberg";
w = textwidth(strtemp1);
h1 = textheight(strtemp1);
outtextxy(r2[0] + (l - w) / 2, r2[1] + (h - h1) / 2, strtemp1);
ExMessage msg;
while (true)
{
while (peekmessage(&msg, EM_MOUSE))
{
//"StepIntegration"
if (msg.x > r1[0] && msg.x<r1[0] + l && msg.y>r1[1] && msg.y < r1[1] + h)
{
setfillcolor(RED);
floodfill(r1[0] + 5, r1[1] + 5, BLACK);
if (msg.message == WM_LBUTTONDOWN)
{
StepIntegration();
}
}
else {
setfillcolor(WHITE);
floodfill(r1[0] + 5, r1[1] + 5, BLACK);
}
//"Longberg"
if (msg.x > r2[0] && msg.x<r2[0] + l && msg.y>r2[1] && msg.y < r2[1] + h)
{
setfillcolor(RED);
floodfill(r2[0] + 5, r2[1] + 5, BLACK);
if (msg.message == WM_LBUTTONDOWN)
{
Longberg();
}
//Sleep(20);
}
else {
setfillcolor(WHITE);
floodfill(r2[0] + 5, r2[1] + 5, BLACK);
}
}
}
}
void Init()
{
initgraph(540, 460, EW_SHOWCONSOLE);
setbkcolor(WHITE);
cleardevice();
setlinecolor(BLACK);
Axis();
Sin();
Button();
_getch();
closegraph();