.cj 2015-11-30 09:19 采纳率: 100%
浏览 1419

关于面向对象中类的问题

定义一个学生类,其中有3个数据成员有学号、姓名、年龄,以及若干成员函数。同时编写主函数使用这个类,实现对学生数据的赋值和输出。并利用这个类建立一个对象数组,内放5个学生的数据,利用指针输出第1,3,5个学生的数据。 要求:使用构造函数和析构函数实现对数据的输入、输出。在头文件student.h中完成类的定义,在student.cpp中完成类的实现,在_tmain().cpp中完成主函数编写。

  • 写回答

1条回答 默认 最新

  • JinJie_Zhang 2015-11-30 09:26
    关注
     #include<iostream.h>
    #include<string.h>
    class student{
        private:
            int intID;
            char charNAME[8];
            short shoAGE;
        public:
            student(int,char *,short);
            ~student();
            void show();
            int getID();
            void getNAME();
            short getAGE();
            void setID(int);
            void setNAME(char *);
            void setAGE(short);
    };
    student::student(int ID,char * NAME,short AGE){
        intID=ID;
        strcpy(charNAME,NAME);
        shoAGE=AGE;
        cout<<"建立了一个学生对象 序列号:"<<intID<<endl;
    };
    student::~student(){
        cout<<"删除了一个学生对象"<<intID<<endl;
    };
    void student::show(){
        cout<<"序列号"<<intID<<"姓名"<<charNAME<<"年龄"<<shoAGE<<endl;
    }
    int student::getID(){
        return intID;
    };
    void student::getNAME(){
        cout<<charNAME<<endl;
    };
    short student::getAGE(){
        return shoAGE;
    };
        void student::setID(int ID){
            intID = ID;
    };
        void student::setNAME(char *NAME){
            strcpy(charNAME,NAME);
    };
        void student::setAGE(short AGE){
            shoAGE=AGE;
    };
        void main(){
            student a(4,"ww",22);
            a.show();
            a.setID(20030133);
            a.setNAME("张三");
            a.setAGE(22);
            cout<<"学号"<<a.getID()<<endl;
            a.getNAME();
            cout<<"年龄"<<a.getAGE()<<endl;
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿