#include
#include
using namespace std;
class STUDENT{
private:
unsigned long ID;
char name[10];
float score;
public:
STUDENT(unsigned long ,float,char*);
~STUDENT(void);
unsigned long getid();
char getname();
float getscore();
};
STUDENT::STUDENT(unsigned long id,float s,char*n)
:ID(id),score(s)
{
strcpy(name,n);
}
STUDENT::~STUDENT()
{}
unsigned long STUDENT::getid()
{
return ID;
}
float STUDENT::getscore()
{
return score;
}
char STUDENT::getname()
{
return *name;
}
void main()
{
STUDENT *st[5];
int i;
unsigned long id;
float s,max;
char n[10];
for(i=0;i<5;i++)
{
cout<<"请输入第"< cin>>id;
cout<<"请输入第"< cin>>n;
cout<<"请输入第"< cin>>s;
cout< st[i]=new STUDENT(id,s,n);
}
max=st[0]->getscore();
for(i=1;i<5;i++)
if(st[i]->getscore()>max)
max=st[i]->getscore();
for(i=0;i<5;i++)
if(st[i]->getscore()==max)
cout<<"你输入的最高分为"
<getname()<<"同学"
<getid()
<getscore()<}
--------------------next---------------------
#include
#include
#include
using namespace std;
class student
{
private:
unsigned long ID;
char name[10];
float score;
public:
student (unsigned long ,float,char*);
~student(void);
unsigned long getid();
char getname();
float getscore();
};
student::student(unsigned long id,float s,char*n)
:ID(id),score(s)
{
strcpy(name,n);
}
student::~student(){}
unsigned long student::getid()
{
return ID;
}
float student::getscore()
{
return score;
}
char student::getname()
{
return *name;
}
int main()
{
student *st[5];
int i;
unsigned long id;
float s,max;
char n[10];
for(i=0;i<5;i++)
{
cout<<"请输入第"< cin>>id;
cout<<"请输入第"< cin>>n;
cout<<"请输入第"< cin>>s;
cout< st[i]=new student(id,s,n);
}
max=st[0]->getscore();
for(i=1;i<5;i++)
if(st[i]->getscore()>max)
max=st[i]->getscore();
for(i=0;i<5;i++)
if(st[i]->getscore()==max)
cout<<"你输入的最高分为"
<getname()<<"同学"
<getid()
<getscore()< system("pause");
return 0 ;
}
我觉得标准的应该是这样的吧,在C++ 中主函数返回值是int 而不是void, 而且按照楼上写的我没有找到最大值啊 ,呵呵,很抱歉啊
--------------------next---------------------
阅读(1235) | 评论(0) | 转发(0) |