| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3225 人关注过本帖
标题:求助急看了一下午也找不到错误
只看楼主 加入收藏
黑色金合欢
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2016-6-10
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
求助急看了一下午也找不到错误
#include<iostream.h>
#include<string.h>
class people
{
protected:
    int age;
    char name[20];
public:
    people(char *n,int a):age(a)
    {
        strcpy(name,n);
    }
    void print()
    {
        cout<<"The name of the people is:"<<name<<endl<<"The age of the people is:"<<age<<endl<<endl;
    }
};
class student:public virtual people
{
protected:
    char classno[7];
public:
    student(char *n,int a,char *c):people(n,a)
    {
        strcpy(classno,c);
    }
    void print()
    {
        cout<<"The name of the student is :"<<name<<endl<<"The age of the student is:"<<age<<endl;
        cout<<"The classno of the student is :"<<classno<<endl<<endl;
    }
};
class techer:public virtual people
{
protected:
    char principalship[11];
    char department[21];
public:
    techer(char *n,int a,char *p,char *d):people(n,a)
    {
        strcpy(principalship,p);
        strcpy(department,d);
    }
    void print()
    {
        cout<<"The name of the techer is :"<<name<<endl<<"The age of the techer is:"<<age<<endl;
        cout<<"The principalship of the techer is:"<<principalship<<endl;
        cout<<"The deparcipalship of the thcher is:"<<department<<endl<<endl;
    }
};
class graduate:virtual public student
{
protected:
    char subject[21];
    techer adviser;
public:
    graduate(char *n,int a,char *c,char *s,techer t):people(n,a),student(n,a,c),adviser(t)
    {
        strcpy(subject,s);
    }
    void print()
    {
        cout<<"The name of the graduate is:"<<name<<endl<<"The age of the gratuate is:"<<age<<endl;
        cout<<"The calssno of the graduate is:"<<classno<<endl;
        cout<<"The subject of the graduate is:"<<subject<<endl;
        cout<<"The techer adviser of the graduate is:";
        adviser.print();
    }
};
class TA: public graduate, public techer
{
public:
    TA(char *n,int a,char *s,techer t,char *p,char *d,char *c):people(n,a),student(n,a,c),techer(n,a,p,d),graduate(n,a,c,s,t){}
    void print()
    {
        cout<<"The name of the TA is:"<<name<<endl<<"The age of TA is:"<<age<<endl;
        cout<<"The calssno of the TA is:"<<classno<<endl;
        cout<<"The subject of the TA is:"<<subject<<endl;
        cout<<"The techer adviser of the TA is:";
        adviser.print();
        cout<<"The principalship of the techer is:"<<principalship<<endl;
        cout<<"The deparcipalship of the thcher is:"<<department<<endl<<endl<<endl;
    }
};
void main()
{
    char n[20],int a;char classnumber[10];char department[21];
    char principalship[11];char subject[10];
    cout<<"输入姓名:"<<endl;
    cin>>n;
    cout<<"输入年龄:"<<endl;
    cin>>a;
    people f(n,a);
    f.print();
    cout<<"输入学生姓名:"<<endl;
    cin>>n;
    cout<<"输入学生年龄:"<<endl;
    cin>>a;
    cout<<"输入学生班级:"<<endl;
    cin>>classnumber;
    student b(n,a,classnumber);
    b.print();
    cout<<"输入姓名:"<<endl;
    cin>>n;
    cout<<"输入教师年龄:"<<endl;
    cin>>a;
    cout<<"输入教师职务:"<<endl;
    cin>>principalship;
    cout<<"输入教师部门"<<endl;
    cin>>department;
    techer c(n,a,principalship,department);
    c.print();
    cout<<"输入研究生姓名:"<<endl;
    cin>>n;
    cout<<"输入研究生年龄:"<<endl;
    cin>>a;
    cout<<"输入学生班级:"<<endl;
    cin>>classnumber;
    cout<<"研究生专业"<<endl;
    cin>>subject;
    graduate d(n,a,classnumber,subject,c);
    d.print();
    cout<<"输入助教姓名:"<<endl;
    cin>>n;
    cout<<"输入助教年龄:"<<endl;
    cin>>a;
    cout<<"输入助教班级:"<<endl;
    cin>>classnumber;
    cout<<"助教专业"<<endl;
    cin>>subject;
    TA e(n,a,subject,c,principalship,department,classnumber);
    e.print();

}
[code][code][code][code][local]1[/local]
[/code][/code][/code][/code]


QQ截图20160610162704.png (9.08 KB)
图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: include public people 
2016-06-10 16:27
wengbin
Rank: 10Rank: 10Rank: 10
来 自:陕西西安
等 级:贵宾
威 望:19
帖 子:370
专家分:1846
注 册:2015-5-8
收藏
得分:10 
程序代码:
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
class people
{
protected:
    int age;
    char name[20];
public:
    people(char *n, int a) :age(a)
    {
        strcpy(name, n);
    }
    void print()
    {
        cout << "The name of the people is:" << name << endl << "The age of the people is:" << age << endl << endl;
    }
};
class student :public virtual people
{
protected:
    char classno[7];
public:
    student(char *n, int a, char *c) :people(n, a)
    {
        strcpy(classno, c);
    }
    void print()
    {
        cout << "The name of the student is :" << name << endl << "The age of the student is:" << age << endl;
        cout << "The classno of the student is :" << classno << endl << endl;
    }
};
class techer :public virtual people
{
protected:
    char principalship[11];
    char department[21];
public:
    techer(char *n, int a, char *p, char *d) :people(n, a)
    {
        strcpy(principalship, p);
        strcpy(department, d);
    }
    void print()
    {
        cout << "The name of the techer is :" << name << endl << "The age of the techer is:" << age << endl;
        cout << "The principalship of the techer is:" << principalship << endl;
        cout << "The deparcipalship of the thcher is:" << department << endl << endl;
    }
};
class graduate :virtual public student
{
protected:
    char subject[21];
    techer adviser;
public:
    graduate(char *n, int a, char *c, char *s, techer t) :people(n, a), student(n, a, c), adviser(t)
    {
        strcpy(subject, s);
    }
    void print()
    {
        cout << "The name of the graduate is:" << name << endl << "The age of the gratuate is:" << age << endl;
        cout << "The calssno of the graduate is:" << classno << endl;
        cout << "The subject of the graduate is:" << subject << endl;
        cout << "The techer adviser of the graduate is:";
        adviser.print();
    }
};
class TA : public graduate, public techer
{
public:
    TA(char *n, int a, char *s, techer t, char *p, char *d, char *c) :people(n, a), student(n, a, c), techer(n, a, p, d), graduate(n, a, c, s, t){}
    void print()
    {
        cout << "The name of the TA is:" << name << endl << "The age of TA is:" << age << endl;
        cout << "The calssno of the TA is:" << classno << endl;
        cout << "The subject of the TA is:" << subject << endl;
        cout << "The techer adviser of the TA is:";
        adviser.print();
        cout << "The principalship of the techer is:" << principalship << endl;
        cout << "The deparcipalship of the thcher is:" << department << endl << endl << endl;
    }
};

int main()//C++中主函数不能是void型
{
    char n[20];//这里原来结尾的是,不是;编译通不过,看编译错误提示的信息,立马能找到的
    int a; 
    char classnumber[10]; 
    char department[21];
    char principalship[11]; 
    char subject[10];
    cout << "输入姓名:" << endl;
    cin >> n;
    cout << "输入年龄:" << endl;
    cin >> a;
    people f(n, a);
    f.print();
    cout << "输入学生姓名:" << endl;
    cin >> n;
    cout << "输入学生年龄:" << endl;
    cin >> a;
    cout << "输入学生班级:" << endl;
    cin >> classnumber;
    student b(n, a, classnumber);
    b.print();
    cout << "输入姓名:" << endl;
    cin >> n;
    cout << "输入教师年龄:" << endl;
    cin >> a;
    cout << "输入教师职务:" << endl;
    cin >> principalship;
    cout << "输入教师部门" << endl;
    cin >> department;
    techer c(n, a, principalship, department);
    c.print();
    cout << "输入研究生姓名:" << endl;
    cin >> n;
    cout << "输入研究生年龄:" << endl;
    cin >> a;
    cout << "输入学生班级:" << endl;
    cin >> classnumber;
    cout << "研究生专业" << endl;
    cin >> subject;
    graduate d(n, a, classnumber, subject, c);
    d.print();
    cout << "输入助教姓名:" << endl;
    cin >> n;
    cout << "输入助教年龄:" << endl;
    cin >> a;
    cout << "输入助教班级:" << endl;
    cin >> classnumber;
    cout << "助教专业" << endl;
    cin >> subject;
    TA e(n, a, subject, c, principalship, department, classnumber);
    e.print();
    return 0;
}
2016-06-10 22:54
yangfrancis
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:贵宾
威 望:141
帖 子:1510
专家分:7661
注 册:2014-5-19
收藏
得分:10 
回复 楼主 黑色金合欢
咋会冒出来个“发送到”?
2016-06-11 16:19
wengbin
Rank: 10Rank: 10Rank: 10
来 自:陕西西安
等 级:贵宾
威 望:19
帖 子:370
专家分:1846
注 册:2015-5-8
收藏
得分:0 
回复 3楼 yangfrancis
他输入了名字“发送到”呀
2016-06-11 16:37
快速回复:求助急看了一下午也找不到错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021500 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved