四则运算计算器_第1页
四则运算计算器_第2页
四则运算计算器_第3页
四则运算计算器_第4页
四则运算计算器_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

四则运算计算器一、程序功能简介可以计算整数四则运算,例如:7+5*(3+4)二、课程设计要求(1)按要求在提供的框架程序源程序的基础上对程序进行修改、补充,并调试通过。(2)修改主程序结构,使程序可以反复运算,直到选择退出为止。(3)增加文件的输入输出功能,是计算过的式子和结果可以根据需要设置命令存储到文件中,同时也可以直接从文件中输入四则运算的式子,运算后,结果输出到原文件中。(4)扩充程序功能,使程序适合实型数运算。(5)增加程序的判断功能,当有非法的输入时( 如字母等),给出提示信息并退出运算。(6)扩充程序功能,使程序可以进行关系表达式(=, /* In Out printf() */#include /* pow(M,n) 开 Mn */#include /* strcpy. */#include /* atof. */#include /* getch(). */#define Max 256 /* 表达式长度定义,可以在这里调节 */* = */* 函数声明 */ /* 计算字符串(不带括号的) ,计算的核心部分*/char *Calculate_f(char *chpString);/* 主操作过程,输入式子串,返回 double 型结果 */double Operation(char *chpString);/* Source1、Source2 加起来到 Destination 中*/char *AddStrings_f(char *chpDestination, char *chpSource1, char *chpSource2);/* 寻找 char_to_find 在 Source 中的位置,后移一位 */int FindChar(char *chpSource, char chCharToFind);/* 获取字符串的长度 */int Len_f(char *chpSource);/* 将 Source 左边 Length 个字符放在 Destination 中*/char *Left_f(char *chpSource, char *chpDestination, int nLength);/* 将 Source 右边 Length 个字符放在 Destination 中*/char *Right_f(char *chpSource, char *chpDestination, int nLength) ;/* 将 Source 中从 Start 开始 Length 长度的字符串截下来放在 Destination 中*/char *Midstr_f(char *chpSource, char *chpDestination, int nStart, int nLength);/* 在字符串中删除一个字符 del + */void DelChar(char *chpString,int sPos);/* 在字符串中插入一个字符 */int InsChar(char *chpString,int sPos,char sChar);/* 替换字符串中的某个字符 */void StrReplace(char *chpString,char strOld ,char strNew);/* 将实数值变为字符串*/char *Str_f(double nValue, char *chpDestination);/* 计算字符串的值,返回实数值 */double Val_f(char *chpSource) ;/* = */* 主菜单. */int Menu_Sel();/* 手工输入表达式求值 */int Do_Press();/* 文件导入表达式求值 */int Do_File();/* 文件检查 0 重新输入,1 继续 */int FileChk(char *FN);/* 式子的合法性检查 0 含有非法字符, 1 正常 2 关系运算 */int StrChk(char *chpSource);/* 关系运算 */int Nexus(char strIn);/* 显示关于 */void Show_About();/* = */* 全局变量声明 */int Debug=0; /* 调试信息显示开关 0 不显示,1 显示 */char *TF_Info3=“FALSE“,“TURE“,“Error“; /* 关系运算信息 */* 将 Source 左边 Length 个字符放在 Destination 中*/char *Left_f(char *chpSource, char *chpDestination, int nLength) *(chpDestination+ -nLength+1)=0; /* 设置目标字符串最后一个为 NULL*/while (nLength=0) /* 直到目标字符串的最后一个 */*(chpDestination+nLength)=*(chpSource+nLength-);return chpDestination;/* 将 Source 中从 Start 开始 Length 长度的字符串截下来放在 Destination 中 */char *Midstr_f(char *chpSource, char *chpDestination, int nStart, int nLength)chpSource+=nStart-1; /* 设置源起点 */*(chpDestination+-nLength+1)=0; /* 设置目标字符串最后一个为 NULL */while (nLength=0) /* 直到目标字符串的最后一个 */*(chpDestination+nLength)=*(chpSource+nLength-);return chpDestination;/* 将 Source 右边 Length 个字符放在 Destination 中 */char *Right_f(char *chpSource, char *chpDestination, int nLength) while (*chpSource != 0)chpSource+; /* 将源指针移到最后 */chpSource-=nLength; /* 将源指针跳到开始复制点 */*(chpDestination+-nLength+1)=0; /* 设置目标字符串最后一个为 NULL */while (nLength=0) /* 直到目标字符串的最后一个 */*(chpDestination+nLength)=*(chpSource+nLength-);return chpDestination;/* 在字符串中删除一个字符 del + */void DelChar(char *chpString,int sPos)char sBufMax;int nCount;strcpy(sBuf,chpString);for(nCount=sPos;sBufnCount;nCount+)sBufnCount=sBufnCount+1;strcpy(chpString,sBuf);/* 在字符串中插入一个字符 */int InsChar(char *chpString,int sPos,char sChar)char sBufMax;int iLen;int nCount;strcpy(sBuf,chpString);iLen=strlen(sBuf);if(iLen=sPos;nCount-)sBufnCount+1=sBufnCount;sBufsPos=sChar;strcpy(chpString,sBuf);elsereturn 0;return 1;/* 替换字符串中的某个字符 # to - */void StrReplace(char *chpString,char strOld ,char strNew)char sBufMax;int nCount=0;strcpy(sBuf,chpString);while(sBufnCount)if (sBufnCount=strOld) sBufnCount=strNew;nCount+;strcpy(chpString,sBuf);/* 寻找 char_to_find 在 Source 中的位置,后移一位*/int FindChar(char *chpSource, char chCharToFind) int nPos=0;while(*(chpSource+nPos)!=0) /* 直到目标字符串的最后一个 */if (chCharToFind = *(chpSource+nPos+) /* 比较 */return nPos; /* 返回第一个出现点,加一 */return 0;/* 获取字符串的长度 */int Len_f(char *chpSource)int nRetval=0; /* 初始化长度 */while (*(chpSource+nRetval+)!=0) /* 移动指针到 Null */return -nRetval;/* 将实数值变为字符串*/char *Str_f(double nValue, char *chpDestination) char strTmpMax;gcvt(nValue,sizeof(double)+1,strTmp); /* 实数值转字符串 */if(strTmp0=-) /* 将 - 负号 转译为 # */strTmp0=#;strcpy(chpDestination,strTmp);if(Debug) printf(“.Conversion Double to String:%f - %sn“,nValue,chpDestination);return chpDestination;/* Source1、Source2 加起来到 Destination 中*/char *AddStrings_f(char *chpDestination, char *chpSource1, char *chpSource2) char *chpTempdest=chpDestination; while(*chpSource1!=0) /* 先把 chpSource1 放入 chpDestination */*(chpTempdest+)=*(chpSource1+);while(*chpSource2!=0) /* 在 chpDestination 后继续写入 chpSource2 */*(chpTempdest+)=*(chpSource2+);*chpTempdest=0; /* 指针位置归零 */return chpDestination;/* 计算字符串的值,返回实数值 */double Val_f(char *chpSource)

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论