CWP7简单计算器

上传人:枫** 文档编号:508567371 上传时间:2024-01-03 格式:DOCX 页数:51 大小:30.55KB
返回 下载 相关 举报
CWP7简单计算器_第1页
第1页 / 共51页
CWP7简单计算器_第2页
第2页 / 共51页
CWP7简单计算器_第3页
第3页 / 共51页
CWP7简单计算器_第4页
第4页 / 共51页
CWP7简单计算器_第5页
第5页 / 共51页
点击查看更多>>
资源描述

《CWP7简单计算器》由会员分享,可在线阅读,更多相关《CWP7简单计算器(51页珍藏版)》请在金锄头文库上搜索。

1、基于 C#窗体程序的一个简单计算器,进制转换的小数部分没有完善,初学者,继续努力中.各位大侠请指教,各位小白大家互相学习,一起进步using System;using System.Collections.Generic;using SystemponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Threading;namespace js_easypublicpartialclassForm1

2、 :FormstringFh = ; / 定义符号位double a, b, c;/ 定义 a第一个值, b第二个值, c输出值long s = 1;/ 定义小数最初为一位publicForm1()InitializeComponent();publicvoid anniu(double i)/ 按钮方法if(Fh.Equals( ) / 是否当前有运算符第 1页if(s = 1)/ 判断是否有小数点a = a * 10 + i;/ 计算无小数的值elsea = a + i / s;/ 计算有小数的值s = s * 10;/ 计算下一个小数的位置textBox1.Text = a.ToStri

3、ng();/ 显示计算的结果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();/ 显示计算的结果publicvoid js()/ 数学计算的方法if(Fh =/ ) / 判断是否除数等于0if(b

4、= 0)/ 是则不计算第 2页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;/ 将结果给第一个变量作为publicvoid fh(stringstr)/ 接收运算符的方法if(Fh.E

5、quals( ) / 当前是否已经有运算符Fh = str; s = 1;/ 没有则接收运算符, 小数点失效elsejs();s = 1; Fh = str;/ 有则计算当前的值, 小数点失效/* 暂不支持小数进制转换*/publicvoid jz2(stringjg)/2 进制转换long temp =Convert .ToInt64(jg);if(temp 0)arrayi+ = (int )temp % 2;temp /= 2;int array_1 =new int i;for( intj = i - 1; j = 0; j-)array_1j = arrayi - 1 - j;/Ar

6、ray.Reverse(array_1);foreach( intkin array_1)textBox2.Text += k.ToString();publicvoid jz8(stringjg)/8 进制转换long temp =Convert .ToInt64(jg);if(temp 0)arrayi+ = (int )temp % 8;temp /= 8;第 4页int array_1 =new int i;for( intj = i - 1; j = 0; j-)array_1j = arrayi - 1 - j;/Array.Reverse(array_1);foreach( in

7、tkin array_1)textBox2.Text += k.ToString();publicvoid jz16(stringjg)/ 十六进制转换long temp =Convert .ToInt64(jg);if(temp 0)arrayi+ = (int )temp % 16;temp /= 16;int array_1 =new int i;for( intj = i - 1; j = 0; j-)array_1j = arrayi - 1 - j;foreach( intkin array_1)textBox2.Text += k.ToString(X );第 5页publicl

8、ong Jiec(long jg)/ 阶乘long temp = jg;if(temp = 1)return1;elselong temp1 = Jiec(temp-1);temp = temp * temp1;returntemp;privatevoid Form1_Load( objectsender,EventArgs e)textBox1.Font =new Font ( 宋体 , 14,FontStyle.Bold);textBox2.Font =new Font ( 宋体 , 14,FontStyle.Bold);this .Text = 简单计算器 ;stringdir =ima

9、geangry.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 ;第 6页button6.Text =C1 ;button7.Text =7 ;button8.Text =8 ;button9.Text =9 ;butt

10、on10.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;第 7页radioButton1.Text =二进制 ;radioButton2.Text =八进制 ;radioButton3.Text =十六进制 ;radioButton4.Text = 十进 制;privatevoidtextBox1_TextChanged(objectsender,EventArgs

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 活动策划

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号