我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
Is there any errors in my code? C++ code using BGI graphics not working for me
// 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
,那么你就需要它。你的控制台输出可能会被缓冲,直到用户提交输入。
相关文章:
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 代码在main()中运行,但在函数中出现错误
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 编译包含字符串的代码时遇到问题
- 我在c++代码中生成了一个运行时#3异常
- 如何在linux终端中同时编译和运行c++代码
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 在Linux for Windows上编译C++代码时出错
- 我的字符计数代码计算错误.为什么
- 孤立代码块在结构中引发异常
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 此代码是否违反一个定义规则
- 为什么我的代码在输出中增加了93天
- 我的简单if-else语句是如何无法访问的代码
- 使用动态分配的数组会导致代码分析发出虚假的C6386缓冲区溢出警告
- 为什么在这个代码结束循环中没有得到结束
- 在c代码之间共享数据的最佳方式
- 这个指针和内存代码打印是什么?我不知道是打印垃圾还是如何打印我需要的值