#include <iostream>
#include <vector>
#include <string>
class Student
{
public:
std::string m_strNo;
std::string m_strName;
std::string m_strSex;
Student(std::string strNo,std::string strName,std::string strSex):
m_strNo(strNo),m_strName(strName),m_strSex(strSex){}
void display()
{
std::cout << m_strNo << "\t" << m_strName << "\t" << m_strSex << "\t" << std::endl;
}
};
class StudentCollect
{
std::vector<Student> Stu_vec;
public:
void Add(Student &s)
{
Stu_vec.push_back(s);
}
Student *Find(std::string strNo)
{
bool bFind=false;
int i;
for(i=0;i<Stu_vec.size();i++)
{
Student &s = Stu_vec.at(i);
if(s.m_strNo==strNo)
{
bFind=true;
break;
}
}
Student *s=NULL;
if(bFind)
s=& Stu_vec.at(i);
return s;
}
};
int main()
{
Student s1("1001","A","boy");
Student s2("1002","B","girl");
StudentCollect s;
s.Add(s1);
s.Add(s2);
Student *ps=s.Find("1002");
if(ps)
ps->display();
return 0;
}
学生信息简单管理(vector)
最新推荐文章于 2023-05-26 11:16:04 发布