




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 全面提升行政管理能力的考试试题及答案
- 2025年度员工健康检查合同协议
- 课题申报书的本质
- 微生物感染传播途径的识别试题及答案
- 课题申报书怎么整页
- 项目闭环管理的必要性试题及答案
- 2025年证券从业资格证考试加速提升技巧试题及答案
- 解析2025年证券从业资格证考试重难点试题及答案
- 新课改瘦专用2025版高考地理一轮复习第二部分人文地理第五章交通运输布局及其影响第二讲交通运输方式和布局变化的影响学案含解析
- 2025年证券从业资格证科学发展试题及答案
- 小学弘扬教育家精神活动方案及措施
- 《中国饮食文化》课件-中国饮食文化溯源
- 2024年贵州省中考数学真题试卷及答案解析
- 统编版语文六年级下册第四单元闯关测试卷(含答案)
- 煤炭开采单位产品能源消耗限额-编辑说明
- MOOC 固体物理学-北京交通大学 中国大学慕课答案
- 2023年4月重庆市考公务员面试题及参考答案
- 书香校园-世界读书日主题教育班会
- TIAC CCSA 32-2019《保险行业云计算场景和总体框架》
- 玻璃瓶丝印制度
- 中医养生如何调理肺炎
评论
0/150
提交评论