c语言代码转换为c++代码


#include <graphics.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
void carstart(int x, int y, int z);
void drawbus();
void init();
IMAGE img;
void main()
{
  init();
  int x=0, y=0, z=0;
  BeginBatchDraw();

  while(!kbhit())
  {
    x += 2;
    y++;
    z += 3;
    if (x > 600) x = -200;
    if (y > 600) y = -200;
    if (z > 600) z = -200;

    carstart(x, y, z); 
    FlushBatchDraw(); 
    Sleep(5);
  }

  EndBatchDraw();
  closegraph();
}
void init()
{
  
  initgraph(600, 600); 
  outtextxy(70, 320, "请按任意键进观看程序执行效果"); 

 
  getch();

  cleardevice();      
  drawbus();       
  getimage(&img, 80, 40, 180, 90); 
}

void carstart(int x, int y, int z)
{
  cleardevice();
  putimage(x, 40, &img);
  setlinestyle(PS_SOLID, 10); 
  line(0, 135, 600, 135);
  putimage(y, 220, &img);
  line(0, 315, 600, 315);
  putimage(z, 380, &img);
  line(0, 475, 600, 475);
}
void drawbus()
{
  setcolor(RED);
  setfillstyle(BLUE);

  fillcircle(120, 120, 10);   
  fillcircle(200, 120, 10);   
  line(80,  120, 110, 120);  
  line(80,  40,  80,  120);   
  line(130, 120, 190, 120);  
  line(210, 120, 250, 120); 
  line(250, 40,  250, 120);   
  line(80,  40,  250, 40);

  for(int x = 90, y = 100; x < 190 && y < 190; x += 15, y += 15)
  {
    rectangle(x, 60, y, 70);
  }
  rectangle(220, 60, 240, 120);
  line(230, 60, 230, 120);
  circle(230, 90, 5);
}
#include <bits/stdc++.h>
void carstart(int x, int y, int z);
void drawbus();
void init();
IMAGE img;
void main()
{
  init();
  int x=0, y=0, z=0;
  BeginBatchDraw();
 
  while(!kbhit())
  {
    x += 2;
    y++;
    z += 3;
    if (x > 600) x = -200;
    if (y > 600) y = -200;
    if (z > 600) z = -200;
 
    carstart(x, y, z); 
    FlushBatchDraw(); 
    Sleep(5);
  }
 
  EndBatchDraw();
  closegraph();
}
void init()
{
  
  initgraph(600, 600); 
  outtextxy(70, 320, "请按任意键进观看程序执行效果"); 
 
 
  getch();
 
  cleardevice();      
  drawbus();       
  getimage(&img, 80, 40, 180, 90); 
}
 
void carstart(int x, int y, int z)
{
  cleardevice();
  putimage(x, 40, &img);
  setlinestyle(PS_SOLID, 10); 
  line(0, 135, 600, 135);
  putimage(y, 220, &img);
  line(0, 315, 600, 315);
  putimage(z, 380, &img);
  line(0, 475, 600, 475);
}
void drawbus()
{
  setcolor(RED);
  setfillstyle(BLUE);
 
  fillcircle(120, 120, 10);   
  fillcircle(200, 120, 10);   
  line(80,  120, 110, 120);  
  line(80,  40,  80,  120);   
  line(130, 120, 190, 120);  
  line(210, 120, 250, 120); 
  line(250, 40,  250, 120);   
  line(80,  40,  250, 40);
 
  for(int x = 90, y = 100; x < 190 && y < 190; x += 15, y += 15)
  {
    rectangle(x, 60, y, 70);
  }
  rectangle(220, 60, 240, 120);
  line(230, 60, 230, 120);
  circle(230, 90, 5);
}