• 数组使用find查询用法


    #include "stdafx.h"
    #include <string>
    #include <list>
    #include <algorithm>
    #include <iostream>
    using namespace std;

    class Student
    {
    public:
     Student(){}
     Student(string name,string sex,int age,string number);
     int getAge(){return _age;}
        string getNumber(){return _number;}
     bool operator==(const string&str)//重载操作符
     {
           return str==_number;
     }
     bool operator==(const int&stemp)
     {
      return stemp==_age;
     }
    private:
     string _name;
     string _sex;
     int _age;
     string _number;
    };

    Student::Student(string name,string sex,int age,string number)
    {
     _name=name;
     _sex=sex;
     _age=age;
     _number=number;
    }

    int _tmain(int argc, _TCHAR* argv[])
    {
     Student st[5]={
          Student("la","男",12,"122"),
       Student("小林","男",13,"123"),
       Student("小林","男",14,"124")
     };

     string strnum;
     cout<<"enter number:";
     cin>>strnum;

     Student *present=find(st,st+4,strnum);
     cout<<"这个学生的学号是:"<<present->getNumber()<<endl;

     int age;
     cout<<"enter age: ";
     cin>>age;
     Student *pre=find(st,st+4,age);
     cout<<"这个学生的年龄是:"<<pre->getAge();
     getchar();
     getchar();
     return 0;
    }

  • 相关阅读:
    并查集-B
    ->的用法
    PTA-1042 字符统计
    PAT 1040有几个PAT
    assembly x86(nasm)修改后的日常
    python接口自动化之操作常用数据库mysql、oracle
    os模块常用方法
    python 多线程编程并不能真正利用多核的CPU
    连接mysql数据库
    python之用yagmail模块发送邮件
  • 原文地址:https://www.cnblogs.com/batman425/p/3188043.html
Copyright © 2020-2023  润新知