C++类的程序

来源:百度知道 编辑:UC知道 时间:2024/07/04 01:55:41
各位大侠麻烦帮我编下这个题目,我自己也已经编了,但是很多错误。所以想看看正确的。谢谢谢
编写一个类以及相关的函数,来为选这门课的学生生成学生成绩。假设成绩只于期中和期末成绩有关,是期中和期末成绩的平均。如果大于等于60则输出P,反之则输出F。在成绩报告中,按照字母表的顺序排列所有学生姓名,并用PF表示成绩。 编写一个程序
我的程序:int main()
{vector<int> student;
while(cin>>x)
student.pushback(x);
class student{
public: std::istream& cmp(std::istream& );
private: double mid,final;string name;}
istream& student::cmp()
{if((mid+final)/2>60)
cout<<"p"<<endl;
else cout<<f"<<endl;}
for(vector<student>::size_type i=0;i!=student.size();++i)
{cout<<student[i].name<<endl;
cmp(student[i].mid,student[i].final)
}
名字排序显示还不会编~~谢谢啊

名字排序自己写一个比较函数
比如
bool less(string n1,string n2)
{
int i = strcmp(n1.c_csr(),n2.c_csr()) //string 转char*
的函数我忘了具体是啥
if(i<0)return 1;
else return 0;
}
然后调用sort(student &,student&,less)

student.pushback(x);
vector有这个函数吗是push_back吧