zoukankan      html  css  js  c++  java
  • c++运算符重载

    #include <iostream>
    #include <string>
    #include <list>
    using namespace std;
    
    class Student {
       string name;
       char sex;
       int score;
       string grade;
    
    public:
       Student(string name, char sex, int score, string grade);
       friend ostream &operator<< (ostream& os, Student st) ;
       friend bool operator<(Student &st1, Student &st2);    
    };
    //你提交的代码将被嵌入到这里
    ostream &operator<< (ostream& os, Student st){
    os<<st.name<<" "<<st.sex<<" "<<st.score<<" "<<st.grade<<'
    ';
    return os;    
    }
    bool operator<(Student &st1, Student &st2){
    if(st1.score>=st2.score) return false;
    return true;    
    }
    Student::Student(string name, char sex, int score, string grade) {
       this->name = name;
       this->sex = sex;
       this->score = score;
       this->grade = grade;
    }
    
    int main() {
       list<Student> st;
       string name, grade;
       char sex;      int score;
        
       for(int i = 0; i < 5; i++) {
          cin>>name;      cin>>sex;
          cin>>score;       cin>>grade;
          st.push_back(Student(name, sex, score, grade));
       }
    
       st.sort();
    
       list<Student>::iterator p = st.begin();
       while(p != st.end()) {
          cout<<*p;
          p++;
       }
       return 0;
    }
    不一样的烟火
  • 相关阅读:
    EntityFramework系列:MySql的RowVersion
    EntityFramework系列:SQLite.CodeFirst自动生成数据库
    怎么回事呢?
    为蛇么不现实
    发布到个人主页
    作别
    budao 首页
    中午吃饱了
    作业写好了吗?
    分类
  • 原文地址:https://www.cnblogs.com/cstdio1/p/10933340.html
Copyright © 2011-2022 走看看