首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

帮忙找异常,多谢!()

2012-02-04 
帮忙找错误,谢谢!(在线等)一个程序,有错误,但不知道在哪,哪位看看//student.h#ifndefSTUDENT#defineSTUDEN

帮忙找错误,谢谢!(在线等)
一个程序,有错误,但不知道在哪,哪位看看
//student.h
#ifndef   STUDENT
#define   STUDENT

#include   <iostream>
#include   <iomanip>
#include   <string>

using   namespace   std;

class   Student
{
public:
//Student(){++i;}
//~Student(){--i;}

int   total();
int   average();
char   grade();

friend   ostream&operator   < <(ostream&,Student&);
friend   istream&operator   > > (istream&,Student&);

private:
//static   int   i;
string   name;
int   num,C,VB,Computer;
};

//static   int   Student::i   =   0;

int   Student::total()
{
return   C+VB+Computer;
}

int   Student::average()
{
return   total()/3;
}

char   Student::grade()
{
int   t   =   average();

if(t> =90&&t <=100)
return   'A ';
else   if(t> =80&&t <90)
return   'B ';
else   if(t> =70&&t <80)
return   'C ';
else   if(t> =60&&t <70)
return   'D ';
else
cout < < "Worng   or   It 's   too   bad. " < <endl;
}

ostream&   operator < <(ostream&   out,Student&   st)
{
out   < <setw(6) < <st.num
        < <setw(10) < <st.name
        < <setw(3) < <st.C
        < <setw(11) < <st.VB
        < <setw(8) < <st.Computer;
return   out;
}

istream&   operator> > (istream&   in,Student&   st)
{
in   > > setw(6)> > st.num
      > > setw(10)> > st.name
      > > setw(3)> > st.C
      > > setw(11)> > st.VB
      > > setw(8)> > st.Computer;
     
return   in;
}

#endif


//student.cpp

#include   <iostream>
#include   "student.h "

using   namespace   std;

void   sort(Student   s[],int   n);
void   main()
{
const   int   n=6;
Student   s[n];

cout < < "Input   Type " < <endl;
cout   < <   "number "   < <   "name "   < < "C " < < "Visual   Basic " < < "Computer " < <endl;
for(int   i=0;i <7;++i)
{
cin> > s[i]> > '\n ';
}

cout < < "*************************************** " < <endl;
cout < < "Output     Type " < <endl;
cout   < <   "number "   < <   "name "   < < "C " < < "Visual   Basic " < < "Computer " < < "Total " < < "Average " < < "grades " < <endl;
sort(s,n);
for(int   i=0;i <7;++i)
{
cout < <s[i] < <setw(5) < <s[i].total() < <setw(7) < <s[i].average() < <setw(6) < <s[i].grade() < <endl;


}

}


void   sort(Student   s[],int   n)
{
for(int   i=0;i <n;i++)
for(int   j=n;j> =0;j--)
{
if(s[j].average()> s[j+1].average())
std::swap(s[j],s[j+1]);
}
}




[解决办法]
for(int i=0;i <7;++i)
{
cin> > s[i]> > '\n ';
}====================
for(int i=0;i <7;++i)
{
cin> > s[i];
}
就可以了..
[解决办法]
for(int i=0;i <7;++i)
{
cin> > s[i]; //这里
}

cout < < "*************************************** " < <endl;
cout < < "Output Type " < <endl;
cout < < "number " < < "name " < < "C " < < "Visual Basic " < < "Computer " < < "Total " < < "Average " < < "grades " < <endl;
sort(s,n);
for(i=0;i <7;++i) //这里int去掉 VC6.0的问题
{
cout < <s[i] < <setw(5) < <s[i].total() < <setw(7) < <s[i].average() < <setw(6) < <s[i].grade() < <endl;
}

}

热点排行