CPerson
来源:互联网 发布:21天学通java知乎 编辑:程序博客网 时间:2024/03/29 14:09
//using the modual file
#include <iostream>
#include <string>
#include <vector>
#include <conio.h>
using namespace std;//using standard namespace
class CPerson
{
public:
CPerson();
~CPerson();
void Add( char * pszName, int nWage );
void Delete( char* pszName );
void Print();
protected:
struct PersonInfo
{
string strName;
int nWage;
};
private:
vector<PersonInfo*> m_vInfo;
};
CPerson::CPerson()
{
}
CPerson::~CPerson()
{
//delete all persons' information
for( size_t st = 0; st < m_vInfo.size(); st ++ )
{
Delete( (char*)m_vInfo[st] -> strName.data() );
}
m_vInfo.clear();
}
void CPerson::Add( char* pszName, int nWage )
{
if( pszName )
{
CPerson::PersonInfo* pPerson = new CPerson::PersonInfo;
pPerson -> strName = pszName;
pPerson -> nWage = nWage;
m_vInfo.push_back( pPerson );
}
else
{
cout<<"ERROR Name is input!!"<<endl;
}
}
void CPerson::Delete( char* pszName )
{
vector<PersonInfo*>::iterator it = m_vInfo.begin();
for( ; it != m_vInfo.end(); it++)
//for( size_t st = 0; st < m_vInfo.size(); st++ )
{
//if( m_vInfo[st] -> strName == pszName )
if( (*it) -> strName == pszName)
{
//delete m_vInfo[st];// this method doesnot delete the personinfo, just clear the name
delete (*it);
m_vInfo.erase( it );
break;
}
}
}
void CPerson::Print()
{
for( size_t st = 0; st < m_vInfo.size(); st++ )
{
cout << "Name = " << m_vInfo[st] -> strName
<< "/t"
<< "Wage = " << m_vInfo[st] -> nWage
<< endl;
}
}
int main(int argc, char* argv[])
{
CPerson p;
cout << "Add Member!" << endl;
//add member
p.Add( "Jackie", 2000 );
p.Add( "Paul", 3000 );
p.Add( "Hery", 3500 );
//print out
p.Print();
cout << "Delete Member!" << endl;
//delete member
p.Delete( "Paul" );
//print out after delete
p.Print();
getch();
return 0;
}
//delete m_vInfo[st]; 这样为什么没有删除呢
- CPerson
- CPerson 的类
- 10.2 CPerson类的派生
- CPerson派生出CEmployee类
- CPerson类p派生CEmployee
- 9.2 CPerson类的派生类
- 第11周项目3-Cperson
- CEmployee类继承自CPerson类
- CPerson类——个人信息表
- 第十一周项目三----定义cperson类
- 11_3CEmployee继承自CPerson类
- CEmployee类继承自CPerson类
- 定义一个名为CPerson的类
- CEmployee类继承自CPerson类
- 10-2 继承与派生应用(CPerson类)
- 第10周-任务2-CEmployee类继承CPerson类
- 第十周任务二 CEmployee类继承CPerson类
- CPerson类派生出CEmployee类(继承)
- 禁止批处理中的某一条命令回显结果(批处理中的sleep)
- php网络状态代码判定
- linux下top命令参数解释
- 今天是2010年9月8日
- cocoa内存管理注意事项
- CPerson
- 用动态SQL. 查询
- Android-Notification的使用
- Android XML属性在文档中的位置
- 也说说internet explorer无法打开internet站点,已终止操作
- JSON数据交换格式
- 浅谈myeclipse内存溢出问题
- shell 判断变量为空
- JavaScript中的JSON