C++,哪里出错了?出错提示:fatal error C1004: unexpected end of file found
#include<iostream>#include<cstring>usingnamespacestd;classPerson{public:virtualvoidpr...
#include<iostream>
#include<cstring>
using namespace std;
class Person{
public:
virtual void print();
virtual void input();
virtual void getpay()=0;
protected:
char name[20];
int number;
int age;
char sex;
float salary;
};
class Boss:public Person{
public:
void input()
{cout<<"请输入老板的姓名:";cin>>name;
cout<<"请输入编号:";cin>>number;
cout<<"请输入年龄:";cin>>age;
cout<<"请输入性别:";cin>>sex;
cout<<"请输入年薪:";cin>>salary;
};
virtual void print()
{cout<<"姓名"<<"\t\t\t"<<"编号"<<"\t\t\t"<<"年龄"<<"\t\t\t"<<"性别"<<endl;
cout<<name<<"\t\t\t\t"<<number<<"\t\t\t"<<age<<"\t\t\t\t"<<sex<<endl; };
void getpay(){
cout<<"老板的工资为%f,salary"<<endl;};
class Employee:public Person{
public:
void input()
{cout<<"请输入雇员的姓名:";cin>>name;
cout<<"请输入编号:";cin>>number;
cout<<"请输入年龄:";cin>>age;
cout<<"请输入性别:";cin>>sex;
cout<<"请输入年薪:";cin>>salary;
};
void print()
{cout<<"姓名"<<"\t\t\t"<<"编号"<<"\t\t\t"<<"年龄"<<"\t\t\t"<<"性别"<<endl;
cout<<name<<"\t\t\t\t"<<number<<"\t\t\t"<<age<<"\t\t\t\t"<<sex<<endl; };
void getpay(){
cout<<"雇员的工资为%f,salary"<<endl;};
};
class Hourlyworker:public Person{
public:
void input()
{cout<<"请输入小时工的姓名:";cin>>name;
cout<<"请输入编号:";cin>>number;
cout<<"请输入年龄:";cin>>age;
cout<<"请输入性别:";cin>>sex;
cout<<"请输入年薪:";cin>>salary;
};
void print()
{cout<<"姓名"<<"\t\t\t"<<"编号"<<"\t\t\t"<<"年龄"<<"\t\t\t"<<"性别"<<endl;
cout<<name<<"\t\t\t\t"<<number<<"\t\t\t"<<age<<"\t\t\t\t"<<sex<<endl; };
void getpay(){
cout<<"小时工的工资为%f,salary"<<endl;};
};
class Commworker:public Person{
public:
void input()
{cout<<"请输入营销员的姓名:";cin>>name;
cout<<"请输入编号:";cin>>number;
cout<<"请输入年龄:";cin>>age;
cout<<"请输入性别:";cin>>sex;
cout<<"请输入年薪:";cin>>salary;
};
void print()
{cout<<"姓名"<<"\t\t\t"<<"编号"<<"\t\t\t"<<"年龄"<<"\t\t\t"<<"性别"<<endl;
cout<<name<<"\t\t\t\t"<<number<<"\t\t\t"<<age<<"\t\t\t\t"<<sex<<endl; };
void getpay(){
cout<<"营销员的工资为%f,salary"<<endl;};
};
int main(){
int n;
Person *p;
Boss b;
Employee e;
Hourlyworker h;
Commworker c;
cout<<"请选择职业类型:"<<endl;
cout<<"1.老板"<<" "<<"2.雇员"<<" "<<"3.小时工"<<" "<<"4.营销人员"<<endl;
cout<<"请输入职业类型对应的数字:";
cin>>n;
cout<<endl;
switch(n)
{case 1:{*p=&b;
*p->input();
*p->print();
*p->getpay();
}break;
case 2:{*p=&e;
*p->input();
*p->print();
*p->getpay();}break;
case 3:{*p=&h;
*p->input();
*p->print();
*p->getpay();}break;
case 4:{*p=&c;
*p->input();
*p->print();
*p->getpay();}break;
default:cout<<"你的输入有误!"<<endl;
}
return 0;
} 展开
#include<cstring>
using namespace std;
class Person{
public:
virtual void print();
virtual void input();
virtual void getpay()=0;
protected:
char name[20];
int number;
int age;
char sex;
float salary;
};
class Boss:public Person{
public:
void input()
{cout<<"请输入老板的姓名:";cin>>name;
cout<<"请输入编号:";cin>>number;
cout<<"请输入年龄:";cin>>age;
cout<<"请输入性别:";cin>>sex;
cout<<"请输入年薪:";cin>>salary;
};
virtual void print()
{cout<<"姓名"<<"\t\t\t"<<"编号"<<"\t\t\t"<<"年龄"<<"\t\t\t"<<"性别"<<endl;
cout<<name<<"\t\t\t\t"<<number<<"\t\t\t"<<age<<"\t\t\t\t"<<sex<<endl; };
void getpay(){
cout<<"老板的工资为%f,salary"<<endl;};
class Employee:public Person{
public:
void input()
{cout<<"请输入雇员的姓名:";cin>>name;
cout<<"请输入编号:";cin>>number;
cout<<"请输入年龄:";cin>>age;
cout<<"请输入性别:";cin>>sex;
cout<<"请输入年薪:";cin>>salary;
};
void print()
{cout<<"姓名"<<"\t\t\t"<<"编号"<<"\t\t\t"<<"年龄"<<"\t\t\t"<<"性别"<<endl;
cout<<name<<"\t\t\t\t"<<number<<"\t\t\t"<<age<<"\t\t\t\t"<<sex<<endl; };
void getpay(){
cout<<"雇员的工资为%f,salary"<<endl;};
};
class Hourlyworker:public Person{
public:
void input()
{cout<<"请输入小时工的姓名:";cin>>name;
cout<<"请输入编号:";cin>>number;
cout<<"请输入年龄:";cin>>age;
cout<<"请输入性别:";cin>>sex;
cout<<"请输入年薪:";cin>>salary;
};
void print()
{cout<<"姓名"<<"\t\t\t"<<"编号"<<"\t\t\t"<<"年龄"<<"\t\t\t"<<"性别"<<endl;
cout<<name<<"\t\t\t\t"<<number<<"\t\t\t"<<age<<"\t\t\t\t"<<sex<<endl; };
void getpay(){
cout<<"小时工的工资为%f,salary"<<endl;};
};
class Commworker:public Person{
public:
void input()
{cout<<"请输入营销员的姓名:";cin>>name;
cout<<"请输入编号:";cin>>number;
cout<<"请输入年龄:";cin>>age;
cout<<"请输入性别:";cin>>sex;
cout<<"请输入年薪:";cin>>salary;
};
void print()
{cout<<"姓名"<<"\t\t\t"<<"编号"<<"\t\t\t"<<"年龄"<<"\t\t\t"<<"性别"<<endl;
cout<<name<<"\t\t\t\t"<<number<<"\t\t\t"<<age<<"\t\t\t\t"<<sex<<endl; };
void getpay(){
cout<<"营销员的工资为%f,salary"<<endl;};
};
int main(){
int n;
Person *p;
Boss b;
Employee e;
Hourlyworker h;
Commworker c;
cout<<"请选择职业类型:"<<endl;
cout<<"1.老板"<<" "<<"2.雇员"<<" "<<"3.小时工"<<" "<<"4.营销人员"<<endl;
cout<<"请输入职业类型对应的数字:";
cin>>n;
cout<<endl;
switch(n)
{case 1:{*p=&b;
*p->input();
*p->print();
*p->getpay();
}break;
case 2:{*p=&e;
*p->input();
*p->print();
*p->getpay();}break;
case 3:{*p=&h;
*p->input();
*p->print();
*p->getpay();}break;
case 4:{*p=&c;
*p->input();
*p->print();
*p->getpay();}break;
default:cout<<"你的输入有误!"<<endl;
}
return 0;
} 展开
3个回答
推荐于2016-07-05
展开全部
逻辑错误我不管,语法错误有三个,第零个是person类纯虚函数写错了,第一个是Boss类少了个反大括号,第二个是主函数里既然对指针取内容了,就不要用箭头访问,所以去掉前面的星号。我给你注释了。你贴的那个语法错误一看就知道是括号写错了,还有你的排版太难看了。
#include<iostream>
#include<cstring>
using namespace std;
class Person
{
public:
virtual void print() = 0;//纯虚函数 =0不能省略
virtual void input() = 0;
virtual void getpay()=0;
protected:
char name[20];
int number;
int age;
char sex;
float salary;
};
class Boss:public Person
{
public:
void input()
{
cout<<"请输入老板的姓名:";cin>>name;
cout<<"请输入编号:";cin>>number;
cout<<"请输入年龄:";cin>>age;
cout<<"请输入性别:";cin>>sex;
cout<<"请输入年薪:";cin>>salary;
};
virtual void print()
{
cout<<"姓名"<<"\t\t\t"<<"编号"<<"\t\t\t"<<"年龄"<<"\t\t\t"<<"性别"<<endl;
cout<<name<<"\t\t\t\t"<<number<<"\t\t\t"<<age<<"\t\t\t\t"<<sex<<endl;
};
void getpay()
{
cout<<"老板的工资为%f,salary"<<endl;
};
};//---------------少了个反括号
class Employee:public Person{
public:
void input()
{
cout<<"请输入雇员的姓名:";cin>>name;
cout<<"请输入编号:";cin>>number;
cout<<"请输入年龄:";cin>>age;
cout<<"请输入性别:";cin>>sex;
cout<<"请输入年薪:";cin>>salary;
};
void print()
{
cout<<"姓名"<<"\t\t\t"<<"编号"<<"\t\t\t"<<"年龄"<<"\t\t\t"<<"性别"<<endl;
cout<<name<<"\t\t\t\t"<<number<<"\t\t\t"<<age<<"\t\t\t\t"<<sex<<endl;
};
void getpay()
{
cout<<"雇员的工资为%f,salary"<<endl;
};
};
class Hourlyworker:public Person{
public:
void input()
{cout<<"请输入小时工的姓名:";cin>>name;
cout<<"请输入编号:";cin>>number;
cout<<"请输入年龄:";cin>>age;
cout<<"请输入性别:";cin>>sex;
cout<<"请输入年薪:";cin>>salary;
};
void print()
{cout<<"姓名"<<"\t\t\t"<<"编号"<<"\t\t\t"<<"年龄"<<"\t\t\t"<<"性别"<<endl;
cout<<name<<"\t\t\t\t"<<number<<"\t\t\t"<<age<<"\t\t\t\t"<<sex<<endl; };
void getpay(){
cout<<"小时工的工资为%f,salary"<<endl;};
};
class Commworker:public Person{
public:
void input()
{cout<<"请输入营销员的姓名:";cin>>name;
cout<<"请输入编号:";cin>>number;
cout<<"请输入年龄:";cin>>age;
cout<<"请输入性别:";cin>>sex;
cout<<"请输入年薪:";cin>>salary;
};
void print()
{cout<<"姓名"<<"\t\t\t"<<"编号"<<"\t\t\t"<<"年龄"<<"\t\t\t"<<"性别"<<endl;
cout<<name<<"\t\t\t\t"<<number<<"\t\t\t"<<age<<"\t\t\t\t"<<sex<<endl; };
void getpay(){
cout<<"营销员的工资为%f,salary"<<endl;};
};
int main(){
int n;
Person *p;
Boss b;
Employee e;
Hourlyworker h;
Commworker c;
cout<<"请选择职业类型:"<<endl;
cout<<"1.老板"<<" "<<"2.雇员"<<" "<<"3.小时工"<<" "<<"4.营销人员"<<endl;
cout<<"请输入职业类型对应的数字:";
cin>>n;
cout<<endl;
switch(n)
{
case 1:{
p=&b;//-------------------用指针前面就不要加*
p->input();//-------------------用指针前面就不要加*
p->print();//-------------------用指针前面就不要加*
p->getpay();//-------------------用指针前面就不要加*
}break;
case 2:{p=&e;//-------------------用指针前面就不要加*
p->input();//-------------------用指针前面就不要加*
p->print();//-------------------用指针前面就不要加*
p->getpay();}break;
case 3:{p=&h;//-------------------下同
p->input();
p->print();
p->getpay();}break;
case 4:{p=&c;
p->input();
p->print();
p->getpay();}break;
default:cout<<"你的输入有误!"<<endl;
}
return 0;
}
#include<iostream>
#include<cstring>
using namespace std;
class Person
{
public:
virtual void print() = 0;//纯虚函数 =0不能省略
virtual void input() = 0;
virtual void getpay()=0;
protected:
char name[20];
int number;
int age;
char sex;
float salary;
};
class Boss:public Person
{
public:
void input()
{
cout<<"请输入老板的姓名:";cin>>name;
cout<<"请输入编号:";cin>>number;
cout<<"请输入年龄:";cin>>age;
cout<<"请输入性别:";cin>>sex;
cout<<"请输入年薪:";cin>>salary;
};
virtual void print()
{
cout<<"姓名"<<"\t\t\t"<<"编号"<<"\t\t\t"<<"年龄"<<"\t\t\t"<<"性别"<<endl;
cout<<name<<"\t\t\t\t"<<number<<"\t\t\t"<<age<<"\t\t\t\t"<<sex<<endl;
};
void getpay()
{
cout<<"老板的工资为%f,salary"<<endl;
};
};//---------------少了个反括号
class Employee:public Person{
public:
void input()
{
cout<<"请输入雇员的姓名:";cin>>name;
cout<<"请输入编号:";cin>>number;
cout<<"请输入年龄:";cin>>age;
cout<<"请输入性别:";cin>>sex;
cout<<"请输入年薪:";cin>>salary;
};
void print()
{
cout<<"姓名"<<"\t\t\t"<<"编号"<<"\t\t\t"<<"年龄"<<"\t\t\t"<<"性别"<<endl;
cout<<name<<"\t\t\t\t"<<number<<"\t\t\t"<<age<<"\t\t\t\t"<<sex<<endl;
};
void getpay()
{
cout<<"雇员的工资为%f,salary"<<endl;
};
};
class Hourlyworker:public Person{
public:
void input()
{cout<<"请输入小时工的姓名:";cin>>name;
cout<<"请输入编号:";cin>>number;
cout<<"请输入年龄:";cin>>age;
cout<<"请输入性别:";cin>>sex;
cout<<"请输入年薪:";cin>>salary;
};
void print()
{cout<<"姓名"<<"\t\t\t"<<"编号"<<"\t\t\t"<<"年龄"<<"\t\t\t"<<"性别"<<endl;
cout<<name<<"\t\t\t\t"<<number<<"\t\t\t"<<age<<"\t\t\t\t"<<sex<<endl; };
void getpay(){
cout<<"小时工的工资为%f,salary"<<endl;};
};
class Commworker:public Person{
public:
void input()
{cout<<"请输入营销员的姓名:";cin>>name;
cout<<"请输入编号:";cin>>number;
cout<<"请输入年龄:";cin>>age;
cout<<"请输入性别:";cin>>sex;
cout<<"请输入年薪:";cin>>salary;
};
void print()
{cout<<"姓名"<<"\t\t\t"<<"编号"<<"\t\t\t"<<"年龄"<<"\t\t\t"<<"性别"<<endl;
cout<<name<<"\t\t\t\t"<<number<<"\t\t\t"<<age<<"\t\t\t\t"<<sex<<endl; };
void getpay(){
cout<<"营销员的工资为%f,salary"<<endl;};
};
int main(){
int n;
Person *p;
Boss b;
Employee e;
Hourlyworker h;
Commworker c;
cout<<"请选择职业类型:"<<endl;
cout<<"1.老板"<<" "<<"2.雇员"<<" "<<"3.小时工"<<" "<<"4.营销人员"<<endl;
cout<<"请输入职业类型对应的数字:";
cin>>n;
cout<<endl;
switch(n)
{
case 1:{
p=&b;//-------------------用指针前面就不要加*
p->input();//-------------------用指针前面就不要加*
p->print();//-------------------用指针前面就不要加*
p->getpay();//-------------------用指针前面就不要加*
}break;
case 2:{p=&e;//-------------------用指针前面就不要加*
p->input();//-------------------用指针前面就不要加*
p->print();//-------------------用指针前面就不要加*
p->getpay();}break;
case 3:{p=&h;//-------------------下同
p->input();
p->print();
p->getpay();}break;
case 4:{p=&c;
p->input();
p->print();
p->getpay();}break;
default:cout<<"你的输入有误!"<<endl;
}
return 0;
}
2012-11-06
展开全部
你的老板类 class boss 少了个结束的大括号;
然后,你的main里面,使用了Person *p,下面在使用指针时不需要再加*了,直接使用
p = &b;
p->input();
这样的形式
然后,你的main里面,使用了Person *p,下面在使用指针时不需要再加*了,直接使用
p = &b;
p->input();
这样的形式
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这种错误一般是因为大括号不匹配引起的,建议把格式排版一下,好好检查括号是否匹配。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询