![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
2011春江蘇省二級C上機考試真題第2套 |
江蘇省高等學(xué)校非計算機專業(yè)學(xué)生 計算機基礎(chǔ)知識和應(yīng)用能力等級考試上機試卷(2011年春) 二級C語言 (試卷代號C02) (本試卷完成時間70分鐘) 一、改錯題(16分) 【程序功能】 統(tǒng)計一個字符串中包含的字母串個數(shù)并找出其中最長的字母串。 所謂字母串是指一個連續(xù)的字母序列(不區(qū)分大小寫),字母串之間用非字母字符分隔。函數(shù)count的功能是統(tǒng)計p指向的字符串中包含的字母串個數(shù),找出的最長字母串存放在pmax指向的數(shù)組中,函數(shù)返回字母串的個數(shù)。 【測試數(shù)據(jù)與運行結(jié)果】 測試數(shù)據(jù):you are teaeher234too. 屏幕輸出:a=you are teacher234too. number is 4 max string is:teacher 【含有錯誤的源程序】 #include <stdio.h> #include <string.h> #include <ctype.h> int count(char p[],char pmax[]) { int j=0,k,m=0; char temp[100]; while(*p) { while((!isalpha(*p)) && *p) p++; k=0; if(*p!='\0') m++; while(isalpha(*p)) temp[k++]=*p++; temp[k]="\0"; if(k<j) { j=k; pmax=temp; } } return m; } void main() { char a[100]="you are teacher234too.",max[100]; int i; i=count(a[],max[]); if(i==0) printf("a=%S: No letter strings!\n",a); else prinff("a=%s\nnumber is %d\nmax string is:%s\n",a,i,max); } 【要求】 1.將上述程序錄入到文件myf1.c中,根據(jù)題目要求及程序中語句之間的邏輯關(guān)系對程序中的錯誤進(jìn)行修改。 2.改錯時,可以修改語句中的一部分內(nèi)容,調(diào)整語句次序,增加少量的變量說明或編譯預(yù)處理命令,但不能增加其他語句,也不能刪去整條語句。 3.改正后的源程序(文件名myf1.c)保存在T:盤根目錄中供閱卷使用,否則不予評分 二、編程題(24分) 【程序功能】 將一個二維數(shù)組中的若干行數(shù)據(jù)按要求插入到另一個二維數(shù)組中。 【編程要求】 1.定義符號常量N代表4 2.編寫函數(shù)int insert_row(int a[][N],int n,int b[][N],int m)。已知形參a指向的二維數(shù)組(簡稱a數(shù)組)前n行數(shù)據(jù)已按每行數(shù)據(jù)之和升序排列,形參b指向的二維數(shù)組中有m行數(shù)據(jù)。insert_row函數(shù)實現(xiàn)將b數(shù)組中m行數(shù)據(jù)插入到a數(shù)組中,完成插入操作后a數(shù)組中所有行的數(shù)據(jù)仍按每行數(shù)據(jù)之和升序排列。函數(shù)返回a數(shù)組中有效數(shù)據(jù)的行數(shù)。 3.編寫main函數(shù)。函數(shù)功能是聲明兩個二維數(shù)組x和y并用測試數(shù)據(jù)初始化,用x和y 數(shù)組作為實參調(diào)用insert_row函數(shù)將y數(shù)組中的兩行數(shù)據(jù)插入到x數(shù)組中。輸出x數(shù)組中全部數(shù)據(jù)到屏幕及文件myf2.out中。最后將考生本人的準(zhǔn)考證號字符串輸出到文myf2. out中。 【測試數(shù)據(jù)與運行結(jié)果】 測試數(shù)據(jù): x數(shù)組原數(shù)據(jù): 2 2 3 4 9 10 11 12 y數(shù)組數(shù)據(jù): 1 3 5 7 5 10 15 20 屏幕輸出: 2 2 3 4 1 3 5 7 9 10 11 12 5 10 15 20 【答案】 改錯1:將第13行 "temp[0]="\0" 修改為 temp[0]='\0' 改錯2:將第 14行 if(k<j) 修改為 if(k>j) 改錯3:將第16行 pmax=temp,修改為 strcpy(pmax,temp); 改錯4:將第24行i=count(a[],max[])修改為i=count(a,max); |