当前位置:编程学习 > C/C++ >>

C++代码求解释


#include "stdio.h"
#include "string.h"
#include <windows.h>
#include <conio.h>
#include <iostream.h>
#include <mmsystem.h>
#include <time.h>
#pragma comment(lib, "winmm.lib")

struct CONSOLE_FONT
{
    DWORD index;
    COORD dim;
};

typedef BOOL (WINAPI *PROCSETCONSOLEFONT)(HANDLE, DWORD);


PROCSETCONSOLEFONT SetConsoleFont;

HANDLE h1=GetStdHandle(STD_OUTPUT_HANDLE);

 

void gotoXY(int x, int y)//控制光标的位置
{
   COORD coord = {x, y};
   SetConsoleCursorPosition(h1, coord);
   return;
}


int main(int argc, char* argv[])
{
 int m=0,i=0,ret=0;
 double t;
 SYSTEMTIME sys;//系统时间结构体
 GetLocalTime(&sys);
 t=time(0)+sys.wMilliseconds/1000.0;

 HMODULE hKernel32 = GetModuleHandle("kernel32");
 SetConsoleFont = (PROCSETCONSOLEFONT)GetProcAddress(hKernel32,"SetConsoleFont");

 SetConsoleFont(h1, 1);//控制字体大小


 MCI_OPEN_PARMS   mciOpen;
 mciOpen.lpstrDeviceType   =   "mpegvideo ";
 mciOpen.lpstrElementName   =   "apple.mp3";
 mciSendCommand(0,MCI_OPEN,MCI_OPEN_TYPE   |   MCI_OPEN_ELEMENT,(DWORD)&mciOpen);
 UINT DeviceID=mciOpen.wDeviceID;
 MCI_PLAY_PARMS mciPlay;
 mciSendCommand(DeviceID,MCI_PLAY,0   ,(DWORD)&mciPlay);

 

 
 
 system("mode con cols=101 lines=44");
 
 FILE *read;
 read=fopen("apple.txt","r");
 char ch;
 char chex[13100]={0};
 char colors[10]={"color f0"};
 system(colors);

 while(!feof(read))
 {
  ch=fgetc(read);
  if(chex[m]!=ch)
   chex[m]=ch;  
  m++;

  if(chex[m-1]=='k'&&  chex[m-2]=='r' &&chex[m-3]=='a' && chex[m-6]=='k' )
  {
   m=0;
   ch=fgetc(read);
   gotoXY(0,0);
   printf(chex);
   while((time(0)+sys.wMilliseconds/1000.0-t<0.032))
   {
    Sleep(1);
    GetLocalTime(&sys);
   }
   GetLocalTime(&sys);
   t=time(0)+sys.wMilliseconds/1000.0;

  }
  
 }
 getchar();

 return 0;
}

答案:
#include "stdafx.h" //啧啧, 应该是Visual Stdio下面运行的程序吧 
#include <math.h>
#include <iostream.h>
const int count=10; //初始化

class point
{
public:
point(const int _x, const int _y):x(_x),y(_y){}
//相当于 point(const int _x, const int _y){x=_x,y=_y;}
point(){}
//上面是两个构造函数的重载
int x,y;

};
//把class 当成struct,就好理解了

void input(point *p)
{
for (int i=0; i <count; i )
{
cout <<"input point (x,y):";
cin>>p[i].x; //对x赋值
cin>>p[i].y;
}
}

void display(const point *p) //显示
{
for(int i=0; i <count; i )
{
cout <<"point" <<i <<":(" <<p[i].x <<"," <<p[i].y <<")" <<endl;
}
}
void cacl_len(const point *p) { double dwLen = 0;
for(int i=0; i<count-1; i )
{
//求距离
dwLen = sqrt((p[i].x - p[i 1].x)*(p[i].x - p[i 1].x) (p[i].y - p[i 1].y)*(p[i].y - p[i 1].y));
}
cout << "Total length = " << dwLen <<endl;
//总长度
}
int main(int argc, char* argv[])
{
point pt[count];
//实例化
input(pt);
display(pt);
//输入

上一个:C++寻路算法
下一个:C++问题的疑惑

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,