zoukankan      html  css  js  c++  java
  • 数组使用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;
    }

  • 相关阅读:
    CB2010连接WORD
    WIN7下的MODI
    视频预览1
    上下文工具栏(ContextTab)
    多功能便携式拉杆箱电源系统
    Firefox 内存占用问题
    「新闻」Google Science Fair
    2011521
    「电视剧」永远的忠诚
    2011429
  • 原文地址:https://www.cnblogs.com/batman425/p/3188043.html
Copyright © 2011-2022 走看看