已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
虽然电脑坏了,之前设计的计算器的代码也没了,但是重新又做了一个也没用了多久。这说明放在脑子里的东西还是最安全的!其实做一个计算器也不难,第一先把界面设计好,这里要用到 XAML 语音,然后用 C#将背后的处理函数写好就好了。我做的这个计算器功能其实还是不是很完善的,但还是欢迎大家免费下载/share/link?shareid=470362using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;namespace 计算器/ / MainWindow.xaml 的交互逻辑/ public partial class MainWindow : Windowpublic MainWindow()InitializeComponent();MessageBox.Show(“本计算器暂不支持负数计算!“);private string txt=“0+“;/定义一个字符串变量来存储数据static double temp = 0;/定义一个临时变量用来存储计算的数据string txt1;private void text_TextChanged(object sender, TextChangedEventArgs e)txt1 =txt.Substring(2);text.Text = txt1;private void button1_Click(object sender, RoutedEventArgs e)txt += “1“;text.Text = txt;private void button2_Click(object sender, RoutedEventArgs e)txt += “2“;text.Text = txt;private void button3_Click(object sender, RoutedEventArgs e)txt += “3“;text.Text = txt;private void button4_Click(object sender, RoutedEventArgs e)txt += “4“;text.Text = txt;private void button5_Click(object sender, RoutedEventArgs e)txt += “5“;text.Text = txt;private void button6_Click(object sender, RoutedEventArgs e)txt += “6“;text.Text = txt;private void button7_Click(object sender, RoutedEventArgs e)txt += “7“;text.Text = txt;private void button8_Click(object sender, RoutedEventArgs e)txt += “8“;text.Text = txt;private void button9_Click(object sender, RoutedEventArgs e)txt += “9“;text.Text = txt;private void button_plus_Click(object sender, RoutedEventArgs e)txt += “+“;text.Text = txt;private void button_subtraction_Click(object sender, RoutedEventArgs e)txt += “-“;text.Text = txt;private void button_multiple_Click(object sender, RoutedEventArgs e)txt += “x“;text.Text = txt;private void button_division_Click(object sender, RoutedEventArgs e)txt += “/“;text.Text = txt;private void button_point_Click(object sender, RoutedEventArgs e)txt += “.“;text.Text = txt;private void button0_Click(object sender, RoutedEventArgs e)txt += “0“;text.Text = txt;private void button_equal_Click(object sender, RoutedEventArgs e)txt += “=“;text.Text = txt;string str1=“;/用来作为中间变量char sign = new chartxt.Length;/用来存储运算符int j = 0;double number = new doubletxt.Length;/用来存储输入的数据char str3 = txt.ToCharArray();/将字符串 txt 存入字符型数组 str3中/从 txt 字符串中分离数据和运算符for (int i = 0; i = 0|str3i=.)str1 += str3i;/str3数组中的数字与运算符分离开来,str1作为中间变量elsesignj = str3i;/存入运算符numberj=Convert.ToDouble(str1); /将 str1存入的数据转化为 double 型数据str1 = “;/将 str 清空便于下次存入j+;if (str3i = =)int k = 0;int index = 0;double temp2 = 1;switch(signk)case +:temp = number0 + number1; index = k; break;case -:temp = number0 - number1; index = k; break;case x:temp=number0*number1;break;case /:temp=number0/number1;break;for (k = 1; signk != =; k+)switch (signk)case +:temp = temp + numberk + 1; index = k; break;case -:temp = temp - numberk + 1; index = k; break;case x:/考虑连乘情况if (signk - 1 = +)temp = temp - numberk;temp2 = numberk * numberk + 1;temp += temp2; break;if (signk - 1 = -)temp = temp + numberk;temp2 = numberk * numberk + 1;temp -= temp2; break;if (signk - 1 = x)if (signindex = +)temp = temp - temp2;temp2 = temp2 * numberk + 1;temp = temp + temp2;if (signindex = -)temp = temp + temp2;temp2 = temp2 * numberk + 1;temp = temp - temp2;break;if (signk - 1 = /)if (signindex = +)temp = temp - temp2;temp2 = temp2 * numberk +1;temp = temp + temp2;if (signindex = -)temp = temp + temp2;temp2 = temp2 * numberk + 1;temp = temp - temp2;break;case /:if (signk - 1 = +)temp = temp - numberk;temp2 = numberk / numberk + 1;temp += temp2; break;if (signk - 1 = -)temp = temp + numberk;temp2 = numberk / numberk + 1;temp -= temp2; break;if (signk - 1 = x)if (signindex = +)temp = temp - temp2;temp2 = temp2 / numberk + 1;temp = temp + temp2;if (signindex = -)temp = temp + temp2;temp2 = temp2 / numberk + 1;temp = temp - temp2;break;if (signk - 1 = /)if (signindex = +)temp = temp - temp2;temp
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年儿科技能操作规范题库
- 2026年华电集团岗位胜任力面试要点
- 2026年权法律法规全解析
- 2026年证明事项告知承诺制题库
- 2026年手足口病防控技术指南题库
- 2026年社区儿童意外伤害防范考核题库
- 2026年经济学基础知识试题
- 统编版(2024)八年级下册语文期中质量评估测试卷3(含答案)
- 二轮完形填空考点解析(15份无水印)-二轮完形填空考点解析4
- 开展班前宣讲工作方案
- 2026年交管12123驾照学法减分完整版练习题库及1套完整答案详解
- 2026年五一节前全体员工安全培训课件
- 初中数学七年级下册问题解决策略专题“特殊化思想:从特殊到一般的桥梁”创新教学设计
- 2026年黑龙江省《保密知识竞赛必刷100题》考试题库附参考答案详解(精练)
- 2026江苏苏州工业园区街道协管员招聘37人农业笔试备考试题及答案解析
- 2026年执业医师定期考核真考试题库带答案详解(A卷)
- 贵州医科大学2026考博历年真题配套模拟题及答案
- (二模)温州市2026届高三第二次适应性考试地理试卷(含答案)
- 《公路水运工程施工安全标准化指南》
- 2026年中考《语文》作文10大主题抢分万能模板
- GB/T 43441.2-2026信息技术数字孪生第2部分:数字实体
评论
0/150
提交评论