資源簡介
c++ 課程設計報告 可直接交作業版 完整 代碼 + 報告

代碼片段和文件信息
#include
#include
#include?
using?namespace?std;
#define?LEN?5?//?車牌長度為5個字符
char?getChar()?//隨機產生一個A到Z的字符
{
char?aChar;
aChar?=?‘A‘+?rand()?%?((‘Z‘?+?1)?-?‘A‘);
while?(‘I‘?==?aChar)?//?設定車牌中不產生I字母
{
aChar?=?‘A‘+?rand()?%?((‘Z‘?+?1)?-?‘A‘);
}
return?aChar;
}
char?getNum()?//隨機產生一個0到9的字符
{
char?aChar;
aChar?=?‘0‘+?rand()?%?((‘9‘?+?1)?-?‘0‘);
return?aChar;
}
void?setData(char?*?data?int?type)?//?設置車牌號碼
{
for?(int?i?=?0;?i? {
int?flag?=?rand()?%?2;
if?(1?==?flag)
{
data[i]?=?getChar();
}?else?{
data[i]?=?getNum();
}
}
if?(type?==?1)?//?需要產生的是出租車車牌
{
data[0]?=?‘C‘;
data[1]?=?‘Z‘;?//?設置出租車車牌為CZ開頭
for?(int?i?=?2;?i? {
int?flag?=?rand()?%?2;
if?(1?==?flag)
{
data[i]?=?getChar();
}?else?{
data[i]?=?getNum();
}
}
}
}
void?printData(char?data[][LEN?+?1]?int?count)
{
for?(int?i?=?0;?i? {
cout?< }
cout?<}
void?main()
{
cout?<“本程序設定車牌為5個字符!“?<
char?data[100][LEN?+?1];?//?保存已經存在的車牌
for?(int?i?=?0;?i?100;?i++)?//?初始化車牌
{
data[i][LEN]?=?‘\0‘;
}
int?count?=?0;
srand((int)time(0));
for?(int?k?=?0;?k?10;?k++)?//?隨機產生已經存在的車牌號碼
{
setData(data[count]?0);
count++;
}
cout?<“已經存在的車牌“?< printData(data?count);
int?type?=?-1;
cout?<“請選擇產生的車牌類型:“?< cout?<“??0.默認“?< cout?<“??1.出租車“?< cin.sync();
cin?>>?type;
while?((type?!=?0)?&&?(type?!=?1))
{
cin.sync();
cin?>>?type;
cout?<“輸入錯誤,重新輸入...“?< continue;
}
int?select?=?-1;
char?getData[LEN?+?1];?//?保存為用戶產生的車牌
getData[LEN]?=?‘\0‘;
bool?flag?=?false;?//?產生的車牌是否有效
int?time?=?2;?//?設置用戶最多選擇兩次
bool?flagUser?=?false;?//?是否根據用戶的選擇產生了有效車牌
bool?flagExi?=?false;
while?((time?>?0)?&&?(flagUser?==?false))
{
cout?<“還可以選擇“?< cout?<“請選擇產生方式:“?< cout?<“??1.手動輸入“?< cout?<“??2.隨機產生“?< cin.sync();
cin?>>?select;
if?(1?==?select)
{
flagExi?=?false;
flag?=?false;
while?(flag?==?false)
{
cout?<“請輸入車牌號(例如?AB123)“?< cin.sync();
cin?>>?getData[0]?>>?getData[1]?>>?getData[2]?>>?getData[3]?>>?getData[4];
for?(int?i?=?0;?i? {
if?(strcmp(getData?data[count])?==?0)?//?判斷是否已經存在
{
cout?<“已存在,請重新輸入“?< flagExi?=?true;
break;
}
if?((1?==?type)?&&?(getData[0]?!=?‘C‘)?&&?(getData[1]?!=?‘Z‘))
{
cout?<“出租車車牌應該以CZ開頭,請重新輸入“?< flagExi?=?true;
break;
}
}
if?(flagExi?==?true)?//?車牌已經存在,重新選擇
{
flagExi?=?false;
continue;
}
cout?<“產生車牌:“?< char?flagChar;
cin.sync();
cin?>>?flagChar;
if?((flagChar?==?‘y‘)?||?(flagChar?==?‘Y‘))
{
flagUser?=?true;?//?車牌有效
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????4364??2015-06-29?13:43??test.cpp
?????文件??????139264??2015-06-29?13:53??選車牌.doc
- 上一篇:C++算法編程視頻
- 下一篇:ntripclient-c++
評論
共有 條評論