用C语言设计能够完成多步四则运算的程序

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/29 13:12:09

用C语言设计能够完成多步四则运算的程序
用C语言设计能够完成多步四则运算的程序

用C语言设计能够完成多步四则运算的程序
多用计算器的构思及设计代码
[关键词]多用计算器;设计

数值计算可以说是日常最频繁的工作了,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
另外,站长团上有产品团购,便宜有保证

用C语言设计能够完成多步四则运算的程序 完成四则运算C语言程序 c语言 设计小学生四则运算测试程序,要求随机产生10题四则运算题,答完后给出得分帮下忙拉 C语言编写程序四则运算法则 用C语言编写简易计算器可实现两位数以上的四则运算.C语言编写单片机程序. 用C语言编一个能完成基本的四则运算和求余的函数完成基本运算四则运算和求余的函数主要功能:实现字符界面下的四则运算和求余等运算.相关的操作提示信息.能够重复操作、连续操作.用 有理数的四则运算(C语言) 急用![问题描述]设计一个可进行有理数运算的演示程序.[基本要求]实现两个有理数相加、相减、相乘、相除的运算. 用简单的C语言实现带括号的四则运算不要用数据库以及堆栈之类的 注意要用标准C 不用C++ 完成实现带有括号的四则运算的任务,要求:1) 在屏幕能够手动输入待运算的带有括号的四则运算 用C语言如何完成下面菱形的显示程序 有理数的四则运算(C语言) C语言,设计一个函数,实现加,减,乘,除运算.设计一个程序,可以模仿计算机完成加,减,乘,除四则运算:由键盘输入两个数,按用户的选择进行一种运算,并给出结果.其中加,减,乘,除各由一个函数 求设计c语言程序 C语言程序 设计:用辗转相除法求两个正整数的最大公约数编写程序 设计一个关于复数的结构类型,并实现复数的四则运算C语言 用C++语言设计一个简单计算器.用户输入四则运算表达式,程序输出正确结果(有追加)设计一个简单计算器.用户输入四则运算表达式,程序输出正确结果.当表达式中数据格式或运算符输入错误, 编写一个程序模拟计算器的加减乘除四则运算.要求:采用函数调用,并用指向函数的指针作为函数的参数用C语言 有理数的四则运算(C语言) 急! 如何编写一个C语言程序,让计算机自动出四则运算计算题,要求自动出0-10之间的四则运算题,并批改结果?