?? 派生 教師.txt
字號(hào):
include <iostream.h>
#include <string.h>
#define MAX_NAME_LENGTH 20
class Person
{
public:
Person(int i_Number, char* i_pName):m_nNumber(i_Number){ i_pName == NULL? memset(m_pName,'\0',MAX_NAME_LENGTH):strlen(i_pName)>MAX_NAME_LENGTH ? memcpy(m_pName, i_pName, MAX_NAME_LENGTH) : strcpy(m_pName, i_pName);}
const char* GetName() const {return m_pName;}
int GetNumber() const {return m_nNumber;}
void SetName( const char* i_pName );
void SetNumber( int i_Number ) {m_nNumber = i_Number;};
protected:
int m_nNumber;
char m_pName[MAX_NAME_LENGTH];
};
void Person::SetName( const char* i_pName )
{
if (i_pName == NULL)
return;
strlen(i_pName)>MAX_NAME_LENGTH ? memcpy(m_pName, i_pName, MAX_NAME_LENGTH) : strcpy(m_pName, i_pName);
}
class student:public Person
{
public:
student(int i_mark, int i_Number, char* i_pName ):m_nMark(i_mark), Person(i_Number, i_pName){}
student():m_nMark(0),Person(0,NULL){};
int GetMark() const { return m_nMark; }
void SetMark( int i_mark ) { m_nMark = i_mark; }
friend ostream& operator<< ( ostream& os, student& i_student );
friend istream& operator >> ( istream& is, student& i_student );
private:
int m_nMark;
};
ostream& operator<< ( ostream& os, student& i_student )
{
os<<"The Student Infomation:"<<endl;
os<<"Name:"<<i_student.GetName()<<endl;
os<<"Number:"<<i_student.GetNumber()<<endl;
os<<"Marks:"<<i_student.GetMark()<<endl;
return os;
}
istream& operator >> ( istream& is, student& i_student )
{
char lpc_Name[MAX_NAME_LENGTH] = {0};
int li_Number = 0, li_mark = 0;
cout<<"Input Student's Information"<<endl;
cout<<"Name:"<<endl;
is >> lpc_Name;
i_student.SetName(lpc_Name);
cout<<"Number:"<<endl;
is >> li_Number;
i_student.SetNumber(li_Number);
cout <<"Marks"<<endl;
is >> li_mark;
i_student.SetMark( li_mark );
return is;
}
void main()
{
student Example;
cout << Example;
cin >> Example;
cout <<Example;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -