我的代码中有错误吗?使用BGI图形的C++代码对我不起作用

Is there any errors in my code? C++ code using BGI graphics not working for me

本文关键字:代码 C++ 不起作用 图形 使用 有错误 我的 BGI      更新时间:2023-10-16
// Program to implement 2D transformations on a rectangle.
// (1) Translation (2) Rotation (3) Scaling.
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
clrscr();
int tx,ty,c,t,i,j,k,sx,sy,x1,x2,y1,y2;
float tx1;
int gd = DETECT, gm;
initgraph(&gd, &gm,"C:\TC\BGI");
x1 = y2 = 100;
x2 = y1 = 150;
rectangle(x1,y1,x2,y2);
cout<<"Enter any one transformation:n1:Translation n2:Rotation n3:Scaling  ";
cout<<"nSelected: ";
cin>>c;
switch(c)
{
case 1:
cout<<"Enter tx & ty :";
cin>>tx>>ty;
rectangle(x1+tx, y1+ty, x2+tx, y2+ty);
break;
case 2 :
int xx1, yy1, xx2, yy2, xx3, yy3, xx4, yy4;
int ax1, ay1, ax2, ay2, ax3, ay3, ax4, ay4;
int refx, refy;
cout<<"Enter an angle for rotation: ";
cin>>tx1;
tx1=tx1*(3.14/180);
refx = refy = 100;
xx1 = yy1 = yy2 = xx4 = 100;
xx2 = xx3 = yy3 = yy4 = 150;
ax1 = refy +(xx1-refx)* cos(tx1)-(yy1-refy)*sin(tx1);
ay1 = refy +(xx1-refx)* sin(tx1)+(yy1-refy)*cos(tx1);
ax2 = refy +(xx2-refx)* cos(tx1)-(yy2-refy)*sin(tx1);
ay2 = refy +(xx2-refx)* sin(tx1)+(yy2-refy)*cos(tx1);
ax3 = refy +(xx3-refx)* cos(tx1)-(yy3-refy)*sin(tx1);
ay3 = refy +(xx3-refx)* sin(tx1)+(yy3-refy)*cos(tx1);
ax4 = refy +(xx4-refx)* cos(tx1)-(yy4-refy)*sin(tx1);
ay4 = refy +(xx4-refx)* sin(tx1)+(yy4-refy)*cos(tx1);
line(ax1,ay1, ax2, ay2);
line(ax2,ay2, ax3, ay3);
line(ax3,ay3, ax4, ay4);
line(ax4,ay4, ax1, ay1);
break;
case 3 :
cout<<"Enter sx & sy: ";
cin>>sx>>sy;
rectangle(x1*sx, y1*sy, x2*sx, y2*sy);
break;
default :
cout<<"Error! Enter a valid choice";
}
getch();
closegraph();
}

使用BGI图形.h库在C++中实现。我知道它很古老,但我需要它来做一个学校项目。显然在IDE中不适合我,我已经安装了所有的库。它只是没有显示任何输出,只有一个黑屏。实现2D转换的程序(i( 缩放(ii(旋转

很难猜测答案,因为你使用的20世纪80年代的技术已经过时多年(甚至比最早的标准早了十多年(,但如果Turbo C++有flush,那么你就需要它。你的控制台输出可能会被缓冲,直到用户提交输入。