第1个回答 2008-12-24
class sailboat
{
public:
void Set(char* szName ,int iLen , char* szCreateName ,int iLen2 , int iWidth , int iHeight ,int iDeep )
{
memncpy( m_szName , szName , iLen);
memncpy( m_szCreateName , szCreateName , iLen2);
m_iWidth = iWidth;
m_iDeep = iDeep;
m_iHeight = iHeight;
}
void WriteInfo()
{
printf("%s , %s , %d , %d , %d " , m_szName ,m_szCreateName ,m_iWidth , m_iHeight , m_iDeep);
}
bool operator> ( const sailboat& s)
{
if ( m_iHeight > s.m_iHeight )
return true;
else if ( m_iHeight == s.m_iHeight )
{
if ( m_iWidth > s.m_iWidth )
return true;
else
return false;
}
else
return false ;
}
private:
char m_szName[20];
char m_szCreateName[20];
int m_iHeight;
int m_iWidth ;
int m_iDeep;
};
第2个回答 2008-12-24
#include <iostream>
#include <cstdlib>
using namespace std;
const int NAME_LENGTH=20;
class sailBoat
{
public:
void set()
{
scanf("%s%s%d%d",m_name,m_creator,&m_lenth,&m_width,&m_depth);
}
void Writeinfo()
{
printf("%s , %s , %d , %d , %d " , m_name ,m_creator , m_lenth,m_width , m_depth);
}
bool operator> ( const sailBoat& s)
{
if ( m_lenth> s.m_lenth)
return true;
else if ( m_lenth== s.m_lenth)
{
if ( m_width > s.m_width )
return true;
}
return false ;
}
private:
char m_name[NAME_LENGTH+1];
char m_creator[NAME_LENGTH+1];
int m_lenth;
int m_width ;
int m_depth;
};
int cmp(const void *a,const void *b)
{
return *(sailBoat*)a>*(sailBoat*)b;
}
int main()
{
sailBoat s[5];
int i;
for(i=0;i<5;i++)
s[i].set();
qsort(s,5,sizeof(sailBoat),cmp);
for(i=0;i<5;i++)
s[i].Writeinfo();
return 0;
}