| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1076 人关注过本帖
标题:带外框的计算器(做的作业,分享下)
取消只看楼主 加入收藏
漈轩
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-9-13
结帖率:100%
收藏
 问题点数:0 回复次数:1 
带外框的计算器(做的作业,分享下)
c++.rar (45.65 KB)
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include <conio.h>
#include <windows.h>
#include<dos.h>

//----------------坐标定位函数----------------

void gotoxy(int x, int y)
{
    COORD pos = {x,y};
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(hOut, pos);
}

//----------------文本闪烁函数------------------

void SetColor(unsigned short ForeColor=7,
              unsigned short BackGroundColor=0)
{
    HANDLE hCon=GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hCon,ForeColor|BackGroundColor);
}

//------------------计算部分------------------

double Add(double num1, double num2) //加
{
 return num1 + num2;
}
double Sub(double num1, double num2) //减
{
 return num1 - num2;
}
double Mul(double num1, double num2) //乘
{
 return num1 * num2;
}
double Div(double num1, double num2) //除
{
    if (num2 == 0)
    {
                gotoxy (4,5);
        printf("input error!");//报错,除数不能为零
        return 0;
    }
    return num1 / num2;
}
void Menu()
{
    double number1, number2;
    double result=0;
    char chooce;
    scanf("%lf%c%lf",&number1,&chooce,&number2);
    switch(chooce)
    {
    case '+':
        result = Add(number1,number2);
        break;
    case '-':
        result = Sub(number1,number2);
        break;
    case '*':
        result = Mul(number1,number2);
        break;
    case '/':
        result = Div(number1,number2);
        break;
    default:
        printf("input error!");
        break;
    }
    gotoxy(10,4);
    printf("=%f\n",result);
    gotoxy (4,19);
    printf("Continue? (Y/N)");//输入Y或N决定是否进行下一次计算
    chooce = getch();
    if(chooce == 'n' || chooce == 'N')
    {
        exit(0);
    }
}
void main()
{
   
    char hit;
    while(1)
      {
           system("cls");//清除以输入的算式
       gotoxy(1,2);
       printf("\n");
           printf(" ┌───────────────┐ \n");
           printf(" │                              │ \n");
           printf(" │                              │ \n");
           printf(" ├───────────────┤ \n");
           printf(" │   1    2    3       +     -  │ \n");
           printf(" │                              │ \n");
           printf(" │   4    5    6       *     /  │ \n");
           printf(" │                              │ \n");
           printf(" │   7    8    9      =    \x1b     \n");
           printf(" │                              │ \n");
           printf(" │   0    .                 End │ \n");
           printf(" └───────────────┘ \n");
       gotoxy(4,17);
       printf("提示:按End键终止计算!");

//---------------------文本闪烁效果--------------------

       while(!kbhit())//当没有按键被按下时
       {
           for(int i=2; i<5; i++)
           {
               SetColor(i);//变换绿,兰,红色
               Sleep(400);
               gotoxy(4,1);
               printf("This is a simple calculator!");
                   SetColor();
           }
       }
   
//----------------------检测按键-----------------------

       while(kbhit())//有按键按下后
       {
           hit=getch();
           if(hit==-32)
               exit(0);//按End结束计算
           else break;
       }
       gotoxy(4,4);
       system("color 7");//文本停止闪烁并恢复白色
       Menu();
       }
}
搜索更多相关主题的帖子: 计算器 作业 分享 
2010-10-10 12:54
漈轩
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-9-13
收藏
得分:0 
回复 3楼 sunyh1999
呵呵,多谢指教
2010-10-16 23:51
快速回复:带外框的计算器(做的作业,分享下)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012765 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved