12.a 若fp已经指向文件末尾,则feof(fp)函数值为“真”,即返回非零值;否则返回0。
13.b
14.2
15.1
16.1
17.2
18.1
19.1 sizeof(double)=8, 32位机中占8个字节
20.2
前面那个有点问题,这是改进后的:#include<iostream>
#include<string>
#include<stack>
#include<cctype>
using namespace std
double count(double left,char op,double right)
int you(char op)
double chuli(string stra)
stack<double>opnd
stack<char>optr
char carstring str=""
double count(double left,char op,double right)
{
double ret
int reta
if(op=='+'){
ret=left+right
return ret
}
if(op=='-'){
ret=left-right
return ret
}
if(op=='*'){
ret=left*right
return ret
}
if(op=='/'){
ret=left/right
return ret
}
if(op=='%'){
int lefta,righta
lefta=(int)left
righta=(int)right
reta=lefta%righta
return reta
}
if(op=='^'){
int righta=(int)right
double lefta=left
if(righta>0){
for(int a=1a<rightaa++)
lefta*=left}
else if(righta==0)
lefta=1.000000
else{
righta=-righta
for(int a=1a<rightaa++)
lefta*=left
lefta=1/lefta}
return lefta
}
}
int you(char op)
{
if(op=='(')
return 0
if(op=='+'||op=='-')
return 1
if(op=='*'||op=='/'||op=='%')
return 2
if(op=='^')
return 3
}
int main(){
double last
char choice
int num1=0
while(true){
cout<<"请输入你要计算的表达式,并以‘=’号结束:\n"
do{
cin>>car
if(car!='=')
str+=car
if(car!='('&&car!=')'&&car!='+'&&car!='-'&&car!='*'&&car!='/'&&car!='%'&&car!='^'&&car!='='&&!isdigit(car)&&car!='.')
num1++
if(car=='=')
break
}while(car!='=')
if(num1==0){
str+="="
last=chuli(str)
cout<<"你输入的表达式是:"<<str<<endl
cout<<"运算结果是:"<<last<<endl}
else{
cout<<"你输入的表达式不符合规则!\n"
num1=0}
cout<<"'y'继续,'n'退出"<<endl
cin>>choice
str=""
if(choice=='n')break
}
system("pause")
return 0
}
double chuli(string stra)
{
string strb=""double dou
for(int a=0a<stra.length()a++){//1
if(isdigit(stra[a])||stra[a]=='.'){//1.1
strb+=stra[a]
if(!isdigit(stra[a+1])&&stra[a+1]!='.'){//1.1.1
dou=atof(strb.c_str())
opnd.push(dou)
strb=""}//1.1.1
}//1.1
if(stra[a]=='+'|| stra[a]=='-'||stra[a]=='*'||stra[a]=='/'||stra[a]=='%'||stra[a]=='^'){//1.2
if(a==0){//1.2.1
opnd.push(0)
optr.push(str[a])}//1.2.1
else if(stra[a-1]=='('){//1.2.4
opnd.push(0)
optr.push(str[a])}//1.2.4
else if(optr.empty()){
optr.push(stra[a])
}
else if(you(stra[a])>you(optr.top())){//1.2.2
optr.push(stra[a])
}//1.2.2
else if(you(stra[a])<=you(optr.top())){//1.2.3
while(!optr.empty()&&you(stra[a])<=you(optr.top())&&optr.top()!='('){
double left,right
right=opnd.top()
opnd.pop()
left=opnd.top()
opnd.pop()
opnd.push(count(left,optr.top(),right))
optr.pop()}
optr.push(stra[a])
}//1.2.3
}//1.2
if(stra[a]==')'&&optr.top()=='('){//1.3
optr.pop()
}//1.3
if(stra[a]==')'&&optr.top()!='('){//1.6
while(optr.top()!='('){//1.6.1
double left,right
right=opnd.top()
opnd.pop()
left=opnd.top()
opnd.pop()
opnd.push(count(left,optr.top(),right))
optr.pop()}//1.6.1
optr.pop()
}//1.6
if(stra[a]=='('){//1.4
optr.push('(')
}//1.4
if(stra[a]=='='){//1.5
while(!optr.empty()){//1.5.1
double left,right
right=opnd.top()
opnd.pop()
left=opnd.top()
opnd.pop()
opnd.push(count(left,optr.top(),right))
optr.pop()}//1.5.1
}//1.5
}//1
return opnd.top()
}
count=0for(fen1=1fen1<100fen1++)
for(fen2=1fen2<50fen2++)
for(fen5=1fen5<20fen5++)
if(fen1+fen2*2+fen5*5==money)
{count++
printf("fen5:%d,fen2:%d,fen1:%d,total:%d\n",fen5, fen2, fen1, fen5+fen2+fen1)
}
我已经调试过了,正确,其实做这类题不要自己用数学方法算,用循环比较简单,希望你能理解!