帮帮忙

IsFast 2011-12-05 03:05:06
#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)






...全文
126 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuegeman 2011-12-05
  • 打赏
  • 举报
回复
#include<iostream>

#include<ctime>
#include<cstdlib>
#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);
void 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='+'; Ceshi::a[i]=a+b;break; //作用域
case 1 : f='-'; Ceshi::a[i]=a-b;break;
case 2 : f='*'; Ceshi::a[i]=a*b; break;
case 3 : f='/'; Ceshi::a[i]=a/b;break;
}
cout<<i<<":"<<a<<f<<b<<"=";
cin>>Ceshi::b[i];
cout<<endl;
}
void Ceshi::Defen() //无返回值 不要int
{
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();
}

//一个字 乱 没报错了 具体输出还有点问题 自己找
cplusplux 2011-12-05
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 dahuaixiaohuai 的回复:]
一、#include<stdlib.h>
二、代码里有中文或是全角的字符
[/Quote]
就是这种情况
无事所所 2011-12-05
  • 打赏
  • 举报
回复
C++统一规范 cstdlib 而不是stdlib,最好也别用stdlib.h.那是给C的
标点符号你用的中文标点吧?
一叶之舟 2011-12-05
  • 打赏
  • 举报
回复
一、#include<stdlib.h>
二、代码里有中文或是全角的字符

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧