計算機四級指的是全國計算機等級考試的最高級別,科目種類有:四級作業系統原理、四級計算機組成與介面、四級資料庫原理、四級軟體工程、四級計算機網路。為幫助考生們更好通過考試,特地為大家準備了以下四級模擬考試題,希望大家喜歡!
1./* 請編寫一個函式changeStr(char *s),函式的功能是把s串中所有的字母改寫成該字母的下一個字母,字母z改寫成字母a。大寫仍為大寫字母,小寫字母仍為小寫字母,其它的字元不變。函式ReadWrite()實現從檔案中讀取兩個字串,並呼叫函式changestr(),最後把結果輸出到檔案中。
注意:部分源程式存在檔案PROG1.C中。請勿改動主函式main()和其它函式中的任何內容,僅在函式changeStr()的花括號中填入你編寫的若干語名。*/
#include
#include
#include
#include
#define N 81
changeStr ( char *s )
{
}
main( )
{
char a[N] ;
clrscr( ) ;
printf ( “Enter a string : ” ) ; gets ( a ) ;
printf ( “The original string is : ” ) ; puts( a ) ;
changeStr ( a ) ;
printf ( “The string after modified : ”) ;
puts ( a ) ;
ReadWrite( ) ;
}
ReadWrite( )
{
int i ;
char a[N] ;
FILE *rf, *wf ;
rf = fopen(“”, “r”) ;
wf = fopen(“”, “w”) ;
for(i = 0 ; i 《 10 ; i++) {
fscanf(rf, “%s”, a) ;
changeStr(a) ;
fprintf(wf, “%s ”, a) ;
}
fclose(rf) ;
fclose(wf) ;
}
2./* 程式PROG1.C的功能是:利用以下所示的簡單迭代方法求方程:
cos(x)-x=0的一個實根2016最新全國計算機四級機試試題及答案2016最新全國計算機四級機試試題及答案。
Xn+1=cos(Xn)
迭代步驟如下:
(1) 取x1初步值為0.0;
(2) x0=x1,把x1,把x1的值賦給x0;
(3) x1=cos(x0),求出一個新的x1;
(4) 若x0-x1的絕對值小於0.000001,執行步驟(5),否則執行步驟(2);
(5) 所求x1就是方程cos(x)-x=0的一個實根,作為函式值返回。
請編寫函式countValue()實現程式的要求,最後呼叫函式writeDAT()把結果輸出到檔案中。
注意:部分源程式存在檔案PROG1.C中,請勿改動主函式main()和輸出資料函式WriteDAT()的內容。 */
#include
#include
#include
float countValue()
{
}
main()
{
clrscr();
printf(“實根=%f ”, countValue());
printf(“ %f ”,cos(countValue())-countValue());
writeDAT();
}
writeDAT()
{
FILE *wf ;
wf=fopen(“”,“w”) ;
fprintf(wf, “%f ”, countValue()) ;
fclose(wf) ;
}
3./* 已知在檔案中存有若干個(個數《200)四位數字的正整數,函式ReadDAT()讀取這些正整數並存入陣列xx中。請編制函式CalValue()其功能要求是:
1.求出這個檔案有多少個正整數totNum;2.求出這些數中的各位數字之和是奇數的數的.個數totCnt,以及不滿足此條件的所有數的算術平均值totPjz,最後呼叫函式WriteDAT()把所求的結果輸出到檔案中。
注意:部分源程式存放在PROG1.C中。
請勿改動主函式main(),讀資料函式ReadDAT()和輸出資料函式WriteDAT()的內容。 */
#include
#include
#define MAXNUM 200
int xx[MAXNUM] ;
int totNum = 0 ; /* 檔案有多少個正整數 */
int totCnt = 0 ; /* 符合條件的正整數的個數 */
double totPjz = 0.0 ; /* 平均值 */
int ReadDat(void) ;
void WriteDat(void) ;
void CalValue(void)
{
}
void main()
{
clrscr() ;
if(ReadDat()) {
printf(“資料檔案不能開啟!07 ”) ;
return ;
}
CalValue() ;
printf(“檔案有正整數=%d個 ”, totNum) ;
printf(“符合條件的正整數的個數=%d個 ”, totCnt) ;
printf(“平均值=%.2lf ”, totPjz) ;
WriteDat() ;
}
int ReadDat(void)
{
FILE *fp ;
int i = 0 ;
if((fp = fopen(“”, “r”)) == NULL) return 1 ;
while(!feof(fp)) {
fscanf(fp, “%d,”, &xx[i++]) ;
}
fclose(fp) ;
return 0 ;
}
void WriteDat(void)
{
FILE *fp ;
fp = fopen(“”, “w”) ;
fprintf(fp, “%d %d %.2lf ”, totNum, totCnt, totPjz) ;
fclose(fp) ;
}
4./* 編寫一個函式findstr(),該函式統計一個長度為2的子字串在另一個字串中出現的次數。例如,假定輸入的字串為“asd asasdfg asd as zx67 asd mklo”,子字串為“as”,則輸出6。 函式ReadWrite()實現從檔案中讀取兩個字串,並呼叫函式findStr(),最後把結果輸出到檔案中
注意:部分源程式存在檔案PROG1.C中2016最新全國計算機四級機試試題及答案計算機考試。請勿改動主函式main()和其它函式中的任何內容,僅在函式findStr()的花括號中填入你編寫的若干語句。*/
#include
#include
#include
int findStr(char *str,char *substr)
{
}
main()
{
char str[81], substr[3] ;
int n ;
clrscr() ;
gets(str) ;
gets(substr) ;
puts(str) ;
puts(substr) ;
n=findStr(str, substr) ;
printf(“n=%d ”, n) ;
ReadWrite() ;
}
ReadWrite()
{
char str[81], substr[3], ch;
int n, len, i = 0;
FILE *rf, *wf ;
rf = fopen(“”, “r”) ;
wf = fopen(“”, “w”) ;
while(i 《 5) {
fgets(str, 80, rf) ;
fgets(substr, 10, rf) ;
len = strlen(substr) - 1 ;
ch = substr[len] ;
if(ch == ’ ’ || ch == 0x1a) substr[len] = 0 ;
n=findStr(str, substr);
fprintf(wf, “%d ”, n) ;
i++ ;
}
fclose(rf) ;
fclose(wf) ;
}
5./* 請編寫函式Void countValue(int *a,int *n),它的功能是:求出1到1000之內能被7或11整除但不能同時被7和11整除的所有整數,並放在陣列a中,然後通過n返回這些數的個數。
注意:部分源程式存入在PROG1.C中。
請改動主函式main()和輸入輸出資料函式WriteDAT()的內容。*/
#include
int cnt, sum ;
void countValue()
{
}
void main()
{
cnt = sum = 0 ;
countValue() ;
printf(“素數的個數=%d ”, cnt) ;
printf(“滿足條件素數值的和=%d”, sum) ;
writeDAT() ;
}
writeDAT()
{
FILE *fp ;
fp = fopen(“”, “w”) ;
fprintf(fp, “%d %d ”, cnt, sum) ;
fclose(fp) ;
}