QQ网名大全

输入15个学生存入数组,并任意输入姓名,根据姓名查找相关信息。

class CStudent{
private:
CString name;CString school;int age;其他数据成员
public:
CString GetName();其他方法
}
CStudent:GetName()
{
return name;}
CStudent:SetName(const CString&newName)
{
name=newName;}
CStudent:SetAge(int newAge)
{
age=newAge;}
按姓名查询的话,先用一个MAP保存学生信息(name为key值,CStudent*为value值,如下:
CStudent*pSt=new CStudent;if(pSt=NULL)
return;pSt->SetName("小李");pSt->SetAge(18);其他set
CMapStringToPtr stMap;stMap.SetAt(pSt->GetName(),pSt);加入到MAP中
要查询的话:
void*p=NULL;if(stMap.Lookup("小李",p)=TRUE)
{
CStudent*pQ=(CStudent*)p;pQ为你查找的名字叫“小李”的学生指针
}
上面是MFC的
佚名
2024-05-19 00:32:01
最佳回答
类似问题(10)