| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 701 人关注过本帖
标题:c++程序该怎么运行的啊!!
只看楼主 加入收藏
newCpp
Rank: 5Rank: 5
来 自:火星
等 级:职业侠客
威 望:3
帖 子:256
专家分:375
注 册:2009-8-17
结帖率:97.83%
收藏
已结贴  问题点数:20 回复次数:2 
c++程序该怎么运行的啊!!

#include "stdafx.h"
#include <windows.h>
#include <iostream>
using namespace std;

#define CONSOLE_MAX_ROW_BY_M 80  // 控制台程序的列宽使用多字符
#define CONSOLE_MAX_ROW_BY_U 40  // 控制台程序的列宽使用宽字符
#ifdef UNICODE
#define _tcout  wcout
#define _tcin   wcin
#else
#define _tcout  cout
#define _tcin   cin
#endif

namespace Minsi
{
    enum E_OPERATOR
    {
        E_OPERATOR_UNKNOW,
        E_OPERATOR_ADD,
        E_OPERATOR_SUB,
        E_OPERATOR_MUL,
        E_OPERATOR_DIV,
#ifdef UNICODE
        E_OPERATOR_TO_WORD = 0x7FFF,
#else
        E_OPERATOR_TO_BYTE = 0x7F,
#endif
    };

    // 初始化
    BOOL    Init(VOID);

    // 显示Logo
    BOOL    Logo(DWORD dwTimeMills/*单位毫秒*/, TCHAR* strText,/*Logo文本*/ TCHAR cAdornChar/*装饰字符*/);

    // 获取字符串显示宽度
    DWORD   GetShowWidth(TCHAR* strText);

    // 获取用户输入的数
    BOOL    AchieveInputNumber(DOUBLE& dNumber, BOOL IfErrorIsClear = TRUE);

    // 获取用户输入的运算符
    BOOL    AchieveInputOperator(E_OPERATOR& eOperator, BOOL IfErrorIsClear = TRUE);

    // 获取用户输入的字符
    BOOL    AchieveInputChar(TCHAR& cChar, BOOL IfErrorIsClear = TRUE);
};

INT _tmain(VOID)
{
    Minsi::Init();
    Minsi::Logo(1000, _T("C,C++,游戏设计II(计算器)"), _T('☆'));

    BOOL                bRet = FALSE;
    DOUBLE              dFirstNumber = 0.0f;
    Minsi::E_OPERATOR   eOperator = Minsi::E_OPERATOR_UNKNOW;
    DOUBLE              dSecondNumber = 0.0f;
    TCHAR               cChar = _T('\0');

    while (TRUE)
    {
        _tcout << _T("请输入表达式\n:");
        do
        {
            bRet = Minsi::AchieveInputNumber(dFirstNumber);
            if (!bRet)
            {
                _tcout << _T("输入的第一个操作数非法,请重新输入整个表达式\n:");
                continue;
            }

            bRet = Minsi::AchieveInputOperator(eOperator);
            if (!bRet)
            {
                _tcout << _T("输入的运算类型非法,请重新输入整个表达式\n:");
                continue;
            }

            bRet = Minsi::AchieveInputNumber(dSecondNumber);
            if (!bRet)
            {
                _tcout << _T("输入的第二个操作数非法,请重新输入整个表达式\n:");
                continue;
            }
            break;
        } while (TRUE);

        switch (eOperator)
        {
        case Minsi::E_OPERATOR_ADD:
            {
                _tcout << dFirstNumber + dSecondNumber << endl;
            }break;
        case Minsi::E_OPERATOR_SUB:
            {
                _tcout << dFirstNumber - dSecondNumber << endl;
            }break;
        case Minsi::E_OPERATOR_MUL:
            {
                _tcout << dFirstNumber * dSecondNumber << endl;
            }break;
        case Minsi::E_OPERATOR_DIV:
            {
                _tcout << dFirstNumber / dSecondNumber << endl;
            }break;
        default:
            {
                ;
            }
        }

        _tcout << _T("按任意键继续, (Q/q)退出") << endl;
        cChar = _gettch();
        if (cChar == _T('q') || cChar == _T('Q'))
        {
            _tcout << _T("您已经选择退出") << endl;
            _tsystem(_T("pause"));
            return 0;
        }
    }
}

BOOL Minsi::Init(VOID)
{
    setlocale(LC_ALL, "Chinese");
    return TRUE;
}

BOOL Minsi::Logo(DWORD dwTimeMills, TCHAR* strText, TCHAR cAdornChar)
{
    CONST DWORD dwCharCount = Minsi::GetShowWidth(strText);
    if (dwCharCount > CONSOLE_MAX_ROW_BY_M)
    {
        return FALSE;
    }
    DWORD nStarCount = (CONSOLE_MAX_ROW_BY_M - dwCharCount) / 2;
    DWORD dwInterval = dwTimeMills / nStarCount;
    for (DWORD i = 0; i <= nStarCount; i++)
    {
        if (i == (nStarCount/2))
        {
            _tcout << strText;
            ::SleepEx(dwInterval, TRUE);
            continue;
        }
        _tcout << cAdornChar;
        ::SleepEx(dwInterval, TRUE);
    }
    return TRUE;
}

DWORD Minsi::GetShowWidth(TCHAR* strText)
{
    DWORD dwWidth = 0;
    for (DWORD i = 0; strText[i]; i++)
    {
        if (strText[i] >= 0x200)
        {
            dwWidth += 2;
        }
        else
        {
            dwWidth ++;
        }
    }
    return dwWidth;
}

BOOL Minsi::AchieveInputNumber(DOUBLE& dNumber, BOOL IfErrorIsClear)
{
    _tcin >> dNumber;
    if (_tcin)
    {
        return TRUE;
    }
    if (IfErrorIsClear)
    {
        _tcin.clear();
        _tcin.sync();
    }
    return FALSE;
}

BOOL Minsi::AchieveInputOperator(E_OPERATOR& eOperator, BOOL IfErrorIsClear)
{
    TCHAR Operator;
    _tcin >> Operator;
    if (_tcin)
    {
        switch(Operator)
        {
        case _T('+'):
            {
                eOperator = E_OPERATOR_ADD;
                return TRUE;
            }break;
        case _T('-'):
            {
                eOperator = E_OPERATOR_SUB;
                return TRUE;
            }break;
        case _T('*'):
            {
                eOperator = E_OPERATOR_MUL;
                return TRUE;
            }break;
        case _T('/'):
            {
                eOperator = E_OPERATOR_DIV;
                return TRUE;
            }break;
        }
    }
    if (IfErrorIsClear)
    {
        _tcin.clear();
        _tcin.sync();
    }
    return FALSE;
}

BOOL Minsi::AchieveInputChar(TCHAR& cChar, BOOL IfErrorIsClear)
{
    _tcin >> cChar;
    if (_tcin)
    {
        return TRUE;
    }
    if (IfErrorIsClear)
    {
        _tcin.clear();
        _tcin.sync();
    }
    return FALSE;
}
这个计算器程序改怎么运行的啊!
一管理大大写的计算器。晕,有了程序看不懂别说,运行都不会运行
谁能帮忙讲解一下这段代码的啊!
谢谢!!
搜索更多相关主题的帖子: 运行 
2009-09-13 14:18
blueboy82006
Rank: 5Rank: 5
来 自:幻想世界
等 级:贵宾
威 望:16
帖 子:1227
专家分:57
注 册:2007-7-23
收藏
得分:14 
这得是个工程,
WIN32控制台应用程序吧

2009-09-13 18:27
kxalpah
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:21
专家分:124
注 册:2009-9-14
收藏
得分:0 
编译链接呗
2009-09-17 18:01
快速回复:c++程序该怎么运行的啊!!
数据加载中...
 
   



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

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