caculate.cpp
来自「一个随机抽人的小游戏,可以随即输入无穷多个人名,点击则随机抽出一个」· C++ 代码 · 共 73 行
CPP
73 行
#include "stdafx.h"
#include "Caculate.h"
CCaculate::CCaculate()
{
m_nListSize = 0;
}
CCaculate::CCaculate(const CCaculate& oOther)
{
if (this == &oOther)
return;
else
{
m_nListSize = oOther.m_nListSize;
m_vNameList = oOther.m_vNameList;
}
}
CCaculate::~CCaculate()
{
}
int CCaculate::LuckClick(CString& strLuck)
{
int nIdx = 0;
if (m_nListSize > 0)
{
nIdx = rand() % m_nListSize;
m_nListSize--;
}
else
{
return 0;
}
vector<CString>::iterator iPos;
iPos = m_vNameList.begin();
int i = 0;
while (i < nIdx)
{
iPos++;
i++;
}
strLuck = (*iPos);
iPos = m_vNameList.erase(iPos);
return nIdx;
}
int CCaculate::AddName(CString strName)
{
if (!strName.IsEmpty())
{
m_vNameList.push_back(strName);
m_nListSize++;
return 1;
}
else
{
return 0;
}
}
int CCaculate::GetListSize()
{
return m_nListSize;
}
void CCaculate::GetNameList(vector<CString>& vNameList) const
{
vNameList = m_vNameList;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?