帮帮忙
#include<iostream>
#include<ctime>
#include<stdlib>
#include<cmath>
using namespace std;
class Ceshi
{ private:
int num,right,corse;
float a[20],b[20];
public:
Ceshi(int n){num=n};
void Chuti(int m);
int Defen();
void Zhicuo();
};
void Ceshi::Chuti(int m)
{ int i,a,b,c;
char f;
i=m;
srand(time(0));
a=rand()%100,b=rand()%100;
c=rand()%4;
switch(c)
{case 0 :f='+'; a[i]=a+b;break;
case 1 : f='-'; a[i]=a-b;break;
case 2 : f='*'; a[i]=a*b; break;
case 3 : f='/';a[i]=a/b;break;
}
cout<<i<<":"<<a<<f<<b<<"=";
cin>>b[i];
cout<<endl;
}
int Ceshi::Defen()
{ for(int j=0;j<num;j++)
if (a[j]==b[j])
right++;
corse=right*5;
cout<<"你作对"<<right<<"题"<<"得分为:"<<corse<<endl;
}
void Ceshi::Zhicuo()
{for(int j=0;j<num;j++)
if(a[j]!=b[j])
cout<<"第"<<j<<"题错误"<<"正确答案为:"<<a[j]<<endl;
}
void main()
{ int n,m;
cout<<"本测试每题五分";
cout<<"Please input the number of questions";
cin>>n;
Ceshi a1(n);
for(m=0;m<n;m++)
a1.Chuti(m);
a1.Defen();
a1.Zhicuo();
}
错误
--------------------Configuration: 测试 - Win32 Debug--------------------
Compiling...
测试.cpp
G:\新建文件夹 (2)\测试.cpp(3) : fatal error C1083: Cannot open include file: 'stdlib': No such file or directory
Error executing cl.exe.
测试.obj - 1 error(s), 0 warning(s)
二
#include<iostream.h>
#include<time.h>
#include<stdlib.h>
class Ceshi
{ private:
int num,right,corse;
float a[20],b[20];
public:
Ceshi(int n){num=n};
void Chuti(int m);
int Defen();
void Zhicuo();
};
void Ceshi::Chuti(int m)
{ int i,a,b,c;
char f;
i=m;
srand(time(0));
a=rand()%100,b=rand()%100;
c=rand()%4;
switch(c)
{case 0:f='+'; a[i]=a+b;break;
case 1: f='-'; a[i]=a-b;break;
case 2: f='*'; a[i]=a*b; break;
case 3: f='/';a[i]=a/b;break;
}
cout<<i<<":"<<a<<f<<b<<"=";
cin>>b[i];
cout<<endl;
}
int Ceshi::Defen()
{ for(int j=0;j<num;j++)
if (a[j]==b[j])
right++;
corse=right*5;
cout<<"你作对"<<right<<"题"<<"得分为:"<<corse<<endl;
}
void Ceshi::Zhicuo()
{for(int j=0;j<num;j++)
if(a[j]!=b[j])
cout<<"第"<<j<<"题错误"<<"正确答案为:"<<a[j]<<endl;
}
void main()
{ int n,m;
cout<<"本测试每题五分";
cout<<"Please input the number of questions";
cin>>n;
Ceshi a1(n);
for(m=0;m<n;m++)
a1.Chuti(m);
a1.Defen();
a1.Zhicuo();
}
错误
--------------------Configuration: 21 - Win32 Debug--------------------
Compiling...
21.cpp
c:\documents and settings\jsjx\桌面\新建文件夹\21.cpp(5) : error C2018: unknown character '0xa3'
c:\documents and settings\jsjx\桌面\新建文件夹\21.cpp(5) : error C2018: unknown character '0xba'
c:\documents and settings\jsjx\桌面\新建文件夹\21.cpp(6) : error C2320: expected ':' to follow access specifier 'type'
c:\documents and settings\jsjx\桌面\新建文件夹\21.cpp(22) : error C2109: subscript requires array or pointer type
c:\documents and settings\jsjx\桌面\新建文件夹\21.cpp(22) : error C2106: '=' : left operand must be l-value
c:\documents and settings\jsjx\桌面\新建文件夹\21.cpp(23) : error C2109: subscript requires array or pointer type
c:\documents and settings\jsjx\桌面\新建文件夹\21.cpp(23) : error C2106: '=' : left operand must be l-value
c:\documents and settings\jsjx\桌面\新建文件夹\21.cpp(24) : error C2109: subscript requires array or pointer type
c:\documents and settings\jsjx\桌面\新建文件夹\21.cpp(24) : error C2106: '=' : left operand must be l-value
c:\documents and settings\jsjx\桌面\新建文件夹\21.cpp(25) : error C2109: subscript requires array or pointer type
c:\documents and settings\jsjx\桌面\新建文件夹\21.cpp(25) : error C2106: '=' : left operand must be l-value
c:\documents and settings\jsjx\桌面\新建文件夹\21.cpp(28) : error C2109: subscript requires array or pointer type
c:\documents and settings\jsjx\桌面\新建文件夹\21.cpp(28) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'int' (or there is no acceptable conversion)
c:\documents and settings\jsjx\桌面\新建文件夹\21.cpp(49) : error C2018: unknown character '0xa3'
c:\documents and settings\jsjx\桌面\新建文件夹\21.cpp(49) : error C2018: unknown character '0xbb'
c:\documents and settings\jsjx\桌面\新建文件夹\21.cpp(49) : error C2146: syntax error : missing ';' before identifier 'm'
Error executing cl.exe.
21.obj - 16 error(s), 0 warning(s)