讨论 / C++新手,一遍AC,求指点析构函数应该写什么,怎么释放空间
18844561135 2018-02-20 13:27:50
点我顶贴 收藏 删除
#include<iostream>

using namespace std;

class student

{

public:

student();

void data_in();

void data_out();

int scholarship();

~student();

private:

char name[20];

int grade1;

int grade2;

bool bgb;

bool west;

int text;

int sch;

};

int main()

{

int num,all=0,i,maxnum=0,themax=0,thesch=0;

student *p[100];

cin>>num;

for(i=0;i<num;i++)

{

p[i]=new student;

thesch=(p[i]->scholarship());

if(themax<thesch)

{

themax=thesch;

maxnum=i;

}

all+=thesch;

}

p[maxnum]->data_out();

cout<<all;

return 0;

}

student::student()

{

sch=0;

data_in();

if(grade1>80&&text>=1) sch+=8000;

if(grade1>85&&grade2>80) sch+=4000;

if(grade1>90) sch+=2000;

if(grade1>85&&west) sch+=1000;

if(grade2>80&&bgb) sch+=850;

}

void student::data_in()

{

char in;

cin>>name>>grade1>>grade2;

cin>>in;

if(in=='Y') bgb=true;

else bgb=false;

cin>>in;

if(in=='Y') west=true;

else west=false;

cin>>text;

}

void student::data_out()

{

cout<<name<<endl<<sch<<endl;

}

int student::scholarship()

{

return sch;

}

student::~student()

{

;

}

查看更多回复
提交回复