类的对象

来源:互联网 发布:水产养殖生产日志数据 编辑:程序博客网 时间:2024/06/06 05:52

#include<iostream>
using namespace std;
class Student{
private:
 string strName;
 unsigned long nIndex;
 int nScore;
public:
 Student()//析构函数
 {
  strName="Unknown";nIndex=0;nScore=0;
  cout<<"Constructedwith an unknow student."<<endl;
 }
 Student(string strNameNew,unsigned longnIndexNew,int nScoreNew)//析构函数
 {
       strName=strNameNew;nIndex=nIndexNew;nScore=nScoreNew;
  cout<<"Stringconstructor has beencalled."<<endl;
 }
   Student(char*pStrName,unsigned long nIndexNew,int nScoreNew)//析构函数
   {
     strName=pStrName;nIndex=nIndexNew;nScore=nScoreNew;
  cout<<"String constructor has beencalled."<<endl;
   }
   string GetName(){returnstrName;}
   unsigned longGetIndex(){return nIndex;}
   int GetScore(){returnnScore;}
   void SetName(stringstrNameNew) {strName=strNameNew;}
   void SetIndex(unsigned longnIndexNew)  {nIndex=nIndexNew;}
   void SetScore(intnScoreNew)  {nScore=nScoreNew;}
};
int main()
{
 Student student1;
 Student student2("Marry",1,100);
 string strName="Susun";
 Student student3(strName,2,90);
 return 0;

}类的对象

0 0
原创粉丝点击