ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

one

2022-04-15 09:34:08  阅读:138  来源: 互联网

标签: Disp Name int char Tbirth Student


// Name.h
class Name  
{
public:
    Name(char*);
    Name(Name&);
    virtual ~Name();
    void Disp();
protected:
    char *pname;

};
// Tbirth.h
class Tbirth  
{
public:
    Tbirth();
    Tbirth(int ,int);
    Tbirth(int);
    void Disp();
protected:
    int month;
    int year;

};
// Student.h

//#include"Name.h"
//#include"Tbirth.h"
class Student  
{
public:
    Student();
    Student(char*);
    Student(char*,int,int,int);
    Student(Student&);
    ~Student();
    void Disp();
    static int Getnumber();
protected:
    Name name;
    Tbirth birth;
    int age;
    static int number;
};

// Name.cpp

//#include "Name.h"
#include<cstring>
#include<iostream>
using namespace std;
Name::Name(char *a)
{
    pname=new char[strlen(a)+1];
    strcpy(pname,a);
}
Name::Name(Name &n)
{
    pname=new char[strlen(n.pname)+1];
    strcpy(pname,n.pname);
}
void Name::Disp()
{
    cout<<pname<<endl;
}
Name::~Name()
{
    delete []pname;
}

// Tbirth.cpp


//#include "Tbirth.h"
//#include<iostream>
//using namespace std;
Tbirth::Tbirth()
{
    year=2022;
    month=4;
}
Tbirth::Tbirth(int a,int b)
{
    year=a;
    month=b;
}
Tbirth::Tbirth(int a)
{
    year=a;
    month=1;
}
void Tbirth::Disp()
{
    cout<<month<<'/'<<year<<endl;
}

// Student.cpp

//#include "Student.h"
//#include<iostream>
//using namespace std;
int Student::number=0;
Student::Student():name("noname"),birth(2001,12)
{
    age=20;
    number++;
}
Student::Student(char *a):name(a),birth(2002,6)
{
    age=19;
    number++;
}
Student::Student(char *a1,int a2,int a3,int a4):name(a1),birth(a2,a3)
{
    age=a4;
    number++;
}
Student::Student(Student &s):name(s.name),birth(s.birth)
{
    age=s.age;
    number++;
}
Student::~Student()
{
    number--;
}
int Student::Getnumber()
{
    return number;
}
void Student::Disp()
{
    name.Disp();
    birth.Disp();
    cout<<age<<endl;
}

//main.cpp

//#include"student.h"
//#include<iostream>
//using namespace std;
void DispStudedntNum()  //随时可以被调用以显示学生人数
{
    cout<<Student::Getnumber()<<endl;; //自行填上所缺代码
}
void fn(Student s)
{
    s.Disp();
    DispStudedntNum();
}
int main()
{
    Tbirth birth1,birth2(1980);
    birth1.Disp();
    birth2.Disp();
    DispStudedntNum();
    char name1[10],name2[10];
    int y,m,age;
    cin>>name1;
    cin>>name2>>y>>m>>age;
    Student s1, s2(name1), s3(name2,y,m,age); 
    DispStudedntNum();
    s1.Disp();
    s2.Disp();
    s3.Disp();
    fn(s3);
    DispStudedntNum();
    return 0;
}
// Name.h
class Name  
{
public:
    Name(char*);
    Name(Name&);
    virtual ~Name();
    void Disp();
protected:
    char *pname;

};
// Tbirth.h
class Tbirth  
{
public:
    Tbirth();
    Tbirth(int ,int);
    Tbirth(int);
    void Disp();
protected:
    int month;
    int year;

};
// Student.h

//#include"Name.h"
//#include"Tbirth.h"
class Student  
{
public:
    Student();
    Student(char*);
    Student(char*,int,int,int);
    Student(Student&);
    ~Student();
    void Disp();
    static int Getnumber();
protected:
    Name name;
    Tbirth birth;
    int age;
    static int number;
};

// Name.cpp

//#include "Name.h"
#include<cstring>
#include<iostream>
using namespace std;
Name::Name(char *a)
{
    pname=new char[strlen(a)+1];
    strcpy(pname,a);
}
Name::Name(Name &n)
{
    pname=new char[strlen(n.pname)+1];
    strcpy(pname,n.pname);
}
void Name::Disp()
{
    cout<<pname<<endl;
}
Name::~Name()
{
    delete []pname;
}

// Tbirth.cpp


//#include "Tbirth.h"
//#include<iostream>
//using namespace std;
Tbirth::Tbirth()
{
    year=2022;
    month=4;
}
Tbirth::Tbirth(int a,int b)
{
    year=a;
    month=b;
}
Tbirth::Tbirth(int a)
{
    year=a;
    month=1;
}
void Tbirth::Disp()
{
    cout<<month<<'/'<<year<<endl;
}

// Student.cpp

//#include "Student.h"
//#include<iostream>
//using namespace std;
int Student::number=0;
Student::Student():name("noname"),birth(2001,12)
{
    age=20;
    number++;
}
Student::Student(char *a):name(a),birth(2002,6)
{
    age=19;
    number++;
}
Student::Student(char *a1,int a2,int a3,int a4):name(a1),birth(a2,a3)
{
    age=a4;
    number++;
}
Student::Student(Student &s):name(s.name),birth(s.birth)
{
    age=s.age;
    number++;
}
Student::~Student()
{
    number--;
}
int Student::Getnumber()
{
    return number;
}
void Student::Disp()
{
    name.Disp();
    birth.Disp();
    cout<<age<<endl;
}

//main.cpp

//#include"student.h"
//#include<iostream>
//using namespace std;
void DispStudedntNum()  //随时可以被调用以显示学生人数
{
    cout<<Student::Getnumber()<<endl;; //自行填上所缺代码
}
void fn(Student s)
{
    s.Disp();
    DispStudedntNum();
}
int main()
{
    Tbirth birth1,birth2(1980);
    birth1.Disp();
    birth2.Disp();
    DispStudedntNum();
    char name1[10],name2[10];
    int y,m,age;
    cin>>name1;
    cin>>name2>>y>>m>>age;
    Student s1, s2(name1), s3(name2,y,m,age); 
    DispStudedntNum();
    s1.Disp();
    s2.Disp();
    s3.Disp();
    fn(s3);
    DispStudedntNum();
    return 0;
}

 

标签:,Disp,Name,int,char,Tbirth,Student
来源: https://www.cnblogs.com/niushaoshuai/p/16147551.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有