Здравствуйте! Нужна Ваша помощь! Нужно запрограммировать textbox(для ввода уравнения), чтобы нажимая кнопку button, результат решения уравнения выводился в Label.
Есть код в с++, а как переделать его в си#не знаю для Visual Studio...
Код:
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
char s[100], ch,const1[10];
int pos,ierror,indNumber,Noper, Nedin;
int A[25][2];
//s - исходная строка;
//ch - текущий символ.
//pos - позиция символа
//ierror - показатель ошибки: 0-ошибки нет, 1-ошибка есть.
//Чтение следующего символа (не пробела)
void NextCh()
{
do
{ pos++;
ch=s[pos];
}
while (ch==' ');
return;
}
void ResetText ()
{
printf("VVedite mnogochlen do .: ");
// Ввод с клавиатуры до точки
scanf("%[^.]",&s);
pos=-1; ierror=0;
//Читаем первый символ
NextCh();
return;
}
//Проверка числа
void Number()
{
if ((ch=='0')||(ch=='1')||(ch=='2')||(ch=='3')||(ch=='4')||(ch=='5')||(ch=='6')||(ch=='7')||(ch=='8')||(ch=='9'))
{
indNumber=1;
Nedin++;const1[Nedin]=ch;
NextCh();
Number();
}
}
void Power()
{
if (ch=='^')
{
Noper++;A[Noper][0]=4;A[Noper][1]=0;
NextCh();
Nedin=-1;
Number();
const1[Nedin+1]='\0';
Noper++;A[Noper][0]=2;A[Noper][1]=atoi(const1);
}
}
void Multiply()
{
int i;
if (ch=='*')
{
Noper++;A[Noper][0]=3;A[Noper][1]=0;
NextCh();
if (ch=='x')
{
Noper++;A[Noper][0]=5;
NextCh();
Power();
}
else
{
if (pos<strlen(s))
{
ierror=1;
printf("%s\n",s);
for (i=0;i<pos;i++) printf(" ");
printf("^\nOshibka! gde x?");
}
}
}
}
//Проверка слагаемого
void Slag()
{int i;
indNumber=0;Nedin=-1;
Number();
if (indNumber==1)
{
const1[Nedin+1]='\0';
Noper++;A[Noper][0]=2;A[Noper][1]=atoi(const1);
Multiply();
}
else
if (ch=='x')
{
Noper++;A[Noper][0]=5;
NextCh();
Power();
}
else
{
if (pos<strlen(s))
{
ierror=1;
printf("%s\n",s);
for (i=0;i<pos;i++) printf(" ");
printf("^\nOshibka! gde x?");
}
}
}
void Polinom()
{ int i;
if ((ch=='+')||(ch=='-'))
{ Noper++; A[Noper][0]=1;
if (ch=='-') A[Noper][1]=0; else A[Noper][1]=1;
NextCh();
//Проверяем слагаемое
Slag();
if (ierror==0)
{if (pos<strlen(s)) Polinom(); else
{
printf ("Verno!!!\n");
}
}
}
else
{if ((pos>0))
{
ierror=1;
printf("%s\n",s);
for (i=0;i<pos;i++) printf(" ");
printf("^\nOshibka! Gde *?");
}
else
//Проверяем слагаемое
Slag();
if (ierror==0)
{if (pos<strlen(s)) Polinom(); else
{
printf ("Verno!!!\n");
}
}
}
}
void calc()
{int i,j,Rez=0;
double x;
if (ierror==0)
{
printf("x=3");
x=3;
printf("\n");
for (i=0; i<=Noper; i++)
if (A[i][0]==5) A[i][1]=x;
for (i=0; i<=Noper; i++)
{for(j=0;j<2;j++) printf("%3d",A[i][j]);
printf("\n");
}
printf("------------\n");
for (i=0; i<=Noper; i++)
if (A[i][0]==4)
{
A[i-1][0]=2;
A[i-1][1]=pow(x,A[i+1][1]);
A[i][0]=0;A[i+1][0]=0;
}
for (i=0; i<Noper;i++)
if (A[i][0]==3)
{
A[i-1][0]=2;
A[i-1][1]=A[i-1][1]*A[i+1][1];
A[i][0]=0;A[i+1][0]=0;
}
if (A[0][0]==2) Rez=A[0][1];
for (i=0; i<Noper;i++)
{
if (A[i][0]==1 && A[i][1]==0)
{
Rez=Rez-A[i+1][1];
A[i][0]=0;
A[i+1][0]=0;
}
if (A[i][0]==1 && A[i][1]==1)
{
Rez=Rez+A[i+1][1];
A[i][0]=0;
A[i+1][0]=0;
}
}
printf("Rez=%d\n",Rez);
}
}
main()
{
//Ввод выражения
Noper=-1;
ResetText();
Polinom();
calc();
}