08年上半年软考程序员考试下午试题

发布时间:2012-07-19 共12页

试题二 (共 15 分)

  阅读以下说明和C程序,将应填入 (n) 处的字句写在答题纸的对应栏内。

[说明]

  下面的程序按照以下规则输出给定名词的复数形式:
  a. 若名词以 “y”结尾,则删除y并添加 “ies”;
  b. 若名词以 “s”、“ch”或“sh”结尾,则添加 “es”
  c. 其他所有情况,直接添加 “s”。

[C程序]

#include
#include
char *plural(char *word)
 {
 int n;
 char *pstr;
 n = strlen(word); /*求给定单词的长度*/
 pstr = (char *)malloc(n+3); /*申请给定单词的复数形式存储空间*/
 if (!pstr || n < 2)
 return NULL;
 strcpy(pstr,word); /*复制给定单词*/
 if ( (1) )
  {pstr[n-1] = 'i'; pstr[n] = 'e'; pstr[n+1] = 's'; (2) ;
  }
 else
 if(pstr[n-1]=='s'||pstr[n-1]== 'h' && ( (3) ))
 {
  pstr[n] = 'e'; pstr[n+1] = 's'; pstr[n+2] = '\0';
 }
  else{ pstr[n] = 's'; pstr[n+1] = '\0';
 }(4) ;
 }

 main( )
 {
 int i; char *ps;char wc[9][10] =
  {"chair","dairy","boss","circus","fly","dog","church","clue","dish"};
  for(i = 0; i < 9; i++)
  {
  ps = (5) ;printf("%s: %s\n",wc[i],ps); /*输出单词及其复数形式*/
  free(ps); /*释放空间*/
  }
  system("pause");
 }

2008年上半年 程序员 下午试卷 第 3 页 (共 12 页)

百分百考试网 考试宝典

立即免费试用