




已阅读5页,还剩21页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
基于 C#窗体程序的一个简单计算器,进制转换的小数部分没有完善,初学者,继续努力中.各位大侠请指教,各位小白大家互相学习,一起进步using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Threading;namespace js_easypublic partial class Form1 : Formstring Fh = “;/定义符号位double a, b, c;/定义a第一个值,b第二个值,c输出值long s = 1;/定义小数最初为一位public Form1()InitializeComponent();public void anniu(double i)/按钮方法if (Fh.Equals(“)/是否当前有运算符if (s = 1)/判断是否有小数点a = a * 10 + i;/计算无小数的值elsea = a + i / s;/计算有小数的值s = s * 10;/计算下一个小数的位置textBox1.Text = a.ToString();/显示计算的结果else /当前有运算符的方法if (!(c = 0) b = 0; c = 0; /当有计算结果就清除B的值if (s = 1)/判断是否有小数点b = b * 10 + i;/计算无小数的值elseif (i = 0)/判断在小数位后添加0s = s * 10;/计算下一个小数的位置elseb = b + i / s;/计算有小数的值s = s * 10;/计算下一个小数的位置textBox1.Text = b.ToString();/显示计算的结果public void js()/数学计算的方法if (Fh = “/“)/判断是否除数等于0if (b = 0) /是则不计算textBox1.Text = “0“;/被除数不能为0return;/返回elsec = a / b;else/如果不是出发计算则执行其他计算if (Fh.Equals(“+“) c = a + b; if (Fh.Equals(“-“) c = a - b; if (Fh.Equals(“*“) c = a * b; if (Fh.Equals(“%“) c = a % b; textBox1.Text = c.ToString(); /显示计算结果a = c;/将结果给第一个变量作为 public void fh(string str) /接收运算符的方法if (Fh.Equals(“)/当前是否已经有运算符Fh = str; s = 1;/没有则接收运算符,小数点失效elsejs();s = 1; Fh = str;/有则计算当前的值,小数点失效/*暂不支持小数进制转换*/public void jz2(string jg)/2进制转换long temp = Convert.ToInt64(jg);if (temp 0)arrayi+ = (int)temp % 2;temp /= 2;int array_1 = new inti;for (int j = i - 1; j = 0; j-)array_1j = arrayi - 1 - j;/Array.Reverse(array_1);foreach (int k in array_1)textBox2.Text += k.ToString();public void jz8(string jg)/8进制转换long temp = Convert.ToInt64(jg);if (temp 0)arrayi+ = (int)temp % 8;temp /= 8;int array_1 = new inti;for (int j = i - 1; j = 0; j-)array_1j = arrayi - 1 - j;/Array.Reverse(array_1);foreach (int k in array_1)textBox2.Text += k.ToString();public void jz16(string jg)/十六进制转换long temp = Convert.ToInt64(jg);if (temp 0)arrayi+ = (int)temp % 16;temp /= 16;int array_1 = new inti;for (int j = i - 1; j = 0; j-)array_1j = arrayi - 1 - j;foreach (int k in array_1)textBox2.Text += k.ToString(“X“);public long Jiec(long jg)/阶乘long temp = jg;if (temp = 1)return 1;elselong temp1 = Jiec(temp-1);temp = temp * temp1;return temp;private void Form1_Load(object sender, EventArgs e)textBox1.Font = new Font(“宋体“, 14, FontStyle.Bold);textBox2.Font = new Font(“宋体“, 14, FontStyle.Bold);this.Text = “简单计算器“;string dir = “imageangry.jpg“;pictureBox1.Image = Image.FromFile(dir);pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;pictureBox1.Dock = DockStyle.Fill;button1.Text = “=“;button2.Text = “2“;button3.Text = “3“;button4.Text = “4“;button5.Text = “5“;button6.Text = “C1“;button7.Text = “7“;button8.Text = “8“;button9.Text = “9“;button10.Text = “0“;button12.Text = “+“;button13.Text = “-“;button14.Text = “*“;button15.Text = “%“;button16.Text = “/“;button17.Text = “6“;button18.Text = “.“;button19.Text = “1“;button11.Text = “C2“;button20.Text = “Sin“;button21.Text = “Cos“;button22.Text = “Tan“;button23.Text = “Log10“;button24.Text=“Lg“;button25.Text = “!“;button25.Font = new Font(“,10,FontStyle.Bold);button26.Text = “2“;radioButton1.Text = “二进制“;radioButton2.Text = “八进制“;radioButton3.Text = “十六进制“;radioButton4.Text = “十 进 制“;private void textBox1_TextChanged(object sender, EventArgs e)textBox1.BackColor = Color.White;textBox1.Enabled = false;private void textBox2_TextChanged(object sender, EventArgs e)textBox1.BackColor = Color.White;textBox1.Enabled = false;private void button19_Click(object sender, EventArgs e)anniu(1);private void button2_Click(object sender, EventArgs e)anniu(2);private void button3_Click(object sender, EventArgs e)anniu(3);private void button4_Click(object sender, EventArgs e)anniu(4);private void button5_Click(object sender, EventArgs e)anniu(5);private void button17_Click(object sender, EventArgs e)anniu(6);private void button7_Click(object sender, EventArgs e)anniu(7);private void button8_Click(object sender, EventArgs e)anniu(8);private void button9_Click(object sender, EventArgs e)anniu(9);private void button10_Click(object sender, EventArgs e)if (!textBox1.Text.Equals(“0“)anniu(0);private void button18_Click(object sender, EventArgs e)if (s = 1) s = 10; private void button14_Click(object sender, EventArgs e)fh(“*“);button14.BackColor = Color.BlueViolet;private void button15_Click(object sender, EventArgs e)fh(“%“);button15.BackColor = Color.BlueViolet;private void button12_Click(object sender, EventArgs e)fh(“+“);button12.BackColor = Color.BlueViolet;private void button13_Click(object sender, EventArgs e)fh(“-“);button13.BackColor = Color.BlueViolet;private void button16_Click(object sender, EventArgs e)fh(“/“);button16.BackColor = Color.BlueViolet;private void button6_Click(object sender, EventArgs e)textBox1.Text = “0“;/清空TEXTBOX的显示值a = 0; b = 0; c = 0; s = 1; Fh = “;/初始化所有值private void button1_Click(object sender, EventArgs e)fh(“=“);Thread.Sleep(300);/颜色改变延迟button12.BackColor = SystemColors.Control;/还原按钮颜色button13.BackColor = SystemColors.Control;button14.BackColor = SystemColors.Control;button15.BackColor = SystemColors.Control;button16.BackColor = SystemColors.Control;private void radioButton1_CheckedChanged(object sender, EventArgs e)if (textBox2.Text != null)textBox2.Text = “;jz2(textBox1.Text);elsejz2(textBox1.Text);private void radioButton2_CheckedChanged(object sender, EventArgs e)if (textBox2.Text != null)textBox2.Text = “;jz8(textBox1.Text);elsejz8(textBox1.Text);private void radioButton3_CheckedChanged(object sender, EventArgs e)if (textBox2.Text != null)textBox2.Text = “;jz16(textBox1.Text);elsejz16(textBox1.Text);private void button11_Click(object sender, EventArgs e)textBox2.Text = “;private void radioButton4_CheckedChanged(object sender, EventArgs e)textBox2.Text = c.ToString();private void button20_Click(object sender, EventArgs e)double temp = Convert.ToDouble(textBox1.Text);temp = Math.Sin(3.1415926 * temp / 180);if (textBox2.Text != null)textBox2.Text = “;textBox2.Text = temp.ToString();elsetextBox2.Text = temp.ToString();private void button21_Click(object sender, EventArgs e)double temp = Convert.ToDouble(textBox1.Text);temp = Math.Cos(3.1415926*temp/180);if (textBox2.Text != null)textBox2.Text = “;textBox2.Text = temp.ToString();elsetextBox2.Text = temp.ToString();private void button22_Click(object sender, EventArgs e)double temp = Convert.ToDouble(textBox1.Text);temp = Math.Tan(3.1415926*temp/180);if (textBox2.Text != null)textBox2.Text = “;textBox2.Text = temp.ToString();elsetextBox2.Text = temp.ToString();private void button23_Click(object sender, EventArgs e)double temp = Convert.ToDouble(textBox1.Text);temp = Math.Log10(temp) ;if (textBox2.Text != null)textBox2.Text = “;textBox2.Text = temp.ToString();elsetextBox2.Text = temp.ToString();private void button24_Click(object sender, EventArgs e)double temp = Convert.ToDouble(textBox1.Text);temp = Math.Log(temp);if (textBox2.Text != null)textBox2.Text = “;textBox2.Text = temp.ToString();elsetextBox2.Text = temp.ToString();private void button25_Click(object sender, EventArgs e)long temp = Convert.ToInt64(textBox1.Text);Jiec(temp);if (textBox2.Text != null)textBox2.Text = “;textBox2.Text = Jiec(temp).ToString();elsetextBox2.Text = Jiec(temp).ToString();private void button26_Click(object sender, EventArgs e)long y = Convert.ToInt64(textBox1.Text);double temp= Math.Pow(y,0.5);if (textBox2.Text != null)textBox2.Text = “;textBox2.Text = temp.ToString();elsetextBox2.Text = temp.ToString();一个基于windows phone 7的简单计算器,同样也是进制转换小数问题,我会不断完善,希望跟小白一起慢慢成长MainPage.xaml.csusing System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;using Microsoft.Phone.Controls;namespace WP_JSpublic partial class MainPage : PhoneApplicationPagestring Fh = “;/定义符号位double first, second, result;/定义a第一个值,b第二个值,c输出值long dec = 1;/定义小数最初为一位/ Constructorpublic void anniu(double i)/按钮方法if (Fh.Equals(“)/是否当前有运算符if (dec = 1)/判断是否有小数点first = first * 10 + i;/计算无小数的值elsefirst = first + i / dec;/计算有小数的值dec = dec * 10;/计算下一个小数的位置textBox1.Text = first.ToString();/显示计算的结果else /当前有运算符的方法if (!(result = 0) second = 0; result = 0; /当有计算结果就清除B的值if (dec = 1)/判断是否有小数点second = second * 10 + i;/计算无小数的值elseif (i = 0)/判断在小数位后添加0dec = dec * 10;/计算下一个小数的位置elsesecond = second+ i / dec;/计算有小数的值dec = dec * 10;/计算下一个小数的位置textBox1.Text = second.ToString();/显示计算的结果public void js()/数学计算的方法if (Fh = “/“)/判断是否除数等于0if (second = 0) /是则不计算textBox1.Text = “0“;/被除数不能为0return;/返回elseresult=first/second;else/如果不是出发计算则执行其他计算if (Fh.Equals(“+“) result = first + second; if (Fh.Equals(“-“) result = first - second; if (Fh.Equals(“*“) result = first * second; if (Fh.Equals(“%“) result = first % second; textBox1.Text = result.ToString(); /显示计算结果first = result;/将结果给第一个变量作为 public void fh(string str) /接收运算符的方法if (Fh.Equals(“)/当前是否已经有运算符Fh = str; dec = 1;/没有则接收运算符,小数点失效elsejs();dec = 1; Fh = str;/有则计算当前的值,小数点失效public void jz_2(string jg)long temp = Convert.ToInt64(jg);if (temp 0)arrayi+ = (int)temp % 2;temp /= 2;int array_1 = new inti;for (int j = i - 1; j = 0; j-)array_1j = arrayi - 1 - j;/Array.Reverse(array_1);foreach (int k in array_1)textBox2.Text += k.ToString();public void jz_8(string jg)long temp = Convert.ToInt64(jg);if (temp 0)arrayi+ = (int)temp % 8;temp /= 8;int array_1 = new inti;for (int j = i - 1; j = 0; j-)array_1j = arrayi - 1 - j;/Array.Reverse(array_1);foreach (int k in array_1)textBox2.Text += k.ToString();public void jz_16(string jg)long temp = Convert.ToInt64(jg);if (temp 0)arrayi+ = (int)temp % 16;temp /= 16;int array_1 = new inti;for (int j = i - 1; j = 0; j-)array_1j = arrayi - 1 - j;/Array.Reverse(array_1);foreach (int k in array_1)textBox2.Text += k.ToString(“X“);public MainPage()InitializeComponent();private void button1_Click(object sender, RoutedEventArgs e)anniu(1);private void button2_Click(object sender, RoutedEventArgs e)anniu(2);private void button3_Click(object sender, RoutedEventArgs e)anniu(3);private void button4_Click(object sender, RoutedEventArgs e)anniu(4);private void button5_Click(object sender, RoutedEventArgs e)anniu(5);private void button6_Click(object sender, RoutedEventArgs e)anniu(6);private void button7_Click(object sender, RoutedEventArgs e)anniu(7);private void button8_Click(object sender, RoutedEventArgs e)anniu(8);private void button9_Click(object sender, RoutedEventArgs e)anniu(9);private void button10_Click(object sender, RoutedEventArgs e)if (!textBox1.Text.Equals(“0“)anniu(0);private void button11_Click(object sender, RoutedEventArgs e)fh(“+“);private void button12_Click(object sender, RoutedEventArgs e)fh(“-“);private void button13_Click(object sender, RoutedEventArgs e)fh(“*“);private void button14_Click(object sender, RoutedEventArgs e)fh(“/“);private void button15_Click(object sender, RoutedEventArgs e)fh(“%“);private void button16_Click(object sender, RoutedEventArgs e)textBox1.Text = “0“;/清空TEXTBOX的显示值textBox2.Text=“;first = 0; second = 0; result = 0; dec = 1; Fh = “;/初始化所有值private void button17_Click(object sender, RoutedEventArgs e)if (dec = 1) dec = 10; private void button18_Click(object sender, RoutedEventArgs e)fh(“=“);private void button19_Click(object sender, RoutedEventArgs e)if (textBox2.Text != null)textBox2.Text = “;jz_2(textBox1.Text);elsejz_2(textBox1.Text);private void button20_Click(object sender, RoutedEventArgs e)if (textBox2.Text != null)textBox2.Text = “;jz_8(textBox1.Text);elsejz_8(textBox1.Text);private void button21_Click(object sender, RoutedEventArgs e)if (textBox2.Text != null)textBox2.Text = “;jz_16(textBox1.Text);elsejz_16(textBox1.
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 合营企业合同(标准版)
- 2025年幼师考试材料题库及答案
- 2025年湖北省技能高考(汽车维修类)专业知识考试复习题附答案
- 海南省卫生健康委员会2025年医师资格考试乡村全科执业助理医师复习题及答案
- 2024年双道氢化物发生原子荧光光度计项目项目投资筹措计划书代可行性研究报告
- 2025年机修安全考试题库及答案
- 2025年高二物理上学期限时训练(60分钟)卷一
- 2025年高二物理上学期寒假作业前置测试
- 2025年高二物理上学期计算题专项训练(一)
- 2025年高二物理上学期复习卷八(创新题展望)
- 重庆机场集团有限公司招聘笔试题库2024
- 医疗器械经营质量管理规范现场检查指导原则培训课件
- 专业学位硕士研究生英语智慧树知到答案2024年黑龙江中医药大学
- 放射科影像合作协议书
- 幼儿园大班艺术课件:《国旗国旗红红的哩》
- 医院感染相关法律法规培训课件
- 中考数学解题的思维模式设计与分析探讨
- 头部手术备皮方法
- 企业内部控制培训课件完整版
- 五年级上册生命与健康教案
- 学位申请书单位评语
评论
0/150
提交评论