C#学习8
C#学习8:建一个WPF文件,实现表达式求值,界面比较简陋,添加了一张背景图片,添加背景图片的代码是
[csharp]
<Grid.Background>
<ImageBrush ImageSource="/表达式求值;component/Images/1.jpg" />
</Grid.Background>
再修改background的属性即可
输入的表达式形如:((1+2)*5+1)/4=
[csharp]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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 表达式求值
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
int[,] map = new int[7, 7] { {1,1,-1,-1,-1,1,1}, // 算符间的优先关系
{1,1,-1,-1,-1,1,1},
{1,1,1,1,-1,1,1},
{1,1,1,1,-1,1,1},
{-1,-1,-1,-1,-1,0,100},
{1,1,1,1,100,1,1},
{-1,-1,-1,-1,-1,100,0}
};
char[]str=new char[1005];
char[]optr = new char[1005];
double[]opnd = new double[1005];
int t1, t2, k, len;
char ch, zz;
int temp1, temp2;
double a, b;
public MainWindow()
{
InitializeComponent();
}
public int cam(char c)
{
switch (c)
{
case '+': return 0;
case '-': return 1;
case '*': return 2;
case '/': return 3;
case '(': return 4;
case ')': return 5;
case '#': return 6;
default: return -1;
}
}
public double sol(double x, char c, double y)
{
switch (c)
{
case '+': return x + y;
case '-': return x - y;
case '*': return x * y;
case '/': return x / y;
default: return -1;
}
}
public int z(char c)
{
if ('0' <= c && c <= '9' || c == '.')
return 1;
if (c == ' ')
return -1;
return 0;
}
private void button2_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void button1_Click(object sender, RoutedEv
补充:软件开发 , C# ,