0

عبارات جبری بدون محدودیت

 
rezahashemian1374
rezahashemian1374
کاربر برنزی
تاریخ عضویت : مهر 1391 
تعداد پست ها : 254
محل سکونت : تهران

عبارات جبری بدون محدودیت
دوشنبه 22 مهر 1392  7:42 AM

در این برنامه می توانید عدد هم بدهید
در این برنامه می توانید چند حرف هم بدهید
حرف ها باید با حروف بزرگ باشند مثلا AB و FG
برای مثال عبارت AB*V-A/(A^32-48+(8*CD%3)-A/5)+805/GFH+Y را وارد کنید

include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <iostream.h>
#include <string.h>
//********************************* Mid *********************************//

int mid char source[] , int start int count char *dest )
{

//int c = 0;
for ( int i start start count i++)
*
dest source[i];
return 
0;
}

//********************************* String Stack *********************************//
struct strstack
{
char info;
strstack *link;
}*
strs;

int strpush char item )
{

strstack *ptr;
ptr = (strstack*) malloc sizeof strstack ));
ptr->link strs;
ptr->info item;
strs ptr;
return 
0;
}


char strpop()
{

strstack *ptr;
char temp;
ptr strs;
strs strs->link;
temp ptr->info;
freeptr );
return 
temp;
}

//********************************* Linked List *********************************//
struct pulishstack
{
int id;
char info[10];
pulishstack *link;
}*
pulishs;

int pulishpushchar item[] , int id)
{

pulishstack *ptr ;
ptr = ( pulishstack*) malloc (sizeof (pulishstack));
strcpy ptr->info item );
ptr->id id;
ptr->link pulishs;
pulishs ptr;
return 
0;
}


int pulishpop(int id char item[] )
{

pulishstack *ptr;
ptr pulishs;
while ( 
ptr != NULL )
{
if ( 
ptr->id == id )
{

strcpy (item ptr->info );
return 
0;
}

ptr ptr->link;
}
return 
0;
}

//********************************* Priority *********************************//
int priority char str1 ,char str2 )
{
if ( 
str1 == '^' ) return 1;
if ( 
str2 == '^' ) return 0;
if ( 
str1 == '*' || str1 == '/' || str1 == '%' ) return 1;
if ( 
str2 == '*' || str2 == '/' || str2 == '%' ) return 0;
return 
1;
}

//********************************* Pulish *********************************//
int pulishchar p[] , int len )
{

char temp[10] , ctemp ctemp2[2];
int count 0;
for ( 
int i len i++ )
{

mid , &ctemp );
switch (
ctemp)
{
case 
'(' :
strpush'(' );
break;
case 
')' :
if ( 
count != 0)
pulishpush (temp C++);
count 0;
while (
strs->info != '(')
{

ctemp2[0] = strpop();
ctemp2[1] = 0x0;
pulishpush ctemp2 C++);
}

strpop();
break;
case 
'^' :
case 
'*' :
case 
'%' :
case 
'/' :
case 
'+' :
case 
'-' :
if ( 
count != 0)
{

pulishpush (tempC++);
count 0;
}
if ( 
priority strs->info ctemp ))
{
while ( 
strs->info != '(' && priority strs->info ctemp ))
{

ctemp2[0] = strpop();
ctemp2[1] = 0x0;
pulishpush ctemp2 ,C++‎ );
}
}

strpush(ctemp);
break;
default :
if ( 
ctemp >= 48 && ctemp <= 122 )
{

temp[count++] = ctemp;
temp[count] = 0x0;
}
}
}
return 
c-1;
}

//********************************* Long Stack *********************************//
struct lngstack
{
long info;
lngstack *link;
}*
lngs;

int lngpush long item )
{

lngstack *ptr;
ptr = (lngstack*) malloc sizeof lngstack));
ptr->info item;
ptr->link lngs;
lngs ptr;
return 
0;
}


long lngpop()
{

lngstack *ptr;
ptr lngs;
lngs lngs->link;
long temp;
temp ptr->info;
free (ptr);
return 
temp;
}

//********************************* Power *********************************//
long power long x long y)
{

long temp 1;
for ( 
long i i++)
temp *= x;
return 
temp;
}

//********************************* Char *********************************//
struct mychar
{
char chr[10];
long value;
mychar *link;
}*
mychars;

long charexist(char item[])
{

mychar *ptr;
ptr mychars;
while ( 
ptr != NULL )
{
if ( 
strcmp item ptr->chr ) == )
return 
ptr->value;
ptr ptr->link;
}
return 
0;
}


int charinsert(char item[] , long value)
{

mychar *ptr;
ptr = (mychar*) malloc(sizeof(mychar));
strcpyptr->chr item );
ptr->value value;
ptr->link mychars;
mychars ptr;
return 
0;
}

//********************************* Value *********************************//
long value (int count)
{

char temp[10];
long tmp;
long x result;
for ( 
int i <= count i++)
{

pulishpop temp );
if ( (
temp [0] >= 98 && temp[0] <= 122) || (temp [0] >= 65 && temp[0] <= 90))
{

tmp charexist temp );
if ( 
tmp == )
{

printf "Please Enter The Number For %s " temp );
cin >> tmp;
lngpush tmp);
charinsert temp tmp );
}
else
{

lngpush tmp);
}

continue;
}
if ( 
temp[0] > 47 && temp[0] < 58 )
{

tmp atol(temp);
lngpush tmp);
continue;
}

lngpop();
lngpop();
if ( 
temp[0] == '+' )
{

result y;
lngpush(result);
continue;
}
if ( 
temp[0] == '*' )
{

result y;
lngpush(result);
continue;
}
if ( 
temp[0] == '/' )
{

result y;
lngpush(result);
continue;
}
if ( 
temp[0] == '%' )
{

result y;
lngpush(result);
continue;
}
if ( 
temp[0] == '-' )
{

result y;
lngpush(result);
continue;
}
if ( 
temp[0] == '^' )
{

result power(y);
lngpush(result);
continue;
}
}
return 
lngpop();
}

//********************************* Main *********************************//
int main()
{

clrscr();
char p[102];
int len plen 0;
printf "Algebra Phrases\nPlease Enter The Phrase\n For Example : \nAB*V-A/(A^32-48+(8*CD%3)-A/5)+805/GFH+Y \n" );
scanf "%s" );
len strlen);
for ( 
int i len i--)
{

[i] = [1];
if ( 
p[i] == ')' plen++;
if ( 
p[i] == '(' plen--;
if ( 
plen )
{

printf ("Error In Phrase\nUnexpected ')' or '(' ");
getch();
return 
0;
}
}
if ( 
plen != )
{

printf ("Error In Phrase\nUnexpected ')' or '(' ");
getch();
return 
0;
}

p] = '(' ;
p[ ++len ] = ')' ;
p[ ++len ] = 0x0;
int c;
pulish len );
long result;
result value(c);
cout << result;
getch();
return 
0;
}

Seyyed.Reza.Hashemian@Gmail.Com

دوستانی که سوالی دارند یا مایل به تماس هستند می توانند از اطلاعات بالا استفاده نمایند.

اگر هم تایپکی زدید و احتیاج به پاسخگویی سریع داشتید اطلاع دهید

تشکرات از این پست
دسترسی سریع به انجمن ها