实现加减乘除和进制转换,三角函数,角度弧度的转换,适合于课程设计。其中有些部分不是很完善,请多提意见
一个简单用C#编写的计算器 实现基本功能 虽不是很强大但仅供大家参考
简单的计算器,实现简单的复数计算,方便人们的生活 。。
C#写的复数计算器。里面包括表达式求值的源代码,以及返回运算符的优先级,以及C#中堆栈的申明。(bug进一步查找中)
复数计算器代码C++.pdf
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; //表头 namespace WindowsFormsApplication1 { public partial class Form1 : Form { public struct Complex { public double real; public double imag; public Complex(double real, double imag) { this.real = real; this.imag = imag; } } Complex a, b, result = new Complex(0, 0); // 复数结构的声明 public Complex CPlus(Complex a, Complex b) { result = new Complex((a.real + b.real), (a.imag + b.imag)); return result; } //加法计算函数声明 public Complex CMinus(Complex a, Complex b) { result = new Complex((a.real - b.real), (a.imag - b.imag)); return result; } //减法计算函数声明 public Complex CMultiply(Complex a, Complex b) { result = new Complex((a.real * b.real - a.imag * b.imag), (a.real * b.imag + a.imag * b.real)); return result; } //乘法计算函数声明 public Complex CDivide(Complex a, Complex b) { result = new Complex((a.real * b.real + a.imag * b.imag) / (b.real * b.real + b.imag * b.imag), (b.real * a.imag - a.real * b.imag) / (b.real * b.real + b.imag * b.imag)); return result; } // 除法计算函数声明 public int flag = 0; //输入框判断标志,初始值为0 public string op="0"; //计算符号标志,初始值为“0” public string Equel ; // 是否清空判断标志 public Form1() { InitializeComponent(); } private void button0_Click(object sender, EventArgs e) //”0”~”9”、”.”、”i”等按键处理方法 { (即相应的输入框回显按钮字符) switch (flag) { case 1:a_real.Text += button0.Text; break; case 2: a_imag.Text += button0.Text; break; case 3: b_real.Text += button0.Text; break; case 4: b_imag. Text += button0.Text; break; case 5: textBox_input.Text += button0.Text; break; } } private void clear_Click(object sender, EventArgs e) //清零按键的处理 { a_real.Clear(); a_imag.Clear(); b_real.Clear(); b_imag.Clear(); output_real.Clear(); output_imag.Clear(); textBox_input.Clear(); result_real.Clear(); result_imag.Clear(); } private void button_1_Click(object sender, EventArgs e) //button1~5输入框是否可输入的控制按键处理 { flag = 1; if (equel == "=") a_real.Clear(); //判断是否该输入框需要清零 a_real.Enabled = true; a_imag.Enabled = false; b_real.Enabled = false; b_imag.Enabled = false; textBox_input.Enabled = false; } private void equal_Click(object sender, EventArgs e)// 等号按键处理方法 { a = new Complex(Convert.ToDouble(a_real.Text), Convert.ToDouble(a_imag.Text)); b = new Complex(Convert.ToDouble(b_real.Text), Convert.ToDouble(b_imag.Text)); //将输入的数据转换成双精度类型数据保存以计算 switch (op) //根据计算符号判定调用的函数进行计算 { case "+": CPlus(a, b); break; case "-": CMinus(a, b); break; case "*": CMultiply(a, b); break; case "/": if (b_real.Text == "0" && b_imag.Text == "0") MessageBox.Show("No zero!Please enter again!" + "denominator is" + b.real + "+(" + b.imag + ")i", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);//除法运算判断分母是否为0,若为0则提示错误 else { CDivide(a, b); } break; } result_real.Text = Convert.ToString(result.real); result_imag.Text = Convert.ToString(result.imag);/ / 回显当前计算的结果 equel = "="; flag = 0; //修改标志 } private void extract_Click(object sender, EventArgs e) //复数实部虚部提取按键方法 { String str = textBox_input.Text; string tem,temp; int i, j,m; int len = str.Length; bool k = true; //初始值赋值 i = str.IndexOf("i"); //判断i在字符串中的位置 for (j= 0; j< len - 1&& k; j++) { temp = Convert.ToString(str[j]); if (temp == "+" || temp == "-") k = false; } //判断第一个符号在字符串中的位置 j--; temp = Convert.ToString(str[j]); if (i == len - 1) // 当i在字符串最后时处理办法 { if (temp == "+")当第一符号为正时候处理办法 { if (j == len - 2) output_imag.Text = "1"; // 当虚部为i时,输出为1 else output_imag.Text = str.Substring(j + 1, len - j - 2); } Else //当符号为负时的处理方法 { if (j == 0) { for (m = 1; m< len - 1 && k; m++) { tem= Convert.ToString(str[m]); if (temp == "+" || temp == "-") k = false; } m--; tem= Convert.ToString(str[m]); if (tem == "+") output_imag.Text = str.Substring(m + 1, len - 2 - m); else { if (m == len - 2) output_imag.Text = "-1"; else output_imag.Text = str.Substring(m, len - 1 - m); } output_real.Text = str.Substring(0, j); } else //当第一个符号为负的处理办法 { if (j == len - 2) output_imag.Text = "-1"; //虚部为-i时,输出为-1 else output_imag.Text = str.Substring(j , len - j-1 ); } } output_real.Text = str.Substring(0, j); } else { if (temp == "+") { if (i ==0) output_imag.Text = "1"; else output_imag.Text = str.Substring(0, i); output_real.Text = str.Substring(j+1, len - j - 1); } else { if (j == 0) { if (j == i - 1) output_imag.Text = "-1"; else output_imag.Text = str.Substring(0, i); tem = Convert.ToString(str[i + 1]); if (tem == "+") output_real.Text = str.Substring(i + 2, len - 2 - i); else output_real.Text = str.Substring(i + 1, len - 1 - i); } else { if (i == 0) output_imag.Text = "1"; else output_imag.Text = str.Substring(0, i); output_real.Text = str.Substring(j, len - j); } } } } private void button10_Click(object sender, EventArgs e) // 退格键的处理方法 { switch (flag) // 用字串提取函数提取前length-1个长度的字符串 { case 1: a_real.Text = a_real.Text.Substring(0, a_real.Text.Length - 1); break; case 2: a_imag.Text = a_imag.Text.Substring(0, a_imag.Text.Length - 1); break; case 3: b_real.Text = b_real.Text.Substring(0, b_real.Text.Length - 1); break; case 4: b_imag.Text = b_imag.Text.Substring(0, b_imag.Text.Length - 1); break; case5:textBox_input.Text=textBox_input.Text.Substring(0,textBox_input.Text.Length - 1); break; } } } }
运行环境:VS2010 代码可以直接打开运行 方便大家参考 计算器实现复数的运算功能和基本事实计算
代码不是很长,觉得可以分享一下,虽然都是初学者
可以完成复数的混合四则运算,界面美观,使用方便。 欢迎下载 使用后请评论下,谢谢
这是我们的一个实验,请注意,本程序不提供源代码,仅供界面参考,欢迎广大同胞提出建议,以便改进。
挺好的。可以做简单的复数四则运算,以及计算器的一些表达式运作。
本工具实现了相量与复数的转换,输出格式精确到小数点后两位数 本工具实现了相量与复数的转换,输出格式精确到小数点后两位数
C语言计算器实现 1.实现十进制加减乘除及开方运算 2.实现复数的加减乘除和求模运算 3.实现矩阵的加减乘除及求矩阵范数的运算 4.实现十进制转二进制
使用普通计算器进行复数运算.pdf使用普通计算器进行复数运算.pdf使用普通计算器进行复数运算.pdf使用普通计算器进行复数运算.pdf使用普通计算器进行复数运算.pdf
用C语言写的复数和实数桌面计算器,包含软件调试版发布版,源代码!
自己用C#写的计算器,分享出来,望多多指教 希望朋友们提出宝贵建议或意见以便我日后改进
一、复数的表达方式 a.直角坐标:a+jb,其中a为实部,b为虚部,j为虚数符号 b.极坐标:a
本文实例为大家分享了简单实现C++复数计算器的具体代码,供大家参考,具体内容如下 1.有关计算器的功能 A,实现多个复数(包括实数)的加减乘除,大小比较, B.实现十进制实数的进制转换,可以转换任意进制 2.有关设计的原理 A.复数计算的部分,采用运算符的重载,进行复数的加减乘除以及大小比较 对于输入输出,(>>和<<),加减乘除运算进行重载。 输入的重载,实现a+bi形式的复数的输入。 输出的重载,实现实数的输出(实现特殊的只输出实部虚部之类的)。 加减乘除的重载,实现有关复数的运算。 B.进制转换的部分,采用进制转换的方法,实现10进制的任意进制转换。辗转相除,记录每次
由于在最近的一个项目中需要用到复数表达式的计算,计算的特点是:对于同一个公式需要进行重复多次的计算,每次计算时只需要变换公式中的某些变量的值。于是花了点时间写了个编译型的复数表达式计算器,该计算器的核心思想是对一个字符串编译一次,转换为一个计算序列,计算时不再分析字符串,直接按照计算序列计算。例如:1+2*5,可以转换为类似下面的计算序列:1、数值1赋值到临时变量12、数值2赋值到临时变量23、数值5赋值到临时变量34、临时变量2等于临时变量2乘以临时变量5 5、临时变量1等于临时变量1加上临时变量26、返回临时变量1 这样在多次重复计算是就省去了编译的过程,提高了效率。 基于以上思想我编写了这个编译型复数表达式计算器。 该计算器提供了多种复数计算函数,支持变量(变量在表达式中以大写的V开头),支持多行表达式,表达式之间用分号";"间隔。例如您可以这样写计算表达式:V0=12+i;V1=V0*V0;log(V1); 计算的结果为4.976734 + 0.166282i。 支持常量e和pi,例如表达式e^pii的计算结果为-1.000000 + 0.000000i。支持的运算符有-(负号)、+、-、*、/、^(幂运算符)、=、(、)、i(虚数定义符);支持的函数有abs, arg, conj, real, imag, norm, exp, log, log10, sqrt, sin, cos, sinh, cosh, tan, tanh