같은 텍스트 상자에 이퀄라이제이션을 표시 할 수있는 계산기를 작성하는 데 문제가 있습니다. 25*3(6-5)^2
그런 다음 순서를 망칠 수있는 다른 배열에 넣습니다.
텍스트 상자에 넣기 전에 먼저 분리하려고 시도했기 때문에 다음 코드를 사용했습니다.
namespace CalculatorForDS
{
public partial class Form1 : Form
{
public int i=0, j=0, x;
int[] a;
int[] b;
char[] c;
void Process()
{
a = new int[100];
b = new int[100];
c = new char[100];
}
public Form1()
{
InitializeComponent();
Process();
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 1;
a[i] = a[i] * 10^j + 1;
j++;
x = a[i];
}
private void button16_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "(";
c[i] = '(';
i++;
j = 0;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 2;
a[i] = a[i] * 10^j + 2;
j++;
}
private void button3_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 3;
a[i] = a[i] * 10^j + 3;
j++;
}
private void button4_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 4;
a[i] = a[i] * 10^j + 4;
j++;
}
private void button5_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 5;
a[i] = a[i] * 10^j + 5;
j++;
}
private void button6_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 6;
a[i] = a[i] * 10^j + 6;
j++;
}
private void button7_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 7;
a[i] = a[i] * 10^j + 7;
j++;
}
private void button8_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 8;
a[i] = a[i] * 10^j + 8;
j++;
}
private void button9_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 9;
a[i] = a[i] * 10^j + 9;
j++;
}
private void button17_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + ")";
c[i] = ')';
i++;
j = 0;
}
private void button18_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "^";
c[i] = '^';
i++;
j = 0;
}
private void button12_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "/";
c[i] = '/';
i++;
j = 0;
}
private void button19_Click(object sender, EventArgs e)
{
int lenght = textBox1.TextLength - 1;
string text = textBox1.Text;
textBox1.Clear();
for (int i = 0; i < lenght; i++)
textBox1.Text = textBox1.Text + text[i];
}
private void button13_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "*";
c[i] = '*';
i++;
j = 0;
}
private void button14_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "-";
c[i] = '-';
i++;
j = 0;
}
private void button15_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "+";
c[i] = '+';
i++;
j = 0;
}
private void button11_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + ".";
c[i] = '.';
i++;
j = 0;
}
private void button10_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 0;
a[i] = a[i] + j * 0;
j++;
}
private void button20_Click(object sender, EventArgs e)
{
listBox1.Items.Add(a[i]);
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
그러나 문제는 예를 들어 1과 5를 쓸 때 텍스트 상자에 15가 표시되지만 목록 상자를 사용하여 배열 a [i]의 값을 확인하면 12가됩니다. 또는 115 = 84!
나는 정말로 무엇이 잘못되었는지 알아낼 수 없다.
그래서 나는 다른 방법으로 할 수 있다고 생각하고 텍스트 상자에 넣은 다음 텍스트 상자를 숫자와 피연산자에 대해 int 및 char 또는 다른 것으로 변환했습니다.
내 주요 프로젝트는 스택을 사용하고 입력 된 textbox1의 이퀄라이제이션을 접미사 버전으로 사용하고 표시합니다.
하지만이 프로젝트 이전에는 C ++를 알고 있었지만 C #에 대해서는 전혀 몰랐기 때문에 먼저 간단한 코드를 시도해보고 net에서 몇 가지를 배웠습니다.
누가 도와 주면 정말 고맙겠어요
내 프로그램을 거의 변경하지 않았지만 결국에는 다음과 같은 입력과 같은 문제가 계속 발생했습니다.
123
123으로 들어가는 대신
1203 년
그래서 처음부터 프로그램을 다시 만들고
String x;
char ch = x[i];
if ( ch == '+' || ch =='-' || ch =='*' || ch == '/' || ch == '^' )
{//Here comes the Operators, as for me it works for pushing operators into stack }
else
{//Here comes the Operands, as for me , it works for putting them in another String }
위의 코드를 사용하면 내 프로그램에서 원하는 작업을 수행 할 수 있습니다. 즉, Infix 표현식을 Postfix : D로 바꾸는 것입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다