ورود

View Full Version : تبدیل کد c++ از توربو به ویژوال استدیو



arefba
سه شنبه 28 اردیبهشت 1389, 20:18 عصر
بسمه تعالی

با سلام
چطور میشه کد زیر رو کانورت کرد از توربو (داس ) به ویژوال استدیو :متفکر:

#include <iostream.h>
#include<conio.h>
char save[200];
int counter;


struct save2
{
int counter2;
save2 * link;
};
save2 * first2,* last2,* newptr2;

int inta()
{
newptr2=first2;
while(newptr2!=last2)
{
newptr2=newptr2->link;
}
return newptr2->counter2;
}
int intb()
{
newptr2=first2;
while(newptr2->link!=last2)
{
newptr2=newptr2->link;
}
return newptr2->counter2;
}
void add2(char ch)
{
newptr2= new save2;
newptr2->counter2=ch-48;
newptr2->link=NULL;
if(first2==NULL)
{
last2=newptr2;
first2=newptr2;
}
else
{
last2->link= newptr2;
last2=newptr2;
}
}
//**********************************************
void del2()
{
newptr2=first2;
if (newptr2->link!=NULL)
{
while(newptr2->link!=last2)
{
newptr2=newptr2->link;
}
newptr2->link=NULL;
last2=newptr2;
}
else
{
first2=NULL;
}
}
int hasel(int a,int b,char ch)
{
newptr2=first2;
while(newptr2->link!=last2)
{
newptr2=newptr2->link;
}
switch (ch)
{
case '*':
newptr2->counter2=a*b;
del2();
break;
case '/':
newptr2->counter2=a/b;
del2();
break;
case '+':
newptr2->counter2=a+b;
del2();
break;
case '-':
newptr2->counter2=a-b;
del2();
break;
}
}
struct posh
{
char poshte;
posh * link;
};
posh * first,* last, * newptr;

//**********************************************
void add(char ch)
{
newptr= new posh;
newptr->poshte=ch;
newptr->link=NULL;
if(first==NULL)
{
last=newptr;
first=newptr;
}
else
{
last->link= newptr;
last=newptr;
}
}
//**********************************************
void del()
{
if(newptr!=first)
{
newptr=first;

while(newptr->link!=last)
{
newptr=newptr->link;
}
newptr->link=NULL;
delete last;
last=newptr;
}
else
{
first=NULL;
}
}




int olaviat(char ch)
{
switch (ch)
{
case '*':
return 10;
case '/':
return 10;
case '%':
return 10;
case '+':
return 5;
case '-':
return 5;
}

}

void main()
{
first=NULL;
clrscr();
char ch[50];
cin>>ch;
for (int a=0;ch[a]!='\0';a++)
{
if(ch[a]>='0' && ch[a]<='9')
{
cout<<ch[a];
save[counter++]=ch[a];
}
else
{
if(ch[a]==')' || ch[a]=='(')
{
if(ch[a]=='(')
add('(');
if(ch[a]==')')
{
while(newptr->poshte!='(')
{
cout<<newptr->poshte;
save[counter++]=newptr->poshte;
del();
}
del();
}
}
else
{
if (first==NULL)
{
add(ch[a]);
}
else
{
if(olaviat(ch[a])>olaviat(newptr->poshte))
{
add(ch[a]);
}
else
{
while(olaviat(ch[a])<=olaviat(newptr->poshte)&& first!=NULL)
{
cout<<newptr->poshte;
save[counter++]=newptr->poshte;
del();

}
add(ch[a]);
}
}
}
}
}

//**************************************
while(first!=NULL)
{
cout<<newptr->poshte;
save[counter++]=newptr->poshte;
del();
}
cout<<"\nRESULT : ";

//**************************RESULT****************
for(int v=0;save[v]!=NULL;v++)
{
switch (save[v])
{
case '*':
hasel(inta(),intb(),'*');
break;
case'+':
hasel(inta(),intb(),'+');
break;
case'/':
hasel(intb(),inta(),'/');
break;
case'-':
hasel(intb(),inta(),'-');
break;
default:
add2(save[v]);
}
}
cout<<last2->counter2;
//*************************************************
getch();
}

arefba
چهارشنبه 29 اردیبهشت 1389, 00:38 صبح
کسی نبود جواب ما رو بده

Nima_NF
چهارشنبه 29 اردیبهشت 1389, 16:09 عصر
از آنجایی که این سوال تکراری ترین سوال این فروم به حساب می آید، لطفا در بخش عمومی C/C++‎ جستجو کنید بارها توضیح داده شده است:

FAQ شماره 8 ،9 ، 13 و 19 را مطالعه کنید (http://barnamenevis.org/forum/showthread.php?t=166590)