64,666
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
using namespace std;
class Student{
public:
Student(char *pName="no name", int ssld=0, int dmark=0.0)
{
strncpy(name,pName,40);
id=ssld;
mark=dmark;
}
void SetMark(int imark) { mark=imark; }
void SetID (int iid) { id=iid; }
void SetName(char* cName) { strncpy(name,cName, 40); }
int GetMark() const { return mark;}
char* GetName() { return name;}
void print() const
{
cout<<"Name: "<<name<<endl;
cout<<"ID: "<<id<<endl;
cout<<"Mark: "<<mark<<endl;
}
~Student()
{
}
protected:
char name[40];
int mark;
int id;
};
int GetHighMarkBetwen2(const Student& s1, const Student& s2)
{
if( s1.GetMark()>=s2.GetMark() )
return s1.GetMark();
else
return s2.GetMark();
}
char* GetHighNameBetwen2(Student& s1, Student& s2)
{
if( s1.GetMark()>=s2.GetMark() )
return s1.GetName();
else
return s2.GetName();
}
void main()
{
Student s1("Me", 1, 2), s2("You", 2,5), s3;
cout<<GetHighMarkBetwen2(s1,s2)<<endl;
cout<<GetHighNameBetwen2(s1, s2)<<endl;
cout<<endl;
s1.print();
s2.print();
s3.print();
s3.SetName("She");
s3.print();
}