| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 918 人关注过本帖
标题:[求助]这个计算器的编程应该怎么改??
取消只看楼主 加入收藏
zwlhao
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-9-24
收藏
 问题点数:0 回复次数:1 
[求助]这个计算器的编程应该怎么改??
#include <process.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>
int number1,number2,answer,val;
class oopcalc {
public:
void calcadd();
void calcsub();
void calcdiv();
void calcmult();
void calcfartocel();
void calcceltofar();
void calcsroot();
void exitprog();
void menu();
void badinput();
private:
int add(int x, int y);
int sub(int x, int y);
int div(int x, int y);
int mult(int x, int y);
int fartocel(int x);
int celtofar(int x);
int sqroot(int x);
};
void oopcalc::calcadd()
{
cout << "The Add Function\n";
cout << "First number: ";
cin >> number1;
cout << "Second number: ";
cin >> number2;
answer = add(number1,number2);
cout << number1 << " + " << number2 << " = " << answer << endl;
cout << "Press any key to continue\n";
getch();
menu();
}
void oopcalc::calcsub()
{
cout << "The Subtract Function\n";
cout << "First number: ";
cin >> number1;
cout << "Second number: ";
cin >> number2;
answer = sub(number1,number2);
cout << number1 << " - " << number2 << " = " << answer << endl;
cout << "Press any key to continue\n";
getch();
menu();
}
void oopcalc::calcdiv()
{
cout << "The Divide Function\n";
cout << "First number: ";
cin >> number1;
cout << "Second number: ";
cin >> number2;
answer = div(number1,number2);
cout << number1 << " / " << number2 << " = " << answer << endl;
cout << "Press any key to continue\n";
getch();
menu();
}
void oopcalc::calcmult()
{
cout << "The Multiply Function\n";
cout << "First number: ";
cin >> number1;
cout << "Second number: ";
cin >> number2;
answer = mult(number1,number2);
cout << number1 << " x " << number2 << " = " << answer << endl;
cout << "Press any key to continue\n";
getch();
menu();
}
void oopcalc::calcfartocel()
{
cout << "The Farenheit to Celsius Function\n";
cout << "Enter a tempature in Farenheit: ";
cin >> number1;
answer = fartocel(number1);
cout << "The tempature in Celsius is " << answer << endl;
cout << "Press any key to continue\n";
getch();
menu();
}
void oopcalc::calcceltofar()
{
cout << "The Celsius to Farenheit Function\n";
cout << "Enter a tempature in Celsius: ";
cin >> number1;
answer = celtofar(number1);
cout << "The tempature in Farenheit is " << answer << endl;
cout << "Press any key to continue\n";
getch();
menu();
}
void oopcalc::calcsroot()
{
cout << "The Square Root Function\n";
cout << "First number: ";
cin >> number1;
answer = sqroot(number1);
cout << "The square root of " << number1 << " is " << answer << endl;
cout << "Press any key to continue\n";
getch();
menu();
}
void oopcalc::exitprog()
{
exit(-1);
}
void oopcalc::menu()
{
char input;
oopcalc a;
system("cls"); //执行系统命令:cls-清屏
cout << "==================MENU===============\n";
cout << "1: Add two numbers\n";
cout << "2: Subtract two numbers\n";
cout << "3: Divide two numbers\n";
cout << "4: Multiply two numbers\n";
cout << "5: Convert Farenheit to Celsius\n";
cout << "6: Convert Celsius to Farenheit\n";
cout << "7: Find the square root of a number\n";
cout << "8: Exit this program\n";
cout << "Choice: ";
cin >> input;
cout << "=====================================\n";
switch (input)
{
case '1': a.calcadd();
break;
case '2': a.calcsub();
break;
case '3': a.calcdiv();
break;
case '4': a.calcmult();
break;
case '5': a.calcfartocel();
break;
case '6': a.calcceltofar();
break;
case '7': a.calcsroot();
break;
case '8': a.exitprog();
break;
default: a.badinput();
}
}
void oopcalc::badinput()
{
cout << "BAD INPUT!\n";
cout << "Press any key to continue\n";
getch();
menu();
}
int oopcalc::add(int x, int y)
{
val = x + y;
return val;
}
int oopcalc::sub(int x, int y)
{
val = x - y;
return val;
}
int oopcalc::div(int x, int y)
{
val = x / y;
return val;
}
int oopcalc::mult(int x, int y)
{
val = x * y;
return val;
}
int oopcalc::fartocel(int x)
{
int cel = ((x - 32) * 5) / 9;
return cel;
}
int oopcalc::celtofar(int x)
{
int f;
f = x * 9 / 5 + 32;
return f;
}
int oopcalc::sqroot(int x)
{
int g = sqrt(x);
return g;
}
void main()
{
oopcalc s;
s.menu();
}

怎么改成:
(1)完善计算器程序,改为可对实数操作。
(2)完善程序,改为多个操作数基本四则运算,遇到0为止。
(3)增加函数,完成四则混合运算,注意算法要考虑运算符的优先级,对应增加主菜单选项
(4)添加语句,使四则运算具有测试功能,即计算机能够自动出题,并要求用户计算,同时计算机
判断用户计算的对错并打分,要求十题为一单元,加减运算是最高为两位数运算,乘法为两位数乘一位数
,除法是两位数或三位数除一位数,并要求没有余数。

谢谢各位大侠了!!!
搜索更多相关主题的帖子: 计算器 
2007-09-24 22:02
zwlhao
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-9-24
收藏
得分:0 
哦 谢谢啊 但我不太懂啊
可不可以帮我改下??
2007-09-24 22:33
快速回复:[求助]这个计算器的编程应该怎么改??
数据加载中...
 
   



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

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