#include
class Stu
{
char *name;
double score;
public :
void Set(char *na,double s);
void Show();
~Stu();
friend int date(Stu &s1,Stu &s2,Stu &s3,Stu &s4,Stu &s5);
};
Stu::Set (char *na,double s)
{
score=s;
name=new char[strlen(na)+1];
strcpy(name,na);
}
Stu::Show ()
{
cout<<"name:"<
}
Stu::~Stu ()
{
delete []name;
}
int date(Stu &s1,Stu &s2,Stu &s3,Stu &s4,Stu &s5);
{
int a[5]={s1.score,s2.score,s3.score,s4.score,s5.score};
int i,j,t;
for(i=0;i
for(j=0;j
if(a[j]>a[j+1])
{ t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
for(i=0;i<5;i++)
cout<<a[i]<<endl;
}
int main()
{
Stu s1,s2,s3,s4,s5;
s1.Set ("zhang",78);
s1.Show ();
s2.Set ("wang",89);
s2.Show ();
s3.Set ("zhao",92);
s3.Show ();
s4.Set ("li",65);
s4.Show ();
s5.Set ("chen",50);
s5.Show ();
date(s1,s2,s3,s4,s5);
return 0;
}
作業\score\one.cpp(28) : error C2447: missing function header (old-style formal list?)
C:\作業\score\one.cpp(44) : error C2264: 'Set' : error in function definition or declaration; function not called
C:\作業\score\one.cpp(45) : error C2264: 'Show' : error in function definition or declaration; function not called
C:\作業\score\one.cpp(46) : error C2264: 'Set' : error in function definition or declaration; function not called
C:\作業\score\one.cpp(47) : error C2264: 'Show' : error in function definition or declaration; function not called
C:\作業\score\one.cpp(48) : error C2264: 'Set' : error in function definition or declaration; function not called
C:\作業\score\one.cpp(49) : error C2264: 'Show' : error in function definition or declaration; function not called
C:\作業\score\one.cpp(50) : error C2264: 'Set' : error in function definition or declaration; function not called
C:\作業\score\one.cpp(51) : error C2264: 'Show' : error in function definition or declaration; function not called
C:\作業\score\one.cpp(52) : error C2264: 'Set' : error in function definition or declaration; function not called
C:\作業\score\one.cpp(53) : error C2264: 'Show' : error in function definition or declaration; function not called
執行 cl.exe 時出錯.
Set和Show函數要加上函數的類型,比如void,改成:
void Stu::Set (char *na,double s) 和void Stu::Show ()
int date(Stu &s1,Stu &s2,Stu &s3,Stu &s4,Stu &s5)後面多了一個分號
Show函數裡cout<<"name:"< }是什麼鬼?要用cout的話包含頭文件iostream,std::cout或者using namespace std;