大三c++程序设计 计算器 高分悬赏

设计一个能实现计算器功能的C++程序1.基本运算:+,-,*,/;2.三角函数:sin,cos,tan;3.进制转换:八进制,十进制,十六进制注:1,用四个类写(基本运算... 设计一个能实现计算器功能的C++程序
1.基本运算:+,-,*,/;
2.三角函数:sin,cos,tan;
3.进制转换:八进制,十进制,十六进制
注:1,用四个类写(基本运算,三角函数,进制转换,主函数)
2,Vc6.0环境下运行
3,要有注释
运行出来要有主菜单,例如:
cout<<" 主菜单 "<<endl;
cout<<"*******************"<<endl;
cout<<"* 1.基本运算 *"<<endl;
cout<<"* 2.三角函数 *"<<endl;
cout<<"* 3.进制转换 *"<<endl;
cout<<"*******************"<<endl;

cout<<" 主菜单 "<<endl;
cout<<"*******************"<<endl;
cout<<"* 1.加法运算 *"<<endl;
cout<<"* 2.减法运算 *"<<endl;
cout<<"* 3.乘法运算 *"<<endl;
cout<<"* 4.除法运算 *"<<endl;
cout<<"* 5.取余运算 *"<<endl;
cout<<"* 6.退出 *"<<endl;
cout<<"*******************"<<endl;
cout<<"请输入菜单项(1-6):";
展开
 我来答
叔叔不骗你
推荐于2017-09-16 · TA获得超过852个赞
知道小有建树答主
回答量:370
采纳率:0%
帮助的人:362万
展开全部
/*本程序较简单
你如果有兴趣可以用栈实现进制转换
用运算符重载实现加减乘除取余等
自己编写算法实现三角函数计算等等
时间关系就写到这了*/
#include <iostream>
#include <cmath>
#include <stdlib.h>
using namespace std;
#define pi 3.14159265

/************************************************************/
class Trigonometric
{//三角函数实现
private:
double number;//要操作的数
char ch2;//选择控制
public:
void print1();//界面输出
void set1(double num)//传值给操作函数
{ number=num;}
};
void Trigonometric::print1()
{
cout<<"\t\t请输入一个弧度数:"<<endl;
cin>>number;
set1(number);
cout<<"\t\t 1.求sin(a)"<<endl;
cout<<"\t\t 2.求cos(a)"<<endl;
cout<<"\t\t 3.求tan(a)"<<endl;
cout<<"\t\t 4.求全部!"<<endl;
cin>>ch2;

back3:

if(ch2=='1')
cout<<"sin("<<number<<")="<<sin(number)<<endl;
else if(ch2=='2')
cout<<"cos("<<number<<")="<<cos(number)<<endl;
else if(ch2=='3')
cout<<"tan("<<number<<")="<<tan(number)<<endl;
else if(ch2=='4')
{
cout<<"sin("<<number<<")="<<sin(number)<<endl;
cout<<"cos("<<number<<")="<<cos(number)<<endl;
cout<<"tan("<<number<<")="<<tan(number)<<endl;
}
else
{
cout<<"\t\t输入有误!请重新选择:"<<endl;
cin>>ch2;
goto back3;
}

}

/************************************************************/
class HexBinDecOct
{//进制转换
private:
char str2[10];//存储二进制
char str8[10];//存储八进制
char str16[10];//存储十六进制
char ch2;//选择控制
int number;//要转换的数
public:
void print2();
void set2(double num)
{ number=num;}
void conversionAll(int number);//全部转换
char sixteen(int number);//转换为十六进制
char eight(int number);//转换为八进制
char two(int number);//转换为二进制

};
void HexBinDecOct::print2()
{
cout<<"\t\t请输入一个十进制数:"<<endl;
cin>>number;
set2( number);
cout<<"\t\t ***********************************"<<endl;
cout<<"\t\t * 1.十进制转换为二进制 *"<<endl;
cout<<"\t\t * 2.十进制转换为八进制 *"<<endl;
cout<<"\t\t * 3.十进制转换为十六进制 *"<<endl;
cout<<"\t\t * 4.十进制转换为二、八、十六进制 *"<<endl;
cout<<"\t\t *请选择:1-4 *"<<endl;
cout<<"\t\t ***********************************"<<endl;
cin>>ch2;

back4:

if(ch2=='1')//1.十进制转换为二进制
cout<<"\t\t"<<number<<"\t转换为二进制:"<<two(number)<<endl;

else if(ch2=='2')//十进制转换为八进制
cout<<"\t\t"<<number<<"\t转换为八进制:"<<eight(number)<<endl;

else if(ch2=='3')//十进制转换为十六进制
cout<<"\t\t"<<number<<"\t转换为十六进制:"<<sixteen(number)<<endl;

else if(ch2=='4')//十进制转换为二、八、十六进制
conversionAll(number);
else
{
cout<<"\t\t输入有误!请重新选择:"<<endl;
cin>>ch2;//重新选择
goto back4;//重新转换
}

}
char HexBinDecOct::two(int number)
{
itoa(number, str2, 2);
return *str2;
}
char HexBinDecOct::eight(int number)
{
itoa(number, str8, 8);
return *str8;
}
char HexBinDecOct::sixteen(int number)
{
itoa(number, str16, 16);
return *str16;
}
void HexBinDecOct::conversionAll(int number)
{
itoa(number, str2, 2);
itoa(number, str8, 8);
itoa(number, str16, 16);
cout<<"\t\t********************"<<endl;
cout<<"\t\t* 1.转换为二进制 *"<<str2<<endl;
cout<<"\t\t* 2.转换为八进制 *"<<str8<<endl;
cout<<"\t\t* 3.转换为十六进制*"<<str16<<endl;
cout<<"\t\t* 请选择:1-3 *"<<endl;
cout<<"\t\t********************"<<endl;
}
/************************************************************/
class Calculate
{//一般计算
private:
double sum;//存储运算结果
char ch2;//选择控制
double num1,num2;//两个操作数
public:
void set3(double num1,double num2)//赋值
{ num2=num2;num1=num1;}
void print3();
double add(double num1,double num2);//加
double subtract(double num1,double num2);//减
double multiplication(double num1,double num2);//乘
double divide(double num1,double num2);//除
double mod(double num1,double num2);//取余
};

void Calculate::print3()
{
cout<<"\t\t请输入两个数:"<<endl;
cin>>num1>>num2;
set3( num1,num2);
cout<<"\t\t*******************"<<endl;
cout<<"\t\t* 1.加法运算 *"<<endl;
cout<<"\t\t* 2.减法运算 *"<<endl;
cout<<"\t\t* 3.乘法运算 *"<<endl;
cout<<"\t\t* 4.除法运算 *"<<endl;
cout<<"\t\t* 5.取余运算 *"<<endl;
cout<<"\t\t*******************"<<endl;
cout<<"\t\t请输入菜单项(1-6):";
cin>>ch2;
back2:

if(ch2=='1')
{// 1.加法运算
cout<<"\t\t"<<num1<<'+'<<num2<<'='<<add(num1,num2)<<endl;
}
else if(ch2=='2')
{// 2.减法运算
cout<<"\t\t"<<num1<<'-'<<num2<<'='<<subtract(num1,num2)<<endl;
}
else if(ch2=='3')
{// 3.乘法运算
cout<<"\t\t"<<num1<<'*'<<num2<<'='<<multiplication(num1,num2)<<endl;
}
else if(ch2=='4')
{// 4.除法运算
cout<<"\t\t"<<num1<<'/'<<num2<<'='<<divide(num1,num2)<<endl;
}
else if(ch2=='5')
{// 5.取余运算
cout<<'\t\t'<<num1<<'%'<<num2<<'='<<mod(num1,num2)<<endl;
}

else
{
cout<<"\t\t输入有误!请重新选择:"<<endl;
cin>>ch2;
goto back2;
}

}
double Calculate::add(double num1,double num2)
{
return sum=num1+num2;
}
double Calculate::subtract(double num1,double num2)
{
return sum=num1-num2;
}
double Calculate::multiplication(double num1,double num2)
{
return sum=num1*num2;
}
double Calculate::divide(double num1,double num2)
{
if(num2==0)
return sum=num1/num2;
else return 0;
}
double Calculate::mod(double num1,double num2)
{
if(num2==0)
return sum=(int)num1%(int)num2;
else return 0;
}

/************************************************************/
int main()
{
//int num1=0,num2=0,number=0;
Trigonometric tri;//三角函数对象
HexBinDecOct hex;//进制转换对象
Calculate cal;//一般计算对象
char ch1,ch3;
back1:
{
do{
cout<<"\t\t*****主菜单**********"<<endl;
cout<<"\t\t* *"<<endl;
cout<<"\t\t* 1. 基本运算 *"<<endl;
cout<<"\t\t* 2. 三角函数 *"<<endl;
cout<<"\t\t* 3. 进制转换 *"<<endl;
cout<<"\t\t* *"<<endl;
cout<<"\t\t* 请选择:1---3 *"<<endl;
cout<<"\t\t*********************"<<endl;
cin>>ch1;
if(ch1=='1')
{// 1.基本运算
cal.print3();
}
else if(ch1=='2')
{// 2.三角函数
tri.print1();
}
else if(ch1=='3')
{// 3.进制转换
hex.print2();
}
else
{
cout<<"输入有误!"<<endl;
goto back1;
}
cout<<"again?(y/n)"<<endl;
cin>>ch3;
}while(ch3=='y'||ch3=='Y');
};
return 0;
}

除了点问题,现在改好了,希望是你想要的
wangruan324
2010-12-28
知道答主
回答量:3
采纳率:0%
帮助的人:0
展开全部
实用计算器之程序设计

[摘 要]多用计算器的构思及设计代码

[关键词]多用计算器;设计

数值计算可以说是日常最频繁的工作了,WIN98提供了“计算器”软件供用户使用,该软件可以处理一般的一步四则运算,例如:3+2、5/3等等,但在日常中用户经常遇到多步四则运算问题,例如:3+4*5-4/2,45*34/2+18*7等等,那么该个计算器就无法胜任了,作者制作了一个实用的计算器,该计算器新增不少功能:(程序界面如图)

1.可以实现连续的四则运算

2.可以实现输入式子的显示

3.可以方便计算个人所得税

4.鼠标、键盘均可输入数据

5.操作界面友好

6.击键可发声

构建该个计算器所需研究及解决的核心问题有如下几个:1、连乘求值?2、字符显示 3、键盘输入?4、击键发声?5、个人所得税法规,为了使大家对程序有更一步认识,现将代码提供给读者参考:

*定义数组及窗体变量

Dim number2(0 To 50) As Double
Dim number(0 To 50) As Double
Dim z As Integer
Dim k As Integer, r As Integer
Dim j As Integer
Dim str As String

*调用名为“playsound”的API函数

Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private Const SND_FILENAME = &H20000?
Private Const SND_ASYNC = &H1?
Private Const SND_SYNC = &H0

*判断通用过程

Sub pianduan(p As String)
r = 0
Dim i As Integer, l As Integer, h As Integer
h = 0
i = 1
If InStr(Trim$(p), "*") <> 0 Then
k = k + 1
End If
If InStr(Trim$(p), "/") <> 0 Then
r = r + 1
End If
End Sub

*连乘通用过程(略)

*各按钮事件过程

Private sub Command1_Click(Index As Integer)
PlaySound App.Path & "\start.wav", 0, SND_SYNC
Text1.Text = Text1.Text + Command1(Index).Caption
Text2.Text = Text2.Text + Command1(Index).Caption
Text1.SetFocus
End Sub

rivate sub Command10_Click()
PlaySound App.Path & "\start.wav", 0, SND_SYNC
str = Text3.Text
End Sub

Private sub Command11_Click()
PlaySound App.Path & "\start.wav", 0, SND_SYNC
Text3.Text = str
End Sub

rivate sub Command2_Click()
PlaySound App.Path & "\start.wav", 0, SND_SYNC
Dim totle As Double
Dim n As Integer
Call pianduan(Text1.Text)
If k >= 1 Or r >= 1 Then
Call liancheng(totle)
number2(z) = totle
If Mid$(Trim$(Text1.Text), 1, 1) = "-" Then
number2(z) = -totle
End If
k = 0: r = 0
Else
number2(z) = Val(Text1.Text)
End If
Text1.Text = ""
Text2.Text = Text2 + "+"
z = z + 1
Text1.SetFocus
End Sub

rivate sub Command3_Click()
PlaySound App.Path & "\start.wav", 0, SND_SYNC
Dim totle As Double
Dim n As Integer
Call pianduan(Text1.Text)
If k >= 1 Or r >= 1 Then
Call liancheng(totle)
number2(z) = totle
If Mid$(Trim$(Text1.Text), 1, 1) = "-" Then
number2(z) = -totle
End If
k = 0: r = 0
Else
number2(z) = Val(Text1.Text)
End If
Text1.Text = ""
Text2.Text = Text2 + "-"
Text1.Text = Text1.Text & "-"
z = z + 1
Text1.SetFocus
End Sub

Private sub Command4_Click()
PlaySound App.Path & "\start.wav", 0, SND_SYNC
Text2.Text = Text2.Text + "*"
Text1.Text = Text1.Text + "*"
Text1.SetFocus
End Sub

rivate sub Command5_Click()
PlaySound App.Path & "\start.wav", 0, SND_SYNC
Text2.Text = Text2 + "/"
Text1.Text = Text1 + "/"
Text1.SetFocus
End Sub

Private sub Command6_Click()
PlaySound App.Path & "\sound.wav", 0, SND_SYNC
Dim totle As Double
Dim n As Integer
Call pianduan(Text1.Text)
If k >= 1 Or r >= 1 Then
Call liancheng(totle)
number2(z) = totle
If Mid$(Trim$(Text1.Text), 1, 1) = "-" Then
number2(z) = -totle
End If
k = 0: r = 0
Else
number2(z) = Val(Text1.Text)
End If
Text1.Text = ""
z = z + 1
Dim dengyu As Double
Dim v As Integer
For v = 0 To 50
dengyu = dengyu + number2(v)
Next v
If dengyu < 0 Then
Text3.ForeColor = &HFF&
Else
Text3.ForeColor = &HFF0000
End If
Text3.Text = dengyu
Text1.SetFocus
If Len(Text3.Text) >= 14 Then
calcresult.Show
End If
End Sub

rivate sub Command7_Click()
PlaySound App.Path & "\start.wav", 0, SND_SYNC
z = 0: k = 0: r = 0: j = 0
Dim i As Integer
For i = 0 To 50
number(i) = 0
number2(i) = 0
Next i
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text1.SetFocus
End Sub

rivate sub Command8_Click()
PlaySound App.Path & "\start.wav", 0, SND_SYNC
If Val(Text3.Text) = 0 Then
MsgBox "除数不能为0!"
Exit Sub
End If
Text3.Text = 1 / Val(Text3.Text)
End Sub

Private sub Command9_Click()
PlaySound App.Path & "\start.wav", 0, SND_SYNC
Text3.ForeColor = &HFF0000
Text3.Text = Val(Text3.Text) * Val(Text3.Text)
End Sub

rivate sub muninternet_Click()
Dim i
i = Shell("C:\Program Files\InternetExplorer\iexplore.exe", vbMaximizedFocus)
End Sub

rivate sub munmp3_Click()
Dim i
i = Shell("C:\Program Files\Windows Media Player\mplayer2", vbNormalNoFocus)
End Sub

Private sub munsm_Click()
Dialog.Show
End Sub

rivate sub muntax_Click()
tax.Show
End Sub

rivate sub munver_Click()
ver.Show
End Sub

rivate sub notepad_Click()
Dim i

i = Shell("c:\windows\notepad", vbNormalFocus)
End Sub

Private sub Text1_KeyPress(KeyAscii As Integer)
PlaySound App.Path & "\start.wav", 0, SND_SYNC
Dim num As Integer
num = Val(KeyAscii)
If num > 47 And num < 58 Then

Text1.Text = Text1.Text + CStr(num - 48)
Text2.Text = Text2.Text + CStr(num - 48)
End If
If num = 46 Then
Text1.Text = Text1.Text + "."
Text2.Text = Text2.Text + "."
End If
If KeyAscii = 43 Then
Dim totle As Double
Dim n As Integer
Call pianduan(Text1.Text)
If k >= 1 Or r >= 1 Then
Call liancheng(totle)
number2(z) = totle
If Mid$(Trim$(Text1.Text), 1, 1) = "-" Then
number2(z) = -totle
End If
k = 0: r = 0
Else
number2(z) = Val(Text1.Text)
End If
Text1.Text = ""
Text2.Text = Text2 + "+"
z = z + 1
End If
If KeyAscii = 45 Then
Call pianduan(Text1.Text)
If k >= 1 Or r >= 1 Then
Call liancheng(totle)
number2(z) = totle
If Mid$(Trim$(Text1.Text), 1, 1) = "-" Then
number2(z) = -totle
End If
k = 0: r = 0
Else
number2(z) = Val(Text1.Text)
End If
Text1.Text = ""
Text2.Text = Text2 + "-"
Text1.Text = Text1.Text & "-"
z = z + 1
End If
If KeyAscii = 42 Then
Text2.Text = Text2.Text + "*"
Text1.Text = Text1.Text + "*"
End If
If KeyAscii = 47 Then
Text2.Text = Text2.Text + "/"
Text1.Text = Text1.Text + "/"
End If
If KeyAscii = vbKeyReturn Then
PlaySound App.Path & "\sound.wav", 0, SND_SYNC
Call pianduan(Text1.Text)
If k >= 1 Or r >= 1 Then
Call liancheng(totle)
number2(z) = totle
If Mid$(Trim$(Text1.Text), 1, 1) = "-" Then
number2(z) = -totle
End If
k = 0: r = 0
Else
number2(z) = Val(Text1.Text)
End If
Text1.Text = ""
z = z + 1
Dim dengyu As Double
Dim v As Integer
For v = 0 To 50
dengyu = dengyu + number2(v)
Next v
If dengyu < 0 Then
Text3.ForeColor = &HFF&
Else
Text3.ForeColor = &HFF0000
End If
Text3.Text = dengyu
End If
If KeyAscii = vbKeyEscape Then
z = 0: k = 0: r = 0: j = 0
Dim i As Integer
For i = 0 To 50
number(i) = 0
number2(i) = 0
Next i
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text1.SetFocus
End If
If Len(Text3.Text) >= 14 Then
calcresult.Show
End If
End Sub

rivate sub Text3_Change()
tax2.Text1 = Text3.Text
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
genius52t
2010-12-28 · TA获得超过197个赞
知道答主
回答量:142
采纳率:0%
帮助的人:51.2万
展开全部
建议看下mfc教程 很容易上手的
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式