本文主要是介绍一个生成祝福短信的简单C++程序,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
正值大过年的,很多人对群发短信反感,我就灵机一动用Qt写了一个简单的祝福短信的程序,主要的代码如下:
void Widget::printMsg()
{
int i = 0;
int j = 0;
bool rightPoint = false;
int mack;
int numBuf[10] = {0};
//词语导入//0位置为标志位
string str[60] = {"","恭喜发财","一帆风顺","富贵双全","双喜临门","五福临门","六六大顺","十全十美","万事如意","福满门庭","万福临门","心想事成","吉星高照","福满人间","喜气临门","吉祥如意","万事亨通","万象更新","合家欢乐","鹏程万里","门迎百福","瑞气盈门","旭日东升","和气生财","财源广进","出入平安","新年快乐","欣欣向荣","美满幸福","和气致祥","鸾凤和鸣","喜气盈门","招财进宝","福星高照","福禄寿禧","荣华富贵","大展鸿图","家庭幸福","前途无量","前程似锦"};
string node = "";
string ToPeople = "***祝你:";
srand(time(0));
for(i = 0;i < 10;i++)
{
while (!rightPoint)//检测词语是否重复或者为空
{
mack = rand() % 60;
if (strcmp(str[mack].c_str(),"") == 0)
{
continue;
}
for (j = 0 ;j < 10; j++)
{
if (numBuf[j] == 0)
{
numBuf[j] == mack;
break;
}
if (numBuf[j] == mack)
{
continue;
}
}
node = str[mack];
break;
}
ToPeople = ToPeople + node;
ToPeople = ToPeople + ",";
//cout << ToPeople;
}
ToPeople = ToPeople + "这个绝对不是群发的哦~请新年务必快乐~!";
ui->textEdit->setText(ToPeople.c_str());
}
源代码可到这里下载:http://download.csdn.net/detail/u013267687/8452157
简单的效果图如下:
这篇关于一个生成祝福短信的简单C++程序的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!