計算機四級指的是全國計算機等級考試的最高級別,科目種類有:四級操作系統原理、四級計算機組成與接口、四級數據庫原理、四級軟件工程、四級計算機網絡。為幫助考生們更好通過考試,特地為大家準備了以下四級模擬考試題,希望大家喜歡!
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) ;
}