⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dashixi.c

📁 在C语言环境下实现计算功能
💻 C
字号:
#include<stdio.h>
#include<dos.h>
#include<bios.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>

#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN  0x5000
#define UP    0x4800
#define SPACE 0x3920
#define Esc   0x11b
#define ENTER 0x1c0d
#define Backspace  0xe08

struct menustruct
{
  char name[10];
  char str[10][20];
  int n;
} menu1[3];

int key;
int textx,texty;
char c[4096];
char save[4096];
int i,j;
int flag2=1;


void menu();
void selectitem();
void drawselectitem();
void redtext(int x,int y,char *z);
void blacktext(int x,int y, char *z);
void run();
void drawm1(int n);
void movem1(int n,int x);
void enter(int m, int n);
void Fangcheng();
void Calculator();
void juanji();
void Tuoyuan();
void testshutdown();



void main()
{
 menu();
 run();
}

void menu()
{
  system("cls");
  textbackground(BLUE);
  window(1,1,25,80);
  clrscr();

  textx=3;
  texty=2;
  gotoxy(1,2);
  printf("%c",218);
  for(i=3;i<=80;i++)

   printf("%c",196);
   printf("%c",191);
  for(i=3;i<=23;i++)
  {
    gotoxy(1,i);
    printf("%c",179);
    gotoxy(80,i);
    printf("%c",179);
   }
  printf("%c",192);
  for(i=0;i<78;i++)
  printf("%c",196);
  printf("%c",217);
  gotoxy(1,1);
  textcolor(7);
  for(i=0;i<80;i++)
  cprintf("%c",219);
  selectitem();
  drawselectitem();
  gettext(2,3,78,23,c);
}

void selectitem()
{
 strcpy(menu1[0].name,"File");
 strcpy(menu1[0].str[0],"Exit");
 strcpy(menu1[0].str[1],"Open");
 strcpy(menu1[0].str[2],"Save");
 strcpy(menu1[0].str[3],"Save as");
 strcpy(menu1[0].str[4],"History");
 strcpy(menu1[0].str[5],"New");

 menu1[0].n=6;

 strcpy(menu1[1].name,"Function");
 strcpy(menu1[1].str[0],"Juanji");
 strcpy(menu1[1].str[1],"Tuoyuan");
 strcpy(menu1[1].str[2],"Calculator");
 strcpy(menu1[1].str[3],"Fangcheng");
 menu1[1].n=4;

 strcpy(menu1[2].name,"Help");
 strcpy(menu1[2].str[0],"This System");
 strcpy(menu1[2].str[1],"Version");
 strcpy(menu1[2].str[2],"Index");
 strcpy(menu1[2].str[3],"Contents");

 menu1[2].n=4;

}
 void drawselectitem()
 {
   for(i=0;i<=3;i++)
   redtext(i,1,menu1[i].name);
 }
 void redtext(int x,int y,char *z)
 {
    textbackground(7);
    gotoxy(3+x*20,y);
    for(j=0;z[j];j++)
    {
      if(j==0)
	textcolor(MAGENTA);
      else
	textcolor(BLACK);
	cprintf("%c",z[j]);
     }
  }
 void blacktext(int x,int y, char*z)
 {
  textbackground(2);
  textcolor(15);
  gotoxy(3+20*x,y);
  cputs(z);

 }

 void run()
 {
  while(1)
  {
   gotoxy(texty,textx);
   key=bioskey(0);
   switch(key)
   {
     case Esc:drawm1(0);break;
     case UP:if (textx==3)
	       textx=23;
	       textx--;
	       gotoxy(texty,textx);
	       break;
     case LEFT:if (texty==2)
	       texty=79;
	       texty--;
	       gotoxy(texty,textx);
	       break;
     case DOWN:if (textx==23)
		 textx=2;
		 textx++;
		 gotoxy(texty,textx);
		 break;
     case RIGHT:if (texty==79)
		  texty=2;
		  texty++;
		  gotoxy(texty,textx);
		  break;
    case Backspace:if (texty==2&&textx==3)
		    continue;
		    else if (textx!=2)
			texty--;
		    else if (texty==2)
			{
			  texty=78;
			  textx--;
			}
		    gotoxy(texty,textx);
		    printf("");
		    gotoxy(textx,texty);
		    break;
     case SPACE:if (texty==79)
		    continue;
		else
		   {
		    gotoxy(texty,textx);
		    printf("");
		    texty++;
		    gotoxy(texty,textx);
		   }
		   break;
    case ENTER: if (textx==23)
		   continue;
		   textx++;
		   texty=2;
		   gotoxy(textx,texty);
		 break;
    default: if (texty==79&&textx==23)
		continue;
	      else if (texty==79&&textx!=23)
	      {
	       textx++;
	       texty=2;
	      }
	     gotoxy(texty,textx);
	     printf("%c",key);
	     if(texty==79)
	      continue;
	     else
	       texty++;
	     break;

   }
  }
 }
 void drawframe(int left,int u,int r,int d, int tcolor, int bcolor)
 {
  textbackground(bcolor);
  textcolor(tcolor);
  for(i=left;i<=r;i++)
   {
    for (j=u;j<d;j++)
    {
     gotoxy(i,j);
     printf("%c",219);
    }
   }
   textcolor(tcolor);
   for(i=u+1;i<d;i++)
   {
    gotoxy(left,i);
    cprintf("%c",179);
    gotoxy(r,i);
    cprintf("%c",179);
   }
   for(i=left+1;i<r;i++)
   {
    gotoxy(i,u);
    cprintf("%c",196);
    gotoxy(i,d);
    cprintf("%c",196);

   }
   gotoxy(left,u);
   cprintf("%c",218);

   gotoxy(r,u);
   cprintf("%c",191);
   gotoxy(left,d);
   cprintf("%c",192);
   gotoxy(r,d);
   cprintf("%c",217);

  }
  void drawm1(int n)
  {
   gettext(1,1,80,25,save);
   blacktext(n,1,menu1[n].name);
   drawframe(3+20*n-1,2,3+20*n+19,3+menu1[n].n,0,7);
   for(i=3;i<3+menu1[n].n;i++)
   {
    if (i==3)
    blacktext(n,i,menu1[n].str[i-3]);
    else
    redtext(n,i,menu1[n].str[i-3]);
    }
    gotoxy(79,2);
    movem1(n,3);

   }

   void movem1(int n,int x)
   {
    int flag=1;
    while(flag)
    {
     gotoxy(79,1);
     key=bioskey(0);
     gotoxy(79,1);
     switch(key)
     {
      case Esc: puttext(1,1,80,25,save);
		flag=0;
		break;
      case LEFT:puttext(1,1,80,25,save);
		if(n==0)
		 drawm1(2);
		else
		 drawm1(n-1);
		 flag=0;
		 break;
      case RIGHT:puttext(1,1,80,25,save);
		 if(n==2)
		  drawm1(0);
		 else
		  drawm1(n+1);
		 flag=0;
		 break;
      case UP:redtext(n,x,menu1[n].str[x-3]);
	      if(x==3)
	       x=3+menu1[n].n-1;
	      else
		x--;
	      blacktext(n,x,menu1[n].str[x-3]);
	      flag=1;
	      break;
      case DOWN:redtext(n,x,menu1[n].str[x-3]);
		if (x==3+menu1[n].n-1)
		x=3;
		else
		 x++;
		 blacktext(n,x,menu1[n].str[x-3]);
		 flag=1;
		 break;
      case ENTER:puttext(1,1,80,25,save);
		 enter(n,x-3);
		 flag=0;
		 break;

     }
     gotoxy(79,1);

    }
   }
    void enter(int m,int n)
    {
     switch(m)
     {
      case 0:switch(n)
      {
       case 0:
       case 1:
       case 2:
       case 3:exit(0);

      }
      break;
      case 1:switch(n)
      {
       case 0: gettext(1,1,80,25,save);
	       juanji();

	       getch();
	       puttext(1,1,80,25,save);
	       break;
       case 1:gettext(1,1,80,25,save);
	       Tuoyuan();
		getch();
		puttext(1,1,80,25,save);
		break;
       case 2:
	      Calculator();break;
       case 3:Fangcheng();
	      break;
       case 4:exit(0);

      }
      break;
      case 2: switch(n)
      {
       case 0: gettext(1,1,80,25,save);


       getch();
       puttext(1,1,80,25,save);
       break;
       case 1: gettext(1,1,80,25,save);
	       getch();
	       puttext(1,1,80,25,save);
	       break;
       case 2:gettext(1,1,80,25,save);


	     getch();
	     puttext(1,1,80,25,save);
	     break;
       case 3:exit(0);

      }
      break;
     }
    }
void  Fangcheng()
{
  float a,b,c,disc,x1,x2,realpart,imagpart;


  while(flag2)
  {
  puttext(1,1,80,25,save);
   gotoxy(texty,textx);
  printf("Please input:");
  scanf("%f,%f,%f",&a,&b,&c);
   gotoxy(texty,textx+1);
  printf("The equation");
  if(fabs(a)<=1e-6)

    printf("is not a quadratic\n");
  else
  {
   disc=b*b-4*a*c;
   if (fabs(disc)<=1e-6)

     printf("has two equal roots:%8.4f\n",-b/(2*a));
   else
     if (disc>1e-6)
     {
      x1=(-b+sqrt(disc))/(2*a);
      x2=(-b-sqrt(disc))/(2*a);

      printf("has distinct real roots:%8.4f and %8.4f\n",x1,x2);

     }
     else
     {
      realpart=-b/(2*a);
      imagpart=sqrt(-disc)/(2*a);
      gotoxy(texty,textx+2);
      printf("has complex roots:\n");
      gotoxy(texty,textx+3);
      printf("%8.4f+%8.4fi\n",realpart,imagpart);
      gotoxy(texty,textx+4);
      printf("%8.4f-%8.4fi\n",realpart,imagpart);
     }
  }
   testshutdown();
}
  getch();
}
  void Calculator()
 {

float data1,data2,result;
char op;
while(flag2)
{  puttext(1,1,80,25,save);
 gotoxy(texty,textx);
printf("please enter the expression:");
scanf("%f%c%f",&data1,&op,&data2);
switch(op)
{
	case'+':
		result=data1+data2;
		gotoxy(texty,textx+1);
		printf("%f+%f=%f\n",data1,data2,result);
		break;
	case'-':
		result=data1-data2;
		gotoxy(texty,textx+1);
		printf("%f-%f=%f\n",data1,data2,result);
		break;
	case'*':
		result=data1*data2;
		gotoxy(texty,textx+1);
		printf("%f*%f=%f\n",data1,data2,result);
		break;
	case'/':
		if (fabs(data2)<=1e-7)

		printf("division by zero!\n");
		else
		result=data1/data2;

		printf("%f/%f=%f\n",data1,data2,result);
		break;
	default:
		printf("unknown operator!\n");
}
getch();
testshutdown();
}
}

void juanji()
{
 int x[10],y[10];
 int n,m,i,j,t;
 int z[100];
 while(flag2)
 {
 puttext(1,1,80,25,save);
 gotoxy(texty,textx);
 printf("input m,n:");
 scanf("%d,%d",&m,&n);

 gotoxy(texty,textx+1);
 printf("input the x[]:");
 for(i=0;i<m;i++)
 scanf("%d",&x[i]);
 gotoxy(texty,textx+2);
 printf("input the y[]:");
 for(i=0;i<n;i++)
 scanf("%d",&y[i]);
 gotoxy(texty,textx+3);
 for(i=m;i<10;i++) x[i]=0;
 for(i=n;i<10;i++) y[i]=0;
 t=m+n-1;

 for(i=0;i<t;i++)
 {
  z[i]=0;
  for(j=0;j<=i;j++)
  z[i]=z[i]+x[j]*y[i-j];

  printf("%3d",z[i]);

 }
getch();
testshutdown();
}
}
void Tuoyuan()
  {
 float x,y;
 while(flag2)
 {

 for(x=5;x<55;x+=0.001)
  {y=sqrt(100*(1-(x-30)*(x-30)/625))+12.5;
  gotoxy(x,y);
 delay(0.1);
  printf(".");
  }
  for(x=5;x<55;x+=0.001)
  {
  y=-sqrt(100*(1-(x-30)*(x-30)/625))+12.5;
  gotoxy(x,y);
  delay(0.1);
   printf(".");
   }
   testshutdown();
   }
   }
void testshutdown(void)
{
int key;
key=bioskey(0);
if(key==0x11b)
{flag2=0;}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -