❶ c语言计算器 功能要求: 可以输入0-9数字、小数点、正负数 可以进行加减乘除运算及简单的数学函数运算
下面是使用 C 语言设计简易科学计算器的示例代码:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
char op;
double num1, num2;
printf("请输入数学表达式(如:1 + 2):");
scanf("%lf %c %lf", &num1, &op, &num2);
switch (op)
{
case '+':
printf("结果为:%.2lf\n", num1 + num2);
break;
case '-':
printf("结果为:%.2lf\n", num1 - num2);
break;
case '*':
printf("结果为:%.2lf\n", num1 * num2);
break;
case '/':
if (num2 == 0)
{
printf("除数不能为 0!\n");
}
else
{
printf("结果为:%.2lf\n", num1 / num2);
}
break;
case '^':
printf("结果为亩茄:%.2lf\n", pow(num1, num2));
break;
case 's':
printf("结果为:%.2lf\n", sin(num1));
break;
case 'c':
printf("结果为:%.2lf\n", cos(num1));
break;
case 't':
printf("结果为:%.2lf\n", tan(num1));
break;
case 'l':
printf("结果为:%.2lf\n", log(num1));
break;
case 'e':
printf("结果为:%.2lf\n", exp(num1));
break;
default:
printf("山哪无效的运算符!逗耐码\n");
break;
}
return 0;
}
❷ c语言编写 编写一个简单的计算器,实现两个整型数的四则运算。
#include<stdio.h>
int main()
{int a,b,c,err;
char op;
do
{scanf("%d%c%d",&a,&op,&b);
err=0;
if(a==0&&b==0)break;
if(op=='+')c=a+b;
if(op=='-')c=a-b;
if(op=='*')c=a*b;
if(op=='/')
if(b)c=a/b;else err=1;
if(op=='%')
if(b)c=a%b;else err=1;
if(err)printf("%d%c%d error! ",a,b,c);
else printf("%d%c%d=%d ",a,op,b,c);
}while(1);
return 0;
}
❸ 怎么用C语言设计一个简单计算器
怎么用C语言设计一个简单计算器 #include<iostream>
#include<math.h>
using namespace std;
main ()
{
char k;
double s,g;
k='-';
cout<<"求绝对值请按A;求平方根请按B;加减乘除清分别按+-*/" <<endl;
cin>>g;
while (1)
{
cin>>k;
if (k=='=')
break;
if (k=='A')
{
g=fabs (g);
break;
}
if (k=='B')
{
g=sqrt (g);
break;
}
cin>>s;
if (k=='+')
g+=s;
if (k=='-')
g-=s;
if (k=='*')
g*=s;
if (k=='/')
{
if (s==0)
cout<<"wrong";
else
g/=s;
}
}
cout<<g;
}
#include<stdio.h> void add(int a,int b,int c) { c=a+b; printf("%d\t",c); printf("\n"); } void minus(int a,int b,int c) { c=a-b; printf("%d\t",c); printf("\n"); } void multiplication(int a,int b,int c) { c=a*b; printf("%d\t",c); printf("\n"); } void div(int a,int b,int c) { c=(float)a/(float)b; printf("%f\t",c); printf("\n"); } main() { int a,b,c; char p; puts("input A:\n"); scanf("%d",&a); puts("input B:\n"); scanf("%d",&b); puts("input operation:\n"); getchar(); p=getchar(); if(p=='+') add(a,b,c);else if(p=='-') minus(a,b,c);else if(p=='*') multiplication(a,b,c);else if(p=='/') div(a,b,c);else puts("没有注册这个运算子号\n"); } 以上是设计的一个简易计算器。可以进行相应的加减乘除。 简介:
C语言是一种计算机程式设计语言,它既具有高阶语言的特点,又具有组合语言的特点。它由美国贝尔研究所的D.M.Ritchie于1972年推出,1978年后,C语言已先后被移植到大、中、小及微型机上,它可以作为工作系统设计语言,编写系统应用程式,也可以作为应用程式设计语言,编写不依赖计算机硬体的应用程式。它的应用范围广泛,具备很强的资料处理能力,不仅仅是在软体开发上,而且各类科研都需要用到C语言,适于编写系统软体,三维,二维图形和动画,具体应用比如微控制器以及嵌入式系统开发。
求用C语言设计一个简单计算器
应该不难,就是按钮的讯息传递处理函式等,
用C语言怎么设计一个简单计算器?
#include<stdio.h>
void add(int a,int b,int c)
{
c=a+b;
printf("%d\t",c);
printf("\n");
}
void minus(int a,int b,int c)
{
c=a-b;
printf("%d\t",c);
printf("\n");
}
void multiplication(int a,int b,int c)
{
c=a*b;
printf("%d\t",c);
printf("\n");
}
void div(int a,int b,int c)
{
c=(float)a/(float)b;
printf("%f\t",c);
printf("\n");
}
main()
{
int a,b,c;
char p;
puts("input A:\n");
scanf("%d",&a);
puts("input B:\n");
scanf("%d",&b);
puts("input operation:\n");
getchar();
p=getchar();
if(p=='+') add(a,b,c);else
if(p=='-') minus(a,b,c);else
if(p=='*') multiplication(a,b,c);else
if(p=='/') div(a,b,c);else
puts("没有注册这个运算子号\n");
}
怎么用C语言程式设计一个简单计算器?
#include<<a href=":./s?wd=stdio.h&tn=44039180_cpr&fenlei=-bIi4WUvYETgN-TLwGUv3EPH6srjc4rH61" target="_blank" class="-highlight">stdio.h</a>>
void main() { float x,y,z; char c;
scanf("%f%c%f",&x,&c,&y);
switch ( c ) {
case '+': z=x+y; break;
case '-': z=x-y; break;
case '*': z=x*y; break;
case '/': z=( y==0 )?(0):(x/y); break;
default: z=0; break;
}
printf("%f%c%f=%f\n",x,c,y,z);
}
C语言是一门通用计算机程式语言,应用广泛。C语言的设计目标是提供一种能以简易的方式编译、处理低阶储存器、产生少量的机器码以及不需要任何执行环境支援便能执行的程式语言。
尽管C语言提供了许多低阶处理的功能,但仍然保持着良好跨平台的特性,以一个标准规格写出的C语言程式可在许多电脑平台上进行编译,甚至包含一些嵌入式处理器(微控制器或称MCU)以及超级电脑等作业平台。
二十世纪八十年代,为了避免各开发厂商用的C语言语法产生差异,由美国国家标准局为C语言制定了一套完整的美国国家标准语法,称为ANSI C,作为C语言最初的标准。[1] 目前2011年12月8日,国际标准化组织(ISO)和国际电工委员会(IEC)释出的C11标准是C语言的第三个官方标准,也是C语言的最新标准,该标准更好的支援了汉字函式名和汉字识别符号,一定程度上实现了汉字程式设计。
用C语言编一个简单计算器
已经为你实现了加减乘除了。 main.c 简易计算器 Created by shengan on 15/6/29. Copyright (c) 2015年 shengan. All rights reserved.#include <stdio.h>double plus();double minus();double multi();double divide();int main(int argc, const char * argv[]) { insert code here... double a, b; char c; while(1 == 1) { printf("简易计算器\n"); printf("输入第一个数:\n"); scanf("%lf", &a); printf("输入运算子:\n"); scanf("%s", &c); printf("输入第二个数:\n"); scanf("%lf", &b); switch (c) { case '+': printf("%lf %c %lf = %lf", a, c, b, plus(a, b)); break; case '-': printf("%lf %c %lf = %lf", a, c, b, minus(a, b)); break; case '*': printf("%lf %c %lf = %lf", a, c, b, minus(a, b)); break; case '/': printf("%lf %c %lf = %lf", a, c, b, minus(a, b)); break; default: printf("运算子号输入错误!\n"); break; } } return 0;}加法double plus(double a, double b){ return a + b;}double minus(double a, double b){ return a - b;}double multi(double a, double b){ return a * b;}double divide(double a, double b){ return a / b;}
设计一个简单计算器
#include <stdio.h>
int main(void)
{
int data1, data2;
char op;
printf("please input data1 op data2:");
scanf("%d %c %d", &data1 , &op , &data2);
switch (op)
{
case '+':
printf("%d + %d = %.0f\n", data1, data2, (double)data1 + (double)data2);
break;
case '-':
printf("%d - %d = %.0f\n", data1, data2, (double)data1 - (double)data2);
break;
case '*':
printf("%d * %d = %.0f\n", data1, data2, (double)data1 * (double)data2);
break;
case '/':
if (data2 == 0)
{
printf("Error! chu shu wei 0.");
}
else
{
printf("%d / %d = %.0f\n", data1, data2, (double)data1 / (double)data2);
}
break;
case '%':
if (data2 == 0)
{
printf("Error! chu shu wei 0.");
}
else
{
printf("%d %% %d=%d3\n", data1, data2, data1 % data2);
}
break;
default:
printf("Unknown operator\n");
}
return 0;
}如果要求是浮点数的话换一下资料型别就可以了
用c语言程式设计一个简单计算器,求其原始码
/*
2013年12月23日 12:43:46
目的:计算器的实现
*/
# include <stdio.h>
# include <ctype.h>
# include <math.h>
char get_choice(void); 获取使用者输入的选项,并建立目
char get_first(void); 获取使用者输入的选项,并剔除错误输入
float get_int(void); 获取使用者输入的计算值
float add(void); 定义加法函式
float subtraction(void); 定义减法函式
float multiplication(void); 定义乘法函式
float division(void); 定义除法函式
float extract(void); 定义开方函式
float square(void); 定义平方函式
float cube(void); 定义立方函式
int count = 0;
int main(void)
{
char choice;
printf("***欢迎使用由小钱制作的计算器***\n");
choice = get_choice();
while(choice != 'q')
{
switch(choice)
{
case 'a':
add(); break;
case 'b':
subtraction(); break;
case 'c':
multiplication(); break;
case 'd':
division(); break;
case 'e':
extract(); break;
case 'f':
square(); break;
case 'g':
cube(); break;
default :
printf("您输入有误,请重新输入:"); break;
}
fflush(stdin);
choice = get_choice();
}
printf("bye");
return 0;
}
获取使用者输入的选项,并建立目录
char get_choice(void)
{
char ch;
int a = 0;
建立目录
printf("\n--------------------------------\n");
printf("a. 加法\t\t\tb. 减法\nc. 乘法\t\t\td. 除法\n");
printf("e. 开方\t\t\tf. 平方\ng. 立方\t\t\tq. 退出\n");
printf("--------------------------------\n");
printf("请输入你的选项:");
ch = get_first();
while(ch == ' ' || ch == '\n' || ch == '\t')
ch = get_first();
判断使用者输入的选项是否有误
while((ch<'a' || ch>'g') && ch !='q')
{
putchar(ch);
printf(" 你输入的选项有误,请重新输入:");
ch = get_first();
}
return ch;
}
获取使用者输入的选项,并剔除错误输入
char get_first(void)
{
char ch;
ch = getchar();
剔除由使用者输入选项时产生的换行符
while(ch == '\n')
{
ch = getchar();
}
return ch;
}
获取使用者输入的计算值
float get_int(void)
{
float input;
char ch;
int a;
if(count == 0)
printf("亲!请输入数值:");
if(count == 1)
printf("亲!请输入第一个数值:");
if(count == 2)
printf("亲!请输入第二个数值:");
a = scanf("%f", &input);
判断使用者的输入是否为一个数值
while(a != 1)
{
剔除使用者输入错误的字符
while((ch = getchar()) != '\n')
{
putchar(ch);
printf(" 不是一个数值,请输入例如3、111.2、或者-1");
a = scanf("%f", &input);
}
}
return input;
}
定义加法函式
float add(void)
{
float i, j, sum;
count = 0;
count = count+1;
i = get_int();
count = count+1;
j = get_int();
sum = i + j;
printf("%.2f + %.2f = %.2f\n", i, j, sum);
return sum;
}
定义减法函式
float subtraction(void)
{
float i, j, sum;
count = 0;
count = count+1;
i = get_int();
count = count+1;
j = get_int();
sum = i - j;
printf("%.2f - %.2f = %.2f\n", i, j, sum);
return sum;
}
定义乘法函式
float multiplication(void)
{
float i, j, sum;
count = 0;
count = count+1;
i = get_int();
count = count+1;
j = get_int();
sum = i * j;
printf("%.2f * %.2f = %.2f\n", i, j, sum);
return sum;
}
定义除法函式
float division(void)
{
float i, j, sum;
count = 0;
count = count+1;
i = get_int();
count = count+1;
j = get_int();
判断除数是否为0
while(j == 0)
{
printf("除数不能为0\n请重新输入!!!\n");
j = get_int();
}
sum = i / j;
printf("%.2f / %.2f = %.2f\n", i, j, sum);
return sum;
}
定义开方函式
float extract(void)
{
float i, sum;
count = 0;
i = get_int();
判断开方数是否小于0,如果小于0,则让使用者重新输入
while(i < 0)
{
printf("请输入大于0的数值\n");
i = get_int();
}
sum = sqrt(i);
printf("%.2f的开方等于%.2f\n", i, sum);
return sum;
}
定义平方函式
float square(void)
{
float i, sum;
count = 0;
i = get_int();
sum = i * i;
printf("%.2f的平方等于%.2f\n", i, sum);
return sum;
}
定义立方函式
float cube(void)
{
float i, sum;
count = 0;
i = get_int();
sum = i * i * i;
printf("%f的立方等于%.3f\n", i, sum);
return sum;
}
❹ 简单的用c语言写一个计算器程式,加减乘除能用就好
简单的用c语言写一个计算器程式,加减乘除能用就好 #include"stdio.h"
void main()
{
float a,b,c;
char e;
printf("input a,e,b\n");/*输入两个数和符号,例如3+8*/
scanf("%f%c%f",&a,&e,&b);
switch(e)
{
case '+':c=a+b;break;
case '-':c=a-b;break;
case '*':c=a*b;break;
case '/':
if(b==0.0) printf("error\n");
else c=a/b;break;
}
printf("%f%c%f=%f",a,e,b,c);
}
如何用vc++编写一个简单的(只有加减乘除)计算器程式?
先设定接口如下
加法按钮程式码
void CMy03Dlg::OnBnClickedButton1()
{
TODO:在此新增控制元件通知处理程式程式码
UpdateData(TRUE);
m_Nub3=m_Nub1+m_Nub2;
UpdateData(FALSE);
}
减法按钮程式码
void CMy03Dlg::OnBnClickedButton2()
{
TODO:在此新增控制元件通知处理程式程式码
UpdateData(TRUE);
m_Nub3=m_Nub1-m_Nub2;
UpdateData(FALSE);
}
乘法按钮程式码
void CMy03Dlg::OnBnClickedButton3()
{
TODO:在此新增控制元件通知处理程式程式码
UpdateData(TRUE);
m_Nub3=m_Nub1*m_Nub2;
UpdateData(FALSE);
}
除法按钮程式码
void CMy03Dlg::OnBnClickedButton4()
{
TODO:在此新增控制元件通知处理程式程式码
UpdateData(TRUE);
if(m_Nub2!=0)
m_Nub3=m_Nub1 / m_Nub2;
else
AfxMessageBox("被除数不能为0");
UpdateData(FALSE);
}
清除按钮程式码
void CMy03Dlg::OnBnClickedButton5()
{
TODO:在此新增控制元件通知处理程式程式码
UpdateData(TRUE);
m_Nub3=0;
m_Nub1=0;
m_Nub2=0;
UpdateData(FALSE);
}
结束按钮程式码
void CMy03Dlg::OnBnClickedButton6()
{
TODO:在此新增控制元件通知处理程式程式码
CDialog::OnOK();
}
如果只允许在输入框中输入资料应该怎样处理?
制作托盘程式
目的:在工作列中建立一个图示,使该程式永远驻留在记忆体中。例如邮件检查程式可以作为驻留程式,一旦有邮件来了,就可以接收邮件。
Shell_NotifyIcon函式传送讯息来增加、删除、修改工作列的图示
BOOL TrayMessage(HWND hWnd, DWORD dwMessage, HICON hIcon, PSTR pszTip)
{
BOOL res;
NOTIFYICONDATA tnd;
tnd.cbSize = sizeof(NOTIFYICONDATA);
tnd.hWnd = hWnd;
tnd.uID = IDI_ICON1;
tnd.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
tnd.uCallbackMessage = WM_MY_TRAY_NOTIFICATION;
tnd.hIcon = hIcon;
lstrcpyn(tnd.szTip, pszTip, sizeof(tnd.szTip));
res = Shell_NotifyIcon(dwMessage, &tnd); dwMessage为NIM_ADD从工作列中新增图示、NIM_DELETE从工作列中删除图示、NIM_MODIFY改变工作列中图示
if (hIcon)
DestroyIcon(hIcon);
return res;
}
定义一个回拨讯息:WM_MY_TRAY_NOTIFICATION
在DLG的CPP档案中,
#define WM_MY_TRAY_NOTIFICATION WM_USER+100
为对话方块新增讯息对映ON_MESSAGE(WM_MY_TRAY_NOTIFICATION,OnTrayNotification)
在DLG的标头档案中应该有
public:
long m_Nub1;
float m_Nub3;
CBitmapButton Button;
afx_msg void OnBnClickedButton1();
long m_Nub2;
afx_msg void OnBnClickedButton2();
afx_msg void OnBnClickedButton4();
afx_msg void OnBnClickedButton5();
afx_msg void OnBnClickedButton3();
afx_msg void OnBnClickedButton6();
afx_msg void OnBnClickedButton7();
afx_msg LRESULT OnTrayNotification(WPARAM wparam, LPARAM lparam);
在DLG的CPP档案中应该有
BEGIN_MESSAGE_MAP(CMailCheckDlg, CDialog)
……
ON_MESSAGE(WM_MY_TRAY_NOTIFICATION,OnTrayNotification)
……
END_MESSAGE_MAP()
并定义一个回拨讯息函式
LRESULT CMailCheckDlg::OnTrayNotification(WPARAM wparam, LPARAM lparam)
{
switch (lparam )
{
case WM_RBUTTONUP:
case WM_LBUTTONDBLCLK:修改不同的按钮处理事件,以观察图示退出效果。
ShowWindow(SW_SHOW);
TrayMessage(m_hWnd, NIM_DELETE, NULL, "");从工作列中删除图示
}
return 0;
}
在对话方块视窗上新增“驻留”按钮,双击按钮新增程式码
void CMailCheckDlg::OnBnClickedButton1()
{
TODO:在此新增控制元件通知处理程式程式码
下面程式向工作列新增图示
TrayMessage(m_hWnd, NIM_ADD, NULL, "计算器程式");
TrayMessage(m_hWnd, NIM_MODIFY, m_hIcon, "计算器程式");
ShowWindow(SW_HIDE);
用MFC编写一个简单的加减乘除计算器
我有程式,加31782771群
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 hMole As Long, ByVal dwFlags As Long) As Long
Private Const SND_FILENAME = &H20000?
Private Const SND_ASYNC = &H1?
Private Const SND_SYNC = &H0
*判断通用过程
Sub pianan(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 pianan(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 pianan(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 pianan(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 muninter_Click()
Dim i
i = Shell("C:\Program Files\InterExplorer\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 mun *** _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 pianan(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 pianan(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 pianan(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语言编写能运算加减乘除的计算器程式,用到栈
#include "stdio.h"
#include "string.h"
#include "ctype.h"
#include "math.h"
expression evaluate
#define iMUL 0
#define iDIV 1
#define iADD 2
#define iSUB 3
#define iCap 4
#define LtKH 5
#define RtKH 6
#define MaxSize 100
void iPush(float);
float iPop();
float StaOperand[MaxSize];
int iTop=-1;
char Srcexp[MaxSize];
char Capaexp[MaxSize];
char RevPolishexp[MaxSize];
float NumCapaTab[26];
char validexp[]="*/+-()";
char NumSets[]="0123456789";
char StackSymb[MaxSize];
int operands;
void NumsToCapas(char [], int , char [], float []);
int CheckExpress(char);
int PriorChar(char,char);
int GetOperator(char [], char);
void counterPolishexp(char INexp[], int slen, char Outexp[]);
float CalcRevPolishexp(char [], float [], char [], int);
void main()
{
int ilen;
float iResult=0.0;
printf("enter a valid number string:\n");
memset(StackSymb,0,MaxSize);
memset(NumCapaTab,0,26); A--NO.1, B--NO.2, etc.
gets(Srcexp);
ilen=strlen(Srcexp);
printf("source expression:%s\n",Srcexp);
NumsToCapas(Srcexp,ilen,Capaexp,NumCapaTab);
printf("Numbers listed as follows:\n");
int i;
for (i=0; i<operands; ++i)
printf("%.2f ",NumCapaTab[i]);
printf("\nCapaexp listed in the following:\n");
printf("%s\n",Capaexp);
ilen=strlen(Capaexp);
counterPolishexp(Capaexp,ilen,RevPolishexp);
printf("RevPolishexp:\n%s\n",RevPolishexp);
ilen=strlen(RevPolishexp);
iResult=CalcRevPolishexp(validexp, NumCapaTab, RevPolishexp,ilen);
printf("\ncounterPolish expression:\n%s%.6f\n",Srcexp,iResult);
}
void iPush(float value)
{
if(iTop<MaxSize) StaOperand[++iTop]=value;
}
float iPop()
{
if(iTop>-1)
return StaOperand[iTop--];
return -1.0;
}
void NumsToCapas(char Srcexp[], int slen, char Capaexp[], float NumCapaTab[])
{
char ch;
int i, j, k, flg=0;
int sign;
float val=0.0,power=10.0;
i=0; j=0; k=0;
while (i<slen)
{
ch=Srcexp[i];
if (i==0)
{
sign=(ch=='-')?-1:1;
if(ch=='+'||ch=='-')
{
ch=Srcexp[++i];
flg=1;
}
}
if (isdigit(ch))
{
val=ch-'0';
while (isdigit(ch=Srcexp[++i]))
{
val=val*10.0+ch-'0';
}
if (ch=='.')
{
while(isdigit(ch=Srcexp[++i]))
{
val=val+(ch-'0')/power;
power*=10;
}
} end if
if(flg)
{
val*=sign;
flg=0;
}
} end if
write Capaexp array
write NO.j to array
if(val)
{
Capaexp[k++]='A'+j;
Capaexp[k++]=ch;
NumCapaTab[j++]=val; A--0, B--1,and C, etc.
}
else
{
Capaexp[k++]=ch;
}
val=0.0;
power=10.0;
i++;
}
Capaexp[k]='\0';
operands=j;
}
float CalcRevPolishexp(char validexp[], float NumCapaTab[], char RevPolishexp[], int slen)
{
float sval=0.0, op1,op2;
int i, rt;
char ch;
recursive stack
i=0;
while((ch=RevPolishexp[i]) && i<slen)
{
switch(rt=GetOperator(validexp, ch))
{
case iMUL: op2=iPop(); op1=iPop();
sval=op1*op2;
iPush(sval);
break;
case iDIV: op2=iPop(); op1=iPop();
if(!fabs(op2))
{
printf("overflow\n");
iPush(0);
break;
}
sval=op1/op2;
iPush(sval);
break;
case iADD: op2=iPop(); op1=iPop();
sval=op1+op2;
iPush(sval);
break;
case iSUB: op2=iPop(); op1=iPop();
sval=op1-op2;
iPush(sval);
break;
case iCap: iPush(NumCapaTab[ch-'A']);
break;
default: ;
}
++i;
}
while(iTop>-1)
{
sval=iPop();
}
return sval;
}
int GetOperator(char validexp[],char oper)
{
int oplen,i=0;
oplen=strlen(validexp);
if (!oplen) return -1;
if(isalpha(oper)) return 4;
while(i<oplen && validexp[i]!=oper) ++i;
if(i==oplen || i>=4) return -1;
return i;
}
int CheckExpress(char ch)
{
int i=0;
char ;
while((=validexp[i]) && ch!=) ++i;
if (!)
return 0;
return 1;
}
int PriorChar(char curch, char stach)
{
栈外优先顺序高于(>)栈顶优先顺序时,才入栈
否则(<=),一律出栈
if (curch==stach) return 0; 等于时应该出栈
else if (curch=='*' || curch=='/')
{
if(stach!='*' && stach!='/')
return 1;
}
else if (curch=='+' || curch=='-')
{
if (stach=='(' || stach==')')
return 1;
}
else if (curch=='(')
{
if (stach==')')
return 1;
}
return 0;
}
void counterPolishexp(char INexp[], int slen, char Outexp[])
{
int i, j, k,pr;
char t;
i=0;
j=k=0;
while (INexp[i]!='=' && i<slen)
{
if (INexp[i]=='(')
StackSymb[k++]=INexp[i];
iPush(*(INexp+i));
else if(INexp[i]==')')
{
if((t=iPop())!=-1)
while((t=StackSymb[k-1])!='(')
{
Outexp[j++]=t;
k--;
}
k--;
}
else if (CheckExpress(INexp[i])) is oparator
{
printf("operator %c k=%d\n",INexp[i],k);
while (k)
{
iPush(*(INexp+i));
if(pr=PriorChar(INexp[i],StackSymb[k-1]))
break;
else
{
if ((t=iPop())!=-1)
t=StackSymb[k-1]; k--;
Outexp[j++]=t;
}
} end while
StackSymb[k++]=INexp[i]; mon process
}
else if() 变数名
{
printf("operand %c k=%d\n",INexp[i],k);
Outexp[j++]=INexp[i];
}
i++;
}
while (k)
{
t=StackSymb[k-1]; k--;
Outexp[j++]=t;
}
Outexp[j]='\0';
}
注:程式源于“网络知道”
用verilog编写一个最简单的加减乘除的计算器的程式
verilog是有加法器乘法器的。也直接识别 + - * / 符号。
mole kjasdja(a,option,b,result);
input option,a,b;
output result;
always @(a,b,option)
begin
result_r=0; 结果暂存器清零
case(option)
+:result_r=a+b;
-:result_r=a-b;
*:result_r=a*b;
/:result_r=a/b;
assign result =result_r;
endmole
大概算法就这样。写的仓促,语法可能有误。另外除法reg型别只能储存整数部分,小数通过移位操作实现,比较麻烦。比如3/5=0.6
做的时候先3=30,然后30/5=6,然后对6在数码管的显示进行调整就好。把6显示在小数点后面1位就好
用vb编写一个计算器程式,实现加减乘除,
Dim v As Boolean
Dim s As Integer
Dim X As Double
Dim Y As Double
Private Sub Command1_Click(Index As Integer)
If Form1.Tag = "T" Then
If Index = 10 Then
Text1.Text = "0"
Else
Text1.Text = Command1(Index).Caption
End If
Form1.Tag = ""
Else
Text1.Text = Text1.Text & Command1(Index).Caption
End If
End Sub
Private Sub Command2_Click(Index As Integer)
Form1.Tag = "T"
If v Then
X = Val(Text1.Text)
v = Not v
Else
Y = Val(Text1.Text)
Select Case s
Case 0
Text1.Text = X + Y
Case 1
Text1.Text = X - Y
Case 2
Text1.Text = X * Y
Case 3
If Y <> 0 Then
Text1.Text = X / Y
Else
MsgBox ("不能以0为除数")
Text1.Text = X
v = False
End If
Case 4
Y = 0
v = False
End Select
X = Val(Text1.Text)
End If
s = Index
End Sub
Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)
End Sub
控制元件自己新增吧,空间名要和程式码名一致
求一简单的加减乘除计算器c++程式
#include<stdio.h>
#include<math.h>
void main()
{
float a,b;
char C;
while(1)
{
scanf("%f%c%f",&a,&C,&b);
if((C!='+')&&(C!='-')&&(C!='*')&&(C!='/'))
break;
switch(C)
{
case '+': printf("%f+%f=%f",a,b,a+b);
break;
case '-': printf("%f-%f=%f",a,b,a-b);
break;
case '*': printf("%f*%f=%f",a,b,a*b);
break;
case '/': printf("%f/%f=%f",a,b,a/b);
break;
}
}
}
想改成按1 2 3 4分别为加减乘除,只需要将程式中的+ - * / 改成1 2 3 4即可。按除了+ - * / 以外的键就会退出。
用c++语言编写一个简单的计算器程式,会加减乘除就行,本人初学不太会,特训求帮助
这个是最简单,简陋的计算器。很多情况没考虑进去,例如除数不能为0之类的,真要写完整的话程式码还要更多。
程式码如下: #include <iostream>using namespace std;int main(){ float a, b, result; char operation; cout << "请输入算式,如1+2并回车:" << endl; cin >> a >> operation >> b; switch(operation) { case '+': result = a + b; break; case '-': result = a - b; break; case '*': result = a * b; break; case '/': result = a / b; break; default: cout << "输入非法,程式退出!" << endl; return -1; } cout << endl << "结果为:" << endl << a << operation << b << "=" << result << endl; return 0;}
知道switch函式 吗 用这个就行
建俩个int型变数 一个字符型变数
❺ 大一c语言编程实现计算器功能实验报告
#include"stdio.h"
intmain()
{
inta,b,c;
do
{
system("cls");
printf("计算器菜单 ");
printf("======================== ");
printf("1:计算a+b ");
printf("2:计算a-b ");
printf("3:计算a*b ");
printf("4:计算a/b ");
printf("5:计算a%b ");
printf("0:退出 ");
printf("请选择(0-5):");
scanf("%d",&c);
if(c!=0)
{
printf("请输入a:");
scanf("%d",&a);
printf("请输入b:");
scanf("%d",&b);
switch(c)
{
case1:printf("a+b=%d",a+b);break;
case2:printf("a-b=%d",a-b);break;
case3:printf("a*b=%d",a*b);break;
case4:printf("a/b=%d",a/b);break;
case5:printf("a%b=%d",a%b);break;
default:break;
}
printf(" 按任意键继续......");
getch();
}
}
while(c!=0);
return0;
}