اين برنامه به زبان فارسيه ؟نقل قول:
ضمنا شما برنامه کنسول که نمي خواين . مي خواين ؟
راستي چرا هميشه وقتي سورس و راهنمايي مي خواين هميشه با دعوا و مرافه ؟ با ملايمت هم ميشه . :46:
Printable View
اين برنامه به زبان فارسيه ؟نقل قول:
ضمنا شما برنامه کنسول که نمي خواين . مي خواين ؟
راستي چرا هميشه وقتي سورس و راهنمايي مي خواين هميشه با دعوا و مرافه ؟ با ملايمت هم ميشه . :46:
خوب ظاهرا شما دقيقا اينو از جايي کپي کردين و گذاشتين و خودتون يک بار هم امتحان نکردين که ببينين برنامه درسته يا نه و اصلا چيکار مي کنه و اين فرمولي رو که گفتين واقعا حل ميکنه يا نه .نقل قول:
چون من که زدم 102 تا ارور داد . چرا با اين قاطعيت از برنامه اي که خودتون هم نمي دونين توش چيه و اصلا ماشين حساب هست يا کد سيستم عامله دفاع مي کنين و به قول خودتون close source ها رو مورد خطاب قرار مي دين ؟ :13:
عزیزم کامپایار میدونی چیه ؟ کامپایلرت نسخش فرق میکنه مهندس . من که بدون هیچ مشکلی باهاش کار کردم .
دوما به کسی مربوط نیست که کپی کردم یا نه . سوما بلدی بگو نیستی خوش اومدی .
چهارما کامپایلر میدونی چیه ؟ :D
این برنامه با borland کامپایل میشه برای visual باید تغییراتی توش بدید ضمن این که چند جا متغییر تعریف نشده به همین دلیل ارور داده من تغییر دادم مشکلی نداره
کد:// C++.cpp : main project file.
#include "stdafx.h"
using namespace System;
#include "iostream"
#include "fstream"
#include "string"
#include "ctype.h"
#include "stdlib.h"
#include "math.h"
using namespace std;
using namespace IO;
void brackets(float[],char*,int,int&);
void operate(float[],char*,int);
void squeeze(float[],char*,int&,int);
void specfunc(float[],char*,int&,int,int);
void strconvert(float*&,char*&,int&,int&);
void strconvert(float*&nexpres,char*&newo,int &nicount,int &oicount)
{
// a:
ifstream istring;
ofstream ostring;
ostring.open("cal.dat",ios::out);
char ch;
nicount=0;
int njcount=1;
oicount=0;
//counts all the numbers and operators
do
{
cin.get(ch);
ostring<<ch;
if(isdigit(ch) || ch=='.')
{
nicount++;
cin.get(ch);
ostring<<ch;
for(int tempnj=2;isdigit(ch) || ch=='.' ;tempnj++)
{
if(tempnj>njcount)
{
njcount=tempnj;
}
cin.get(ch);
ostring<<ch;
}
}
if(isalpha(ch))
{
oicount++;
cin.get(ch);
ostring<<ch;
for(;isalpha(ch);)
{
cin.get(ch);
ostring<<ch;
}
}
if(isalnum(ch)==0 && ch!='\n' && ch!='.')
oicount++;
}
while(ch!='\n');
ostring.close();
char **oexpres=new char*[oicount+1]; //+1 for safety
for (int index=0;index<oicount;index++)
{
oexpres[index]=new char[5]; //max asin+1
}
char **numch=new char*[nicount+1];
for (int index=0;index<nicount;index++)
{
numch[index]=new char[njcount+1];
}
istring.open("cal.dat",ios::in);
//puts numbers and operators in seperate 2-d strings
int ni=0,oi=0;
do
{
istring.get(ch);
if(isdigit(ch) || ch=='.' && ni<nicount)
{
numch[ni][0]=ch;
istring.get(ch);
for(int nj=1;isdigit(ch) || ch=='.' && nj<njcount;nj++)
{
numch[ni][nj]=ch;
istring.get(ch);
}
ni++;
}
if(isalpha(ch))
{
oexpres[oi][0]=ch;
istring.get(ch);
for(int oj=1;isalpha(ch) && oj<4;oj++)
{
oexpres[oi][oj]=ch;
istring.get(ch);
}
oi++;
}
if(isalnum(ch)==0 && ch!='.' && ch!='\n' && oi<oicount)
{
oexpres[oi][0]=ch;
oi++;
}
}
while(ch!='\n');
//converts number string to float a string
nexpres=new float[nicount];
for(int index=0;index<nicount;index++)
{
nexpres[index]=atof(numch[index]);
}
newo=new char[oicount+1];
for(int index=0;index<oicount;index++)
{
if (isalpha(oexpres[index][0]))
{
if(strncmp(oexpres[index],"sin",3)==0)
{oexpres[index][0]='s';}
else if(strncmp(oexpres[index],"cos",3)==0)
{oexpres[index][0]='c';}
else if(strncmp(oexpres[index],"tan",3)==0)
{oexpres[index][0]='t';}
else if(strncmp(oexpres[index],"asin",4)==0)
{oexpres[index][0]='i';}
else if(strncmp(oexpres[index],"acos",4)==0)
{oexpres[index][0]='o';}
else if(strncmp(oexpres[index],"atan",4)==0)
{oexpres[index][0]='a';}
else if(strncmp(oexpres[index],"log",3)==0)
{oexpres[index][0]='g';}
else if(strncmp(oexpres[index],"ln",2)==0)
{oexpres[index][0]='n';}
else if(strncmp(oexpres[index],"exp",3)==0)
{oexpres[index][0]='e';}
else if(strncmp(oexpres[index],"abs",3)==0)
{oexpres[index][0]='b';}
else if(strncmp(oexpres[index],"sqrt",4)==0)
{oexpres[index][0]='q';}
}
newo[index]=oexpres[index][0];
}
}
void brackets(float nexpres[],char *oexpres,int nxindex,int &oxindex)
{
int bcount=0;
for(int i=0;i<oxindex;i++) //counts times to perform funtion
{
if (oexpres[i]==')')
bcount++;
}
for(int braks=0;braks<bcount;braks++)
{
int end=0;
for(;oexpres[end]!=')';end++)
{}
int begin=end;
for(;oexpres[begin]!='(';begin--)
{}
float *number=new float[end-begin];
char *operators=new char[end-begin]; // chars+ '/0'
int numpos=0;
int i;
for(int i=0;i<begin;i++) //for nested brackets
{
if (oexpres[i]=='(' || isalpha(oexpres[i]))
numpos++;
}
i=0;
for(int k=(begin-numpos);k<(end-numpos);k++) //load up number with bracket elements
number[i++]=nexpres[k];
for(int k=begin+1,i=0;k<end;k++)
operators[i++]=oexpres[k]; //load up with operators
operate(number,operators,(end-begin-1));
nexpres[begin-numpos]=number[0];
int j=(begin-numpos+1);
for(i=(end-numpos);i<nxindex;i++)
nexpres[j++]=nexpres[i];
for(i=end+1,j=begin;i<oxindex;i++)
oexpres[j++]=oexpres[i];
nxindex-=(end-begin-1);
oxindex-=(end-begin+1);
if(isalpha(oexpres[begin-1]))
specfunc(nexpres,oexpres,oxindex,begin,numpos);
}
}
void operate(float number[],char*operators,int oindex)
{
const char* orderof="^/*-+";
for(int k=0;k<5;k++) //changes operator according to precedence
{
for(int i=0;i<oindex;i++) //marches through the statement
{
if(operators[i]==orderof[k]) //checks for desired operator
{
switch(operators[i]) //conducts the operation
{
case '^':number[i]=pow(number[i],number[i+1]);break;
case '*':number[i]*=number[i+1];break;
case '/':number[i]/=number[i+1];break;
case '+':number[i]+=number[i+1];break;
case '-':number[i]-=number[i+1];break;
}
squeeze(number,operators,oindex,(i+1)); //squeezeout (i+1)
if(oindex==1)
i--;
if(i!=(oindex-1)) //re-test same index with new 'squeezed' values
i--;
}
}
}
}
void squeeze(float number[],char*operators,int &oindex,int squeezeout)
{//sqeezes remaining operation together, maintains integrity of loop
for(int j=squeezeout;j<oindex;j++)
{
number[j]=number[j+1];
operators[j-1]=operators[j];
}
oindex--;
}
void specfunc
(float nexpres[],char *oexpres,int &oxindex,int begin,int numpos)
{
switch(oexpres[begin-1])
{
case 's':nexpres[begin-numpos]=sin(nexpres[begin-numpos]);break;
case 'c':nexpres[begin-numpos]=cos(nexpres[begin-numpos]);break;
case 't':nexpres[begin-numpos]=tan(nexpres[begin-numpos]);break;
case 'i':nexpres[begin-numpos]=asin(nexpres[begin-numpos]);break;
case 'o':nexpres[begin-numpos]=acos(nexpres[begin-numpos]);break;
case 'a':nexpres[begin-numpos]=atan(nexpres[begin-numpos]);break;
case 'g':nexpres[begin-numpos]=log10(nexpres[begin-numpos]);break;
case 'n':nexpres[begin-numpos]=log(nexpres[begin-numpos]);break;
case 'e':nexpres[begin-numpos]=exp(nexpres[begin-numpos]);break;
case 'b':nexpres[begin-numpos]=abs(nexpres[begin-numpos]);break;
case 'q':nexpres[begin-numpos]=sqrt(nexpres[begin-numpos]);break;
}
for(int j=begin;j<oxindex;j++)
oexpres[j-1]=oexpres[j];
oxindex--;
}
void main()
{
float *nexpres;
char *oexpres;
int nxindex,oxindex;
cout<<"//all calculations are in radians"<<endl<<endl;
cout<<"calculate->";
strconvert(nexpres,oexpres,nxindex,oxindex);
brackets(nexpres,oexpres,nxindex,oxindex);
operate(nexpres,oexpres,oxindex);
cout<<"="<<nexpres[0];
//to view all elements
//for(int i=0;i<nxindex;i++)
//cout<<nexpres[i]<<" ";
//cout<<endl;
//for(int i=0;i<oxindex;i++)
//cout<<oexpres[i];
//cout<<endl;
cin.ignore(128, '\n');
}
:31: :31:نقل قول:
بنده متاسفانه نمي دونم کامپايلر يعني چي . ببخشيد . واقعا عذر مي خوام .
حالا مطمئن شدم برنامه رو تست نکردين .
دکتر !!!! هيچ وقت براي يه هدر فايل 102 تا ارور داده نمي شه . اگه نتونست هدر فايل رو بشناسه 1 ارور مي ده و اجراي برنامه همون جا مي مونه . (چون پيش پردازنده قبل از کامپايل برنامه اجرا ميشه ! :46: )
هيچ وقت تو ++C وقتي مي خوان در مورد Syntax ارور برنامه حرف بزنن سراغ هدر و ;using namespace std نمي رن . همه مي دونن برنامه تو توربو سي چطور اجرا ميشه و تو Visual Studio چطور . مشکل شما همون تعريف متغيرها بود که دوست عزيزمون m_h_hadavi هم اشاره کردن .
مي دونم تعريف متغير مسئله مهمي تو برنامه نويسي نيست ولي بالاخره مهم اينه که باعث ميشه برنامه اجرا نشه . منظور من هم از مطرح کردن ايراد برنامه اين بود که ثابت کنم شما برنامه رو همين جوري گذاشتي و تست نکردي . :31:
حالا فرض کن من اون اضافاتي رو که گفتي اعمال کردم ( درصد و اينا ) ، شما از کجا مي فهمي که درسته يا نه ؟
موفق باشي پروفسور ...............
اين هم کد کامل اين برنامه که مشکل متغير ها هم جل شد و چند تا Warning هم داشت ( 9 تا ) که اونا رو هم حل کردم . با استفاده از Tab و اينا هم خوندن برنامه آسان تر شده ( براي کسايي که مي خوان توسعه اش بدن )
;using namespace IO و ;using namespace systemبرام نياز نشدن . اينا براي چي هستن ؟
[html]
#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
#include <cstdlib>
#include <cmath>
using namespace std;
void brackets ( double [], char *, int, int & );
void operate ( double [], char *, int );
void squeeze ( double [], char *, int &, int );
void specfunc ( double [], char *, int &, int, int );
void strconvert ( double *&, char *&, int &, int & );
int main ()
{
double *nexpres;
char *oexpres;
int nxindex, oxindex;
cout << "//all calculations are in radians\n\n";
cout << "calculate->";
strconvert ( nexpres, oexpres, nxindex, oxindex );
brackets ( nexpres, oexpres, nxindex, oxindex );
operate ( nexpres, oexpres, oxindex );
cout << "=" << nexpres [ 0 ];
cin.ignore ( 128, '\n');
return 0;
}
void strconvert ( double *&nexpres, char *&newo, int &nicount, int &oicount )
{
ifstream istring;
ofstream ostring;
ostring.open ( "cal.dat", ios::out );
char ch;
nicount = 0;
int njcount = 1;
oicount = 0;
do
{
cin.get ( ch );
ostring << ch;
if ( isdigit ( ch ) || ch == '.' )
{
nicount++;
cin.get ( ch );
ostring << ch;
for ( int tempnj = 2; isdigit ( ch ) || ch == '.'; tempnj++ )
{
if ( tempnj > njcount )
{
njcount = tempnj;
}
cin.get ( ch );
ostring << ch;
}
}
if ( isalpha ( ch ) )
{
oicount++;
cin.get ( ch );
ostring << ch;
for ( ; isalpha ( ch ); )
{
cin.get ( ch );
ostring << ch;
}
}
if ( isalnum ( ch ) == 0 && ch != '\n' && ch != '.' )
oicount++;
} while ( ch != '\n' );
ostring.close ();
char **oexpres = new char * [ oicount + 1 ];
for ( int index = 0; index < oicount; index++ )
{
oexpres [ index ] = new char [ 5 ];
}
char **numch = new char * [ nicount + 1 ];
for ( int index = 0; index < nicount; index++ )
{
numch [ index ] = new char [ njcount + 1 ];
}
istring.open ( "cal.dat", ios::in );
int ni = 0, oi = 0;
do
{
istring.get ( ch );
if ( isdigit ( ch ) || ch == '.' && ni < nicount )
{
numch [ ni ][ 0 ] = ch;
istring.get ( ch );
for ( int nj = 1; isdigit ( ch ) || ch == '.' && nj < njcount; nj++ )
{
numch [ ni ][ nj ] = ch;
istring.get ( ch );
}
ni++;
}
if ( isalpha ( ch ) )
{
oexpres [ oi ][ 0 ] = ch;
istring.get ( ch );
for ( int oj = 1; isalpha ( ch ) && oj < 4; oj++ )
{
oexpres [ oi ][ oj ] = ch;
istring.get ( ch );
}
oi++;
}
if ( isalnum ( ch ) == 0 && ch != '.' && ch != '\n' && oi < oicount )
{
oexpres [ oi ][ 0 ] = ch;
oi++;
}
} while ( ch != '\n' );
nexpres = new double [ nicount ];
for ( int index = 0; index < nicount; index++ )
{
nexpres [ index ] = atof ( numch [ index ] );
}
newo = new char [ oicount + 1 ];
for ( int index = 0; index < oicount; index++ )
{
if ( isalpha ( oexpres [ index ][ 0 ] ) )
{
if ( strncmp ( oexpres [ index ], "sin", 3 ) == 0 )
oexpres [ index ][ 0 ] = 's';
else if ( strncmp ( oexpres [ index ], "cos", 3 ) == 0 )
oexpres [ index ][ 0 ] = 'c';
else if ( strncmp ( oexpres [ index ], "tan", 3 ) == 0 )
oexpres [ index ][ 0 ] = 't';
else if ( strncmp ( oexpres [ index ], "asin", 4 ) == 0 )
oexpres [ index ][ 0 ] = 'i';
else if ( strncmp ( oexpres [ index ], "acos", 4 ) == 0 )
oexpres [ index ][ 0 ] = 'o';
else if ( strncmp ( oexpres [ index ], "atan", 4 ) == 0 )
oexpres [ index ][ 0 ] = 'a';
else if ( strncmp ( oexpres [ index ], "log", 3 ) == 0 )
oexpres [ index ][ 0 ] = 'g';
else if ( strncmp ( oexpres [ index ], "ln", 2 ) == 0 )
oexpres [ index ][ 0 ] = 'n';
else if ( strncmp ( oexpres [ index ], "exp", 3 ) == 0 )
oexpres [ index ][ 0 ] = 'e';
else if ( strncmp ( oexpres [ index ], "abs", 3 ) == 0 )
oexpres [ index ][ 0 ] = 'b';
else if ( strncmp ( oexpres [ index ], "sqrt", 4 ) == 0 )
oexpres [ index ][ 0 ] = 'q';
}
newo [ index ] = oexpres [ index ][ 0 ];
}
}
void brackets(double nexpres[],char *oexpres,int nxindex,int &oxindex)
{
int bcount = 0;
int i, k;
for ( i = 0; i < oxindex; i++ )
{
if ( oexpres [ i ] == ')' )
bcount++;
}
for ( int braks = 0; braks < bcount; braks++ )
{
int end = 0;
for ( ; oexpres [ end ] != ')'; end++ )
{
}
int begin = end;
for ( ; oexpres [ begin ] != '('; begin-- )
{
}
double *number = new double [ end - begin ];
char *operators = new char [ end - begin ];
int numpos = 0;
for ( i = 0; i < begin; i++ )
{
if ( oexpres [ i ] == '(' || isalpha ( oexpres [ i ] ) )
numpos++;
}
i = 0;
for ( k = ( begin - numpos ); k < ( end - numpos ); k++ )
number [ i++ ] = nexpres [ k ];
for ( k = begin + 1, i = 0; k < end; k++ )
operators [ i++ ] = oexpres [ k ];
operate ( number, operators, ( end - begin - 1 ) );
nexpres [ begin - numpos ] = number [ 0 ];
int j = ( begin - numpos + 1 );
for ( i = ( end - numpos ); i < nxindex; i++ )
nexpres [ j++ ] = nexpres [ i ];
for ( i = end + 1, j = begin; i < oxindex; i++ )
oexpres [ j++ ] = oexpres [ i ];
nxindex -= ( end - begin - 1 );
oxindex -= ( end - begin + 1 );
if ( isalpha ( oexpres [ begin - 1 ] ) )
specfunc ( nexpres, oexpres, oxindex, begin, numpos );
}
}
void operate ( double number [], char *operators, int oindex )
{
const char *orderof = "^/*-+";
for ( int k = 0; k < 5; k++ )
{
for ( int i = 0; i < oindex; i++ )
{
if ( operators [ i ] == orderof [ k ] )
{
switch ( operators [ i ] )
{
case '^':
number [ i ] = pow ( number [ i ], number [ i + 1 ] );
break;
case '*':
number [ i ] *= number [ i + 1 ];
break;
case '/':
number [ i ] /= number [ i + 1 ];
break;
case '+':
number [ i ] += number [ i + 1 ];
break;
case '-':
number [ i ] -= number [ i + 1 ];
break;
}
squeeze ( number, operators, oindex, ( i + 1 ) );
if ( oindex == 1 )
i--;
if ( i != ( oindex - 1 ) )
i--;
}
}
}
}
void squeeze ( double number [], char *operators, int &oindex, int squeezeout )
{
for ( int j = squeezeout; j < oindex; j++ )
{
number [ j ] = number [ j + 1 ];
operators [ j - 1 ] = operators [ j ];
}
oindex--;
}
void specfunc ( double nexpres [], char *oexpres, int &oxindex, int begin, int numpos )
{
switch ( oexpres [ begin - 1 ] )
{
case 's':
nexpres [ begin - numpos ] = sin ( nexpres [ begin - numpos ] );
break;
case 'c':
nexpres [ begin - numpos ] = cos ( nexpres [ begin - numpos ] );
break;
case 't':
nexpres [ begin - numpos ] = tan ( nexpres [ begin - numpos ] );
break;
case 'i':
nexpres [ begin - numpos ] = asin ( nexpres [ begin - numpos ] );
break;
case 'o':
nexpres [ begin - numpos ] = acos ( nexpres [ begin - numpos ] );
break;
case 'a':
nexpres [ begin - numpos ] = atan ( nexpres [ begin - numpos ] );
break;
case 'g':
nexpres [ begin - numpos ] = log10 ( nexpres [ begin - numpos ] );
break;
case 'n':
nexpres [ begin - numpos ] = log ( nexpres [ begin - numpos ] );
break;
case 'e':
nexpres [ begin - numpos ] = exp ( nexpres [ begin - numpos ] );
break;
case 'b':
nexpres [ begin - numpos ] = abs ( nexpres [ begin - numpos ] );
break;
case 'q':
nexpres [ begin - numpos ] = sqrt ( nexpres [ begin - numpos ] );
break;
}
for ( int j = begin; j < oxindex; j++ )
oexpres [ j - 1 ] = oexpres [ j ];
oxindex--;
}
[/html]
شما از چه کامپایلری استفاده کردید من از visual 2005 استفاده کردم
برای استفاده از توابع fstream و .. باید using namespace IO;
رو تعریف کرد
using namespace System; هم اضافی هست
من هم از 2008 . نسخه Professional . شما وقتي نمي ذارين ارور ميده ؟نقل قول:
بلهنقل قول:
من بیشتر با C++ Builder 2009 کار کردم اونجا نیاز نیست IO رو هم گشتم پیدا کردم تا به حال ازش استفاده نکرده بودم
به گفته دوست عزیزمان برنامه 9 تا ارور داشت اون هم برای تعریف متغیر بوده . یک متغیر چند جا تعریف شده بود . مشکلش را حل کرده بودم . ولی مثل اینکه کد قدیمی را گذاشته بودم .
و اگه شما درصد را توش بذارین و بگین چطور میشه ازش استفاده کرد بسیار ممنون میشیم. همین . سخته ؟ یا میشه ؟