鱼C论坛

 找回密码
 立即注册
查看: 2604|回复: 5

[已解决]头文件与源文件(有点急,明天要交)

[复制链接]
发表于 2018-5-5 22:56:38 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
//一个教学系统至少有学生和教师两种人,假设教师的数据有教师编号、姓名、年龄、性别、职称和系别,
//学生的数据有学号姓名、年龄、性别、班级和语文、数学、英语三门课程的成绩。编程完成学生和教师档案数据的输入和显示。
//要求:设计三个类Person、Teacher、Student,Person是Teacher和Student的基类,具有此二类共有的数据成员姓名、年龄、性别,并具有输入
//和显示这些数据的成员函数;Teacher类继承了Person类的功能,并增加对教师编号、职称和系别等数据成员进行输入和显示的成员函数;按同样
//的方法完善Student类的设计


三个头文件都通过编译了,但是最后的源文件里好像引用头文件出了点问题,我也不太清楚

#ifndef Person_h
#define Person_h
#include <string>
#include <iostream>
using namespace std;
class  Person{
        protected:
                string name;
                int age; string sex;  //共有的成员:年龄,性别,姓名
        public:
                Person(string n,int AGE,char m);
                Person(){};
                string getName() { return name; };
                int getAGE() { return age; };
                string getSEX() { return sex; };
                void setAGE(int a) { age = a; };
                void show(){
                        cout << "名字:" << getName() << endl;
                        cout << "年龄:" << getAGE()  << endl;
                        cout << "性别:" << getSEX()  << endl;
                }
};
#endif

#include "Person.h"
#ifdef Teacher_h
#define Teacher_h
#include <iostream>
#include <string>
using namespace std;
class Teacher:public Person{
        protected:
                int numbering;
                string jobtitle,xibie;
        public:
                Teacher(string n,int AGE,string m,int bh;string j,string x); //名字、年龄、性别、编号、职称、系别
                Teacher(){};
                string getJob() { return jobtitle; };
                int getNUM() { return numbering; };
                string getXB() { return xibie; };
                void setNUM(int a) { numbering = a; };
                void show(){
                        cout << "该名教师的情况如下:"<< endl;
                        Person::show();
                        cout << "编号:" << getNUM() << endl;
                        cout << "职称:" << getJob() <<endl;
                        cout << "系别:" << getXB()  <<endl;
                }                       
};
#endif

#include "Person.h"
#ifdef Student_h
#define Student_h
#include <iostream>
#include <string>
using namespace std;
class Student:public Person{
        protected:
                string class;
                int Chinese,Math,English;
        public:
                Student(string n,int AGE,string m,string c,int C,int M,int E); //名字、年龄、性别、语文、数学、英语
                Student(){};
                string getclass() { return class; };
                int getCHI() { return Chinese; };
                int getMAT() { return Math; };
                int getEng() { return English; };
                void setCHI(int a) { Chinese = a; };
                void setMAT(int a) { Math = a };
                void setENG(int a) { English = a};
                void show(){
                        cout << "该名学生的情况如下:"<< endl;
                        Person::show();
                        cout << "语文成绩:" << getCHI() << endl;
                        cout << "数学成绩:" << getMAT() <<endl;
                        cout << "英语成绩:" << getENG()  <<endl;
                }                               
};
#endif


#include <iostream>
#include <string>
#include "Person.h"
#include "Teacher.h"
#include "Student.h"
using namespace std;
int main(){
        string Tname,Tsex,zc,xb;
        int Tage,Tnum,Sage,Schi,Smath,Seng;
        string Sname,Ssex,Sclass;
        cout << "请输入教师的姓名、年龄、性别、编号、职称以及系别:";
        cin >> Tname >> Tage >> Tsex >> Tnum >> zc >> xb ;
        cout << "请输入学生的姓名、年龄、性别、班级、语文、数学以及英语成绩:";
        cin >> Sname >> Sage >> Ssex >> Sclass >> Schi >> Smath >> Seng ;
        Teacher T1(Tname,Tage,Tsex,Tnum,zc,xb); //名字、年龄、性别、编号、职称、系别
        Student S1(Sname,Sage,Ssex,Sclass,Schi,Smath,Seng); //名字、年龄、性别、语文、数学、英语
        cout << endl;
        T1.show();
        cout << endl;
        S1.show();
        char anwser;
        cout << "do you want to continue ? ( Y or N)";
        cin >> anwser;
        if(anwser=='Y')
        {
                main();
        }
        else
        {
                return 0;
        }
}

最佳答案
2018-5-6 13:48:43
这个程序问题太多了

这是这四个代码存储的位置

这是这四个代码存储的位置

提示错误

提示错误
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2018-5-6 05:23:16 | 显示全部楼层
没人吗?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-5-6 05:25:28 | 显示全部楼层
没人吗?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-5-6 08:33:36 | 显示全部楼层
没有人吗?
或者哪位帮我写一个也行啊,如果看我的看地烦
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-5-6 11:42:29 | 显示全部楼层
自顶
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-5-6 13:48:43 | 显示全部楼层    本楼为最佳答案   
这个程序问题太多了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-17 11:32

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表