c++编程出错 error C2143: syntax error : missing ';' before 'public' 该怎么修改程序
#include<iostream.h>#include<stdio.h>enumbase//抽象类{protected:chartitle[80];public:voi...
#include<iostream.h>
#include<stdio.h>
enum base //抽象类
{
protected:
char title[80];
public:
void gettitle()
{
cout<<"书名:";cin>>title;
}
void printtitle()
{
cout<<"书名:"<<title<<":";
}
virtual boolean isgood()=0;
};
class Book : public base
{ int numsold;
public:
void getsold()
{
cout<<"每月销售书量:";cin>>numsold;
}
boolean isgood()
{
return (numsold>500) ? True:False;
}
};
class Journal:public base
{
int numsold;
public:
void getsold()
{
cout<<"每月销售杂志量:";cin>>numsold;
}
boolean isgood()
{
return (numsold>2500) ? True:False;
}
};
void main()
{
base *p[50]; //定义基类的指针数据
Book *pbook;
Journal *pjour;
char ch;
int count=0;
do //循环输入图书或者杂志的销售量
{
cout<<"输入书(b)或杂志(j):";
cin>>ch;
if (ch=='b')
{
pbook=new Book;
pbook->gettitle();
pbook->getsold();
p[count++]=pbook;
}
else if (ch=='j')
{
pjour=new Journal;
pjour->gettitle();
pjour->getsold();
p[count++]=pjour;
}
else
cout<<"输入错误"<<endl;
cout<<"输入另一项吗(y/n)?";
cin>>ch;
}while (ch=='y');
cout<<"\n输入结果:"<<endl;
for (int i=0;i<coount;i++) //循环查找,显示销售良好的图书或者杂志
{
if (p[i]->isgood()==True)
{
cout<<" ";
p[i]->printtitle();
cout<<"销售良好"<<endl;
}
}
}
显示错误
1.cpp
C:\Program Files (x86)\Microsoft Visual Studio\Common\MSDev98\Bin\1.cpp(5) : error C2059: syntax error : 'protected'
C:\Program Files (x86)\Microsoft Visual Studio\Common\MSDev98\Bin\1.cpp(7) : error C2143: syntax error : missing ';' before 'public'
C:\Program Files (x86)\Microsoft Visual Studio\Common\MSDev98\Bin\1.cpp(16) : error C2146: syntax error : missing ';' before identifier 'isgood'
C:\Program Files (x86)\Microsoft Visual Studio\Common\MSDev98\Bin\1.cpp(16) : error C2433: 'boolean' : 'virtual' not permitted on data declarations
C:\Program Files (x86)\Microsoft Visual Studio\Common\MSDev98\Bin\1.cpp(16) : error C2501: 'boolean' : missing storage-class or type specifiers
C:\Program Files (x86)\Microsoft Visual Studio\Common\MSDev98\Bin\1.cpp(16) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
1.exe - 6 error(s), 0 warning(s) 展开
#include<stdio.h>
enum base //抽象类
{
protected:
char title[80];
public:
void gettitle()
{
cout<<"书名:";cin>>title;
}
void printtitle()
{
cout<<"书名:"<<title<<":";
}
virtual boolean isgood()=0;
};
class Book : public base
{ int numsold;
public:
void getsold()
{
cout<<"每月销售书量:";cin>>numsold;
}
boolean isgood()
{
return (numsold>500) ? True:False;
}
};
class Journal:public base
{
int numsold;
public:
void getsold()
{
cout<<"每月销售杂志量:";cin>>numsold;
}
boolean isgood()
{
return (numsold>2500) ? True:False;
}
};
void main()
{
base *p[50]; //定义基类的指针数据
Book *pbook;
Journal *pjour;
char ch;
int count=0;
do //循环输入图书或者杂志的销售量
{
cout<<"输入书(b)或杂志(j):";
cin>>ch;
if (ch=='b')
{
pbook=new Book;
pbook->gettitle();
pbook->getsold();
p[count++]=pbook;
}
else if (ch=='j')
{
pjour=new Journal;
pjour->gettitle();
pjour->getsold();
p[count++]=pjour;
}
else
cout<<"输入错误"<<endl;
cout<<"输入另一项吗(y/n)?";
cin>>ch;
}while (ch=='y');
cout<<"\n输入结果:"<<endl;
for (int i=0;i<coount;i++) //循环查找,显示销售良好的图书或者杂志
{
if (p[i]->isgood()==True)
{
cout<<" ";
p[i]->printtitle();
cout<<"销售良好"<<endl;
}
}
}
显示错误
1.cpp
C:\Program Files (x86)\Microsoft Visual Studio\Common\MSDev98\Bin\1.cpp(5) : error C2059: syntax error : 'protected'
C:\Program Files (x86)\Microsoft Visual Studio\Common\MSDev98\Bin\1.cpp(7) : error C2143: syntax error : missing ';' before 'public'
C:\Program Files (x86)\Microsoft Visual Studio\Common\MSDev98\Bin\1.cpp(16) : error C2146: syntax error : missing ';' before identifier 'isgood'
C:\Program Files (x86)\Microsoft Visual Studio\Common\MSDev98\Bin\1.cpp(16) : error C2433: 'boolean' : 'virtual' not permitted on data declarations
C:\Program Files (x86)\Microsoft Visual Studio\Common\MSDev98\Bin\1.cpp(16) : error C2501: 'boolean' : missing storage-class or type specifiers
C:\Program Files (x86)\Microsoft Visual Studio\Common\MSDev98\Bin\1.cpp(16) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
1.exe - 6 error(s), 0 warning(s) 展开
展开全部
编译错误已修正,包括enum->class 前者是定义枚举类型的,不是类
boolean-> bool, c++没有前者那样的类型
True-> true,同上
False-> false,同上
coount-> count,拼写错误
;-> ; 需要用半角字符
#include<iostream.h>
#include<stdio.h>
class base //抽象类
{
protected:
char title[80];
public:
void gettitle()
{
cout<<"书名:";cin>>title;
}
void printtitle()
{
cout<<"书名:"<<title<<":";
}
virtual bool isgood()=0;
};
class Book : public base
{ int numsold;
public:
void getsold()
{
cout<<"每月销售书量:";cin>>numsold;
}
bool isgood()
{
return (numsold>500) ? true:false;
}
};
class Journal:public base
{
int numsold;
public:
void getsold()
{
cout<<"每月销售杂志量:";cin>>numsold;
}
bool isgood()
{
return (numsold>2500) ? true:false;
}
};
void main()
{
base *p[50]; //定义基类的指针数据
Book *pbook;
Journal *pjour;
char ch;
int count=0;
do //循环输入图书或者杂志的销售量
{
cout<<"输入书(b)或杂志(j):";
cin>>ch;
if (ch=='b')
{
pbook=new Book;
pbook->gettitle();
pbook->getsold();
p[count++]=pbook;
}
else if (ch=='j')
{
pjour=new Journal;
pjour->gettitle();
pjour->getsold();
p[count++]=pjour;
}
else
cout<<"输入错误"<<endl;
cout<<"输入另一项吗(y/n)?";
cin>>ch;
}while (ch=='y');
cout<<"\n输入结果:"<<endl;
for (int i=0;i<count;i++) //循环查找,显示销售良好的图书或者杂志
{
if (p[i]->isgood()==true)
{
cout<<" ";
p[i]->printtitle();
cout<<"销售良好"<<endl;
}
}
}
boolean-> bool, c++没有前者那样的类型
True-> true,同上
False-> false,同上
coount-> count,拼写错误
;-> ; 需要用半角字符
#include<iostream.h>
#include<stdio.h>
class base //抽象类
{
protected:
char title[80];
public:
void gettitle()
{
cout<<"书名:";cin>>title;
}
void printtitle()
{
cout<<"书名:"<<title<<":";
}
virtual bool isgood()=0;
};
class Book : public base
{ int numsold;
public:
void getsold()
{
cout<<"每月销售书量:";cin>>numsold;
}
bool isgood()
{
return (numsold>500) ? true:false;
}
};
class Journal:public base
{
int numsold;
public:
void getsold()
{
cout<<"每月销售杂志量:";cin>>numsold;
}
bool isgood()
{
return (numsold>2500) ? true:false;
}
};
void main()
{
base *p[50]; //定义基类的指针数据
Book *pbook;
Journal *pjour;
char ch;
int count=0;
do //循环输入图书或者杂志的销售量
{
cout<<"输入书(b)或杂志(j):";
cin>>ch;
if (ch=='b')
{
pbook=new Book;
pbook->gettitle();
pbook->getsold();
p[count++]=pbook;
}
else if (ch=='j')
{
pjour=new Journal;
pjour->gettitle();
pjour->getsold();
p[count++]=pjour;
}
else
cout<<"输入错误"<<endl;
cout<<"输入另一项吗(y/n)?";
cin>>ch;
}while (ch=='y');
cout<<"\n输入结果:"<<endl;
for (int i=0;i<count;i++) //循环查找,显示销售良好的图书或者杂志
{
if (p[i]->isgood()==true)
{
cout<<" ";
p[i]->printtitle();
cout<<"销售良好"<<endl;
}
}
}
2011-12-30
展开全部
#include<iostream.h>
#include<stdio.h>
class base //抽象类
{
protected:
char title[80];
public:
void gettitle()
{
cout<<"书名:";cin>>title;
}
void printtitle()
{
cout<<"书名:"<<title<<":";
}
virtual bool isgood()=0;
};
class Book : public base
{ int numsold;
public:
void getsold()
{
cout<<"每月销售书量:";cin>>numsold;
}
bool isgood()
{
return (numsold>500) ? true:false;
}
};
class Journal:public base
{
int numsold;
public:
void getsold()
{
cout<<"每月销售杂志量:";cin>>numsold;
}
bool isgood()
{
return (numsold>2500) ? true:false;
}
};
int main()
{
base *p[50]; //定义基类的指针数据
Book *pbook;
Journal *pjour;
char ch;
int count=0;
do //循环输入图书或者杂志的销售量
{
cout<<"输入书(b)或杂志(j):";
cin>>ch;
if (ch=='b')
{
pbook=new Book;
pbook->gettitle();
pbook->getsold();
p[count++]=pbook;
}
else if (ch=='j')
{
pjour=new Journal;
pjour->gettitle();
pjour->getsold();
p[count++]=pjour;
}
else
cout<<"输入错误"<<endl;
cout<<"输入另一项吗(y/n)?";
cin>>ch;
}while (ch=='y');
cout<<"\n输入结果:"<<endl;
for (int i=0;i<count;i++) //循环查找,显示销售良好的图书或者杂志
{
if (p[i]->isgood()==true)
{
cout<<" ";
p[i]->printtitle();
cout<<"销售良好"<<endl;
}
}
}
#include<stdio.h>
class base //抽象类
{
protected:
char title[80];
public:
void gettitle()
{
cout<<"书名:";cin>>title;
}
void printtitle()
{
cout<<"书名:"<<title<<":";
}
virtual bool isgood()=0;
};
class Book : public base
{ int numsold;
public:
void getsold()
{
cout<<"每月销售书量:";cin>>numsold;
}
bool isgood()
{
return (numsold>500) ? true:false;
}
};
class Journal:public base
{
int numsold;
public:
void getsold()
{
cout<<"每月销售杂志量:";cin>>numsold;
}
bool isgood()
{
return (numsold>2500) ? true:false;
}
};
int main()
{
base *p[50]; //定义基类的指针数据
Book *pbook;
Journal *pjour;
char ch;
int count=0;
do //循环输入图书或者杂志的销售量
{
cout<<"输入书(b)或杂志(j):";
cin>>ch;
if (ch=='b')
{
pbook=new Book;
pbook->gettitle();
pbook->getsold();
p[count++]=pbook;
}
else if (ch=='j')
{
pjour=new Journal;
pjour->gettitle();
pjour->getsold();
p[count++]=pjour;
}
else
cout<<"输入错误"<<endl;
cout<<"输入另一项吗(y/n)?";
cin>>ch;
}while (ch=='y');
cout<<"\n输入结果:"<<endl;
for (int i=0;i<count;i++) //循环查找,显示销售良好的图书或者杂志
{
if (p[i]->isgood()==true)
{
cout<<" ";
p[i]->printtitle();
cout<<"销售良好"<<endl;
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
第七行的public后面貌似是个分号,还是我孤陋寡闻了,我没见过是分号的语句结尾。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
//你错的地方很多,具体改了哪里我也不知道了,
//首先你的头文件iostream.h是C语言里的吗?
//然后你true为什么老是写成True,false也是一样的问题,还有就是bool老是写成booleam
//还有一个很重要的问题就是你有一个地方的分号写成了中文的
//cout<<"输入书(b)或杂志(j):";
// cin>>ch;
//是这个地方,你看到同有,这个问题是比较难发现的。
//还下面有一个地方count你写成了coount,我找到的就这些错误吧,其他的没了
//还有,把enum改成class,这个我不知道是什么原因啊,对C++里的类不是很懂,你自己看吧
#include<iostream>
#include<stdio.h>
using namespace std ;
//#include<iostream.h>
//#include<stdio.h>
class base //抽象类
{
protected:
char title[80];
public:
void gettitle()
{
cout<<"书名:";cin>>title;
}
void printtitle()
{
cout<<"书名:"<<title<<":";
}
virtual bool isgood()=0;
};
class Book : public base
{ int numsold;
public:
void getsold()
{
cout<<"每月销售书量:";cin>>numsold;
}
bool isgood()
{
return (numsold>500) ? true:false;
}
};
class Journal:public base
{
int numsold;
public:
void getsold()
{
cout<<"每月销售杂志量:";cin>>numsold;
}
bool isgood()
{
return (numsold>2500) ? true:false;
}
};
void main()
{
base *p[50]; //定义基类的指针数据
Book *pbook;
Journal *pjour;
char ch;
int count=0;
do //循环输入图书或者杂志的销售量
{
cout<<"输入书(b)或杂志(j):";
cin>>ch;
if (ch=='b')
{
pbook=new Book;
pbook->gettitle();
pbook->getsold();
p[count++]=pbook;
}
else if (ch=='j')
{
pjour=new Journal;
pjour->gettitle();
pjour->getsold();
p[count++]=pjour;
}
else
cout<<"输入错误"<<endl;
cout<<"输入另一项吗(y/n)?";
cin>>ch;
}while (ch=='y');
cout<<"\n输入结果:"<<endl;
for (int i=0;i<count;i++) //循环查找,显示销售良好的图书或者杂志
{
if (p[i]->isgood()==true)
{
cout<<" ";
p[i]->printtitle();
cout<<"销售良好"<<endl;
}
}
}
//首先你的头文件iostream.h是C语言里的吗?
//然后你true为什么老是写成True,false也是一样的问题,还有就是bool老是写成booleam
//还有一个很重要的问题就是你有一个地方的分号写成了中文的
//cout<<"输入书(b)或杂志(j):";
// cin>>ch;
//是这个地方,你看到同有,这个问题是比较难发现的。
//还下面有一个地方count你写成了coount,我找到的就这些错误吧,其他的没了
//还有,把enum改成class,这个我不知道是什么原因啊,对C++里的类不是很懂,你自己看吧
#include<iostream>
#include<stdio.h>
using namespace std ;
//#include<iostream.h>
//#include<stdio.h>
class base //抽象类
{
protected:
char title[80];
public:
void gettitle()
{
cout<<"书名:";cin>>title;
}
void printtitle()
{
cout<<"书名:"<<title<<":";
}
virtual bool isgood()=0;
};
class Book : public base
{ int numsold;
public:
void getsold()
{
cout<<"每月销售书量:";cin>>numsold;
}
bool isgood()
{
return (numsold>500) ? true:false;
}
};
class Journal:public base
{
int numsold;
public:
void getsold()
{
cout<<"每月销售杂志量:";cin>>numsold;
}
bool isgood()
{
return (numsold>2500) ? true:false;
}
};
void main()
{
base *p[50]; //定义基类的指针数据
Book *pbook;
Journal *pjour;
char ch;
int count=0;
do //循环输入图书或者杂志的销售量
{
cout<<"输入书(b)或杂志(j):";
cin>>ch;
if (ch=='b')
{
pbook=new Book;
pbook->gettitle();
pbook->getsold();
p[count++]=pbook;
}
else if (ch=='j')
{
pjour=new Journal;
pjour->gettitle();
pjour->getsold();
p[count++]=pjour;
}
else
cout<<"输入错误"<<endl;
cout<<"输入另一项吗(y/n)?";
cin>>ch;
}while (ch=='y');
cout<<"\n输入结果:"<<endl;
for (int i=0;i<count;i++) //循环查找,显示销售良好的图书或者杂志
{
if (p[i]->isgood()==true)
{
cout<<" ";
p[i]->printtitle();
cout<<"销售良好"<<endl;
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询