论坛: 编程破解 标题: 设计课题四:计算器的设计 复制本贴地址    
作者: fatcat [xu09]    论坛用户   登录

   用C语言设计一个有加/减/乘/除功能的计算器。
基本界面与平常的计算器无太大的差别!
望知道者告之,不甚感激。。。

地主 发表时间: 05/20 11:28

回复: dizi0774 [dizi0774]   论坛用户   登录
这个最简单了,用一些图形函数(点,线,画框,画距形)就能写出界面了.
剩下的加减乘除什么的就用一个捕捉键盘动作的函数如:bioskey(i)大体上就差不多了.

B1层 发表时间: 05/20 21:05

回复: fatcat [xu09]   论坛用户   登录
能不能再讲清楚明白些呢?!
我还是有些不知道如何去做啊~~~~~~
谢谢!!

B2层 发表时间: 05/21 07:30

回复: fatcat [xu09]   论坛用户   登录
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#define IMAGE_SIZE 10
void draw_image(int x,int y);
void Putstar(void);
main()
{
 int graphdriver=DETECT;
 int graphmode,color;
 void *pt_addr;
 int x,y,maxx,maxy,midy,midx,i;
 unsigned int size;
 initgraph(&graphdriver,&graphmode,"");
 maxx=getmaxx();
 maxy=getmaxy();
 midx=maxx/2;
 x=0;
 midy=y=maxy/2;
 setcolor(YELLOW);
 settextstyle(TRIPLEX_FONT,HORIZ_DIR,4);
 settextjustify(CENTER_TEXT,CENTER_TEXT);
 outtextxy(midx,400,"AROUND THE WORLD");
 setbkcolor(BLACK);
 setcolor(RED);
 setlinestyle(SOLID_LINE,0,THICK_WIDTH);
 ellipse(midx,midy,130,50,160,30);
 setlinestyle(SOLID_LINE,0,NORM_WIDTH);
 draw_image(x,y);
 size=imagesize(x,y-IMAGE_SIZE,x+(4*IMAGE_SIZE),y+IMAGE_SIZE);
 pt_addr=malloc(size);
 getimage(x,y-IMAGE_SIZE,x+(4*IMAGE_SIZE),y+IMAGE_SIZE,pt_addr);
 Putstar();
 setcolor(WHITE);
 setlinestyle(SOLID_LINE,0,NORM_WIDTH);
 rectangle(0,0,maxx,maxy);
 while(! kbhit())
 {Putstar();
  setcolor(RED);
  setlinestyle(SOLID_LINE,0,THICK_WIDTH);
  ellipse(midx,midy,130,50,160,30);
  setcolor(BLACK);
  ellipse(midx,midy,130,50,160,30);
  for(i=0;i<=13;i++)
    {
     setcolor(i%2==0? LIGHTBLUE:BLACK);
     ellipse(midx,midy,0,360,100,100-8*i);
     setcolor(LIGHTBLUE);
     ellipse(midx,midy,0,360,100-8*i,100);
    }
     putimage(x,y-IMAGE_SIZE,pt_addr,XOR_PUT);
     x=x>=maxx? 0:x+6;
     putimage(x,y-IMAGE_SIZE,pt_addr,XOR_PUT);
  }
  free(pt_addr);
  closegraph();
  return;
}

void draw_image(int x,int y)
{
 int arw[11];
 arw[0]=x+10;arw[1]=y-10;arw[2]=x+34;arw[3]=y-6;
 arw[4]=x+34;arw[5]=y+6;arw[6]=x+10;arw[7]=y+10;
 arw[9]=x+10;arw[10]=y-10;
 moveto(x+10,y-4);
 setcolor(14);
 setfillstyle(1,4);
 linerel(-3*10,-2*8);
 moveto(x+10,y+4);
 linerel(-3*10,+2*8);
 moveto(x+10,y);
 linerel(-3*10,0);
 setcolor(3);
 setfillstyle(1,LIGHTBLUE);
 fillpoly(4,arw);
}

void Putstar(void)
{
 int seed=1858;
 int i,dotx,doty,h,w,color,maxcolor;
 maxcolor=getmaxcolor();
 w=getmaxx();
 h=getmaxy();
 srand(seed);
 for(i=0;i<250;++i)
 {
  dotx=i+random(w-1);
  doty=1+random(h-1);
  color=random(maxcolor);
  setcolor(color);
  putpixel(dotx,doty,color);
  circle(dotx+1,doty+1,1);
  }
 srand(seed);
}
程序还有些不完整。
请大家看看有没有什么好的建议与修改的地方。。。

B3层 发表时间: 05/24 15:35

回复: dizi0774 [dizi0774]   论坛用户   登录
我看你这个程序不象是计算器的,写的倒象是个动画程序。

B4层 发表时间: 05/25 00:16

回复: group [group]   论坛用户   登录
很久以前用VB写了一个

B5层 发表时间: 05/26 02:34

回复: sainthero [sainthero]   论坛用户   登录
呵呵
这个事我想起了大一的习题
是试验课的
当时用的是谭浩强的那本书作课本
里面什么都没有,更谈不到界面的设计
后来又另外找了些参考书,才好不容蒙混过关
现在改行用delphi了
也作了个计算器,感觉上阵是简单多了阿


B6层 发表时间: 05/29 00:18

回复: dirboys [dirboys]   论坛用户   登录
谭浩强的那本书根本就是骗骗外行的,太简单了而且编写的时候根本不考虑使用者的兴趣和偏向。泛泛而谈,而且内容老套。

B7层 发表时间: 06/05 10:55

回复: group [group]   论坛用户   登录
入门很好

B8层 发表时间: 06/08 02:11

论坛: 编程破解

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号