首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我的代码中有没有什么错误?使用BGI图形的C++代码对我不起作用

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

Stack Overflow用户
提问于 2020-07-10 19:52:05
回答 1查看 36关注 0票数 0
代码语言:javascript
复制
// 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();
}

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

EN

回答 1

Stack Overflow用户

发布于 2020-07-10 20:01:11

很难猜测这个问题的答案,因为你正在使用的技术已经过时很多年了(甚至比最早的标准早了十多年),但是如果Turbo C++有flush,那么you're going to need it。在用户提交输入之前,您的控制台输出可能会被缓冲。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62833744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档