88.函數(shù)Rdata()實現(xiàn)從文件IN.dat中讀取一篇英文文章,存入到字符串?dāng)?shù)組string中;請編寫函數(shù)encryptChar(),其功能是:按給定的替代關(guān)系對數(shù)組string中的所有字符進(jìn)行替代后,仍存入數(shù)組string的對應(yīng)位置上,最后調(diào)用函數(shù)Wdata(),把結(jié)果string輸出到OUT.dat文件中。
替代關(guān)系:f(p)=p*11 mod 256(p是數(shù)組中某一個字符的ASCII值,f(p)是計算后新字符的ASCII值),如果原字符是數(shù)字字符0~9或計算后f(p)值小于等于32,則該字符不變,否則將f(p)所對應(yīng)的字符進(jìn)行替代。
原始數(shù)據(jù)文件存放的格式是:每行的寬度均小于80個字符。
【答案】
void encryptChar()
{ int i;
char *pf;
for (i=0; i
{ pf = string[i];
while (*pf != 0)
{ if ((*pf>='0' && *pf<='9') || *pf*11%256<=32)
{ pf++;
continue;
}
*pf = *pf*11%256;
pf++;
}
}
}
89.已知數(shù)據(jù)文件IN.dat中存有200個四位數(shù),并已調(diào)用讀函數(shù)RData()把這些數(shù)存入數(shù)組a中,請編寫函數(shù)CalVal(),其功能是:若一個四位數(shù)的千位數(shù)字上的值大于等于百位數(shù)字上的值,百位數(shù)字上的值大于等于十位數(shù)字上的值,以及十位數(shù)字上的值大于等于個位數(shù)字上的值,并且原四位數(shù)是奇數(shù),則統(tǒng)計出滿足此條件的個數(shù)count并把這些四位數(shù)按從小到大的順序存入數(shù)組b中。最后調(diào)用寫函數(shù)WData(),把結(jié)果count以及數(shù)組b中符合條件的數(shù)輸出到OUT.dat文件中。
【答案】
void CalVal()
{ int i, thou, hun, ten, data, j;
for (i=0; i
{ thou = a[i]/1000;
hun = a[i]%1000/100;
ten = a[i]%100/10;
data = a[i]%10;
if ((thou>=hun) && (hun>=ten) && (ten>=data) && a[i]%2!=0)
{ b[count] = a[i];
count++;
}
}
for (i=0; i
for (j=i+1; j
if (b[i] > b[j])
{ data = b[i];
b[i] = b[j];
b[j] = data;
}
}
90.已知在文件IN.dat中存有100個產(chǎn)品銷售記錄,每個產(chǎn)品銷售記錄由產(chǎn)品代碼code(字符型4位)、產(chǎn)品名稱name(字符型10位)、單價uprice(整型)、數(shù)量amount(整型)、金額sum(長整型)5部分組成。其中:金額=單價×數(shù)量。函數(shù)RData()讀取這100個銷售記錄并存入結(jié)構(gòu)數(shù)組sell中。請編寫函數(shù)AscendSort(),其功能是:按產(chǎn)品代碼從小到大進(jìn)行排列,若產(chǎn)品代碼相等,則按金額從大到小進(jìn)行排列,最終排列結(jié)果仍存入結(jié)構(gòu)數(shù)組sell中。最后調(diào)用函數(shù)WData(),把結(jié)果輸出到OUT.dat文件中。
【答案】
void AscendSort()
{ int i, j;
PRO temp;
for (i=0; i<99; i++)
for (j=i+1; j<100; j++)
if (strcmp(sell[i].code, sell[j].code) > 0)
{ temp = sell[i];
sell[i] = sell[j];
sell[j] = temp;
}
else if (strcmp(sell[i].code, sell[j].code) == 0)
{ if (sell[i].sum < sell[j].sum)
{ temp = sell[i];
sell[i] = sell[j];
sell[j] = temp;
}
}
}
相關(guān)推薦:
2011計算機(jī)等級三級數(shù)據(jù)庫考前實訓(xùn)練習(xí)匯總
考試吧策劃:2011年計算機(jī)等級考試備考攻略
2011年計算機(jī)等級考試三級數(shù)據(jù)庫SQL語句大全