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;
    }
    不一样的烟火
  • 相关阅读:
    原型模式
    windows下Redis安装及利用java操作Redis
    redis笔记
    STS 安装SVN插件
    java 操作MongoDB简易工具类
    Mysql 单表数据量过大移除数据
    Mysql 提示拷贝效率
    JS 图片显示一部分 小计
    FashJson转换
    WIndow MongoDb安装和启动
  • 原文地址:https://www.cnblogs.com/cstdio1/p/10933340.html
Copyright © 2011-2022 走看看