------------------------------------------------
student.h
------------------------------------------------

class student
{
public:
 static int count;
protected:
 int ID;
 char Name[10];
public:
 int score;
 student();
 student(char *pname);
 ~student();
 virtual void dumpname()=0;
 int read_id();
};

class IMstudent: public student
{
public:
 IMstudent(char *pname);
 int cpp_score;
 void read_cpp();
 void dumpname();
};

------------------------------------------------


------------------------------------------------
student.cpp
------------------------------------------------

#include "stdafx.h"
#include "student.h"
#include "string.h"
#include "iostream"

using namespace std;
int student::count = 0;
student::student()
{
 count++;
 ID = count;
 score = 0;
}

student::student(char *pname)
{
 count++;
 ID = count;
 score = 0;
 strcpy(Name, pname);
}

int student::read_id()
{
 return(ID);
}

student::~student()
{
 count--;
}

IMstudent::IMstudent(char *pname)
{
 cpp_score = 90;
 strcpy(Name, pname);
}

void IMstudent::dumpname()
{
 cout << "#" << Name << "#";
}

------------------------------------------------


------------------------------------------------
awei.cpp
------------------------------------------------

// awei.cpp : 定義主控台應用程式的進入點。
//

#include "stdafx.h"
#include "student.h"
#include "string.h"

int _tmain(int argc, _TCHAR* argv[])
{
 IMstudent *c;
 c = new IMstudent("AweiGood");
 printf("%d\n", student::count);
 printf("%d\n", c ->cpp_score);
 c->dumpname();
 delete c;
 return 0;
}

------------------------------------------------

AwEi 發表在 痞客邦 PIXNET 留言(0) 人氣()