1. 程式人生 > >一個生成祝福簡訊的簡單C++程式

一個生成祝福簡訊的簡單C++程式

正值大過年的,很多人對群發簡訊反感,我就靈機一動用Qt寫了一個簡單的祝福簡訊的程式,主要的程式碼如下:

voidWidget::printMsg()
{
inti=0;
intj=0;
boolrightPoint=false;
intmack;
intnumBuf[10]={0};
//詞語匯入//0位置為標誌位
stringstr[60]={"","恭喜發財","一帆風順","富貴雙全","雙喜臨門","五福臨門","六六大順","十全十美","萬事如意","福滿門庭","萬福臨門","心想事成","吉星高照","福滿人間","喜氣臨門","吉祥如意","萬事亨通","永珍更新","閤家歡樂","鵬程萬里"
,"門迎百福","瑞氣盈門","旭日東昇","和氣生財","財源廣進","出入平安","新年快樂","欣欣向榮","美滿幸福","和氣致祥","鸞鳳和鳴","喜氣盈門","招財進寶","福星高照","福祿壽禧","榮華富貴","大展鴻圖","家庭幸福","前途無量","前程似錦"};
stringnode="";
stringToPeople="***祝你:";
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

簡單的效果圖如下: