資源簡介
c++例程:類的簡單應用,關于建立一個學生信息系統(tǒng)
代碼片段和文件信息
#include?
#include?
using?namespace?std;
class?student
{
private:
//學號、姓名、性別、專業(yè)、
//班級、年級、住址、電話
char?stuNo[10];
char?stuName[20];
char?stuSex[4];
char?stuZy[10];
char?stuClass[5];
char?stuGrade[6];
char?stuAdress[20];
char?stuPhone[12];
static?int?stu_Number?;//在這里只是相當于聲明
public:
student();
student(student?&stu);
student(char?No[]?char?name[]);
~student();
void?input();//信息的輸入
void?output();//信息的輸出
static?void?output_wholeNum();
};
int?student::stu_Number?=?0;?//在類的外部需要定義而且加上類域訪問符初始化也通常同時進行
student::student(student?&stu)
{
stu_Number++;
strcpy(stuNo?stu.stuNo);
strcpy(stuName?stu.stuName);
}
student::student()
{
stu_Number++;
cout<<“請輸入學號:“;?? cin>>stuNo;
cout<<“請輸入姓名:“; cin>>stuName;
}
student::student(
評論
共有 條評論