#include<iostream.h>
#include<stdio.h>
template <class Ta,class Tb,class Tc>
Ta temp(const Ta &Cfist,const Tc &Cschar,const Tb &Clast)
{
Ta first=Cfist;
Tb last=Clast;
Tc fC=Cschar;
switch(fC)
{
case '+' :cout<< (ffisst+flast);
break;
case '-':cout<<(ffisst-flast);
break;
case '/' :cout<< (ffisst/flast);
break;
case '*' :cout<< (ffisst*flast);
break;
default : cout<<"Error!!!schar!!"<<endl;
}
}
int main()
{
int first;
int last;
char schar;
cout<<"Please input :"<<endl;
cout<<"first=";
cin>>first;
cout<<endl;
cout<<"schar=";
cin>>schar;
cout<<endl;
cout<<"last=";
cin>>last;
cout<<endl;
cout<<"The resurlt is:"<<first<<scahr<<last<<"="<<temp(first,schar,last)<<endl;
return 0;
}
已调试过,可一用了,以后多交流啊,
* a,b为随机两数?c为随机数,由c得出随机运算符,d为运算符的表示
*/
#include "stdio.h"
#include "conio.h"
main()
{
int a,b,c,e,f;
char d;
a=rand();
b=rand();
c=rand();
printf("a=%d,b=%d\n",a,b);
switch (c%4){
case 0:d='+'; e=a+b;break;
case 1:d='-'; e=a-b;break;
case 2:d='*'; e=a*b;break;
case 3:d='/'; e=a/b;break;
}
do {
printf("c=a%cb=",d);
scanf("%d",&f);
if(e!=f) printf("error\n");
}while(e!=f);
printf("You are right!");
getch();
}
就是这个,你看看吧!很简单的啊!