用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;
namespace 赵巍_复数计算器
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int flag=2,flag1=0;
char fuhao1;
string str="";
public struct cpxNum //复数的结构
{
public double real;
public double imag;
public cpxNum(double real, double imag)
{
this.real = real;
this.imag = imag;
}
}
cpxNum num1, num2, num3 = new cpxNum(0, 0);//定义三个复数
public cpxNum CAdd(cpxNum num1, cpxNum num2) //加法运算函数
{
num3 = new cpxNum((num1.real + num2.real), (num1.imag + num2.imag));
return num3;
}
public cpxNum CSub(cpxNum num1, cpxNum num2) //减法运算函数
{
num3 = new cpxNum((num1.real - num2.real), (num1.imag - num2.imag));
return num3;
}
public cpxNum CMul(cpxNum num1, cpxNum num2) //乘法运算函数
{
num3 = new cpxNum((num1.real * num2.real - num1.imag * num2.imag),
(num1.real * num2.imag + num1.imag * num2.real));
return num3;
}
public cpxNum CDiv(cpxNum num1, cpxNum num2) //除法运算函数
{
num3 = new cpxNum((num1.real * num2.real + num1.imag * num2.imag)
/ (num2.real * num2.real + num2.imag * num2.imag),
(num2.real * num1.imag - num1.real * num2.imag) /
(num2.real * num2.real + num2.imag * num2.imag));
return num3;
}
private void shu_chu(int flag1, string str1, string str2) //输出子函数
{ //flag1标志 为0 将保存的字符串在textBox3和textBox4输出
if (flag1 == 0)
2021-06-06 21:46:45
412KB
复数计算器
1