问题 问答题

编写函数fun(),该函数的功能是从字符串中删除指定的字符,同一字母的大、小写按不同字符处理。 例如:程序执行时输入字符串为turbo c and borland c++,从键盘上输入字符n,则输出后变为turbo c ad borlad c++。 如果输入的字符在字符串中不存在,则字符串照原样输出。 注意:部分源程序已存在文件test18_2.cpp中。 请勿改动主函数脚in和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 文件test18_2.cpp的内容如下: #include<stdio.h> #include<iostream.h> #include<conio.h> void fun(char s[ ], int c) { } void main ( ) { static char str[ ]="turbo c and borland c++"; char ch; cout<<"原始字符串:\n"<<str<<end1; cout<<"输入一个字符:"; cin>>ch; fun(str.ch); cout<<"str="<<str<<end1; }

答案

参考答案:

解析:void fun(char s[], int c) { int i=0; char *p; p=s; while( *p) {if( *p!=c) {s[i]=*p; i++; } p++; } s[i]=’\0’; }本题考查用字符指针来控制字符数组中的元素。指针p初始化时应指向字符数组的首地址s,之后利用p逐个取得数组中的元素,然后用取得的字符逐个与要删除的字符进行比较,如果二者相同,则跳过该字符,去取下一个数组元素,这样最终得到的字符串中就把要删除的字符去掉了。最后不要忘记要手动地加上一个字符串结束标记‘\0’。

阅读理解

阅读理解

     Much as Robby tried,he lacked the sense of tone and basic rhythm (节奏). But he dutifully reviewed

his lessons.Over the months he tried and tried,and often repeated to me "My mom's going to hear me play some day."

     But he seemed hopeless,with no born ability.A real bad advertisement for my teaching!I was so happy when one day he stopped coming.

     Several weeks later my students were to have a recital (演奏会). To my surprise,Robby came,asking

to play in the recital.

     "But,it is for current pupils,you dropped."

     "My mom was sick.But I have been practicing.I've just got to play!"

     I didn't know what led me to agree,maybe...

     The recital came.I_put_Robby_up_last_to_play_before_my_"curtain_closer",by which,I could save the recital if...

     The recital went off well.Robby came up on stage,clothes wrinkled and his hair looked like he'd run an eggbeater through it."How could his mom...?"

     Robby pulled out the piano bench and began.It was Mozart's work!I was not prepared for what I heard next.Like in a dream,I was then woken up by the wild applause-everybody was on their feet!

     "I've never heard you play like that,Robby!How'd you do it?"

     Through the microphone Robby explained:"Well,Miss Hondorf,remember I told you my mom was

sick?Actually she had cancer and died this morning.She was born deaf,and tonight was the first time she

ever heard me play.I wanted to make it special."

     My eyes were wet.He was not a student of mine,but a teacher!

1. We can infer from the underlined sentence that the writer________.

A. was fully confident that Robby would perform well at the recital

B. thought that Robby would make the recital special

C. thought that Robby wouldn't play at the recital

D. had no confidence in Robby at all for the recital

2. What made the boy succeed in the recital?

A. Love for his mother.

B. Musical talent.

C. The writer's help.

D. Regular practice.

3. What made the writer think that Robby was her teacher,not student?

A. That he played better than her in the recital.

B. That he loved his mother more than she did.

C. That he never gave up.

D. That,the audience gave him more applause than her.

4. What is the highlight of the recital?

A. The writer's performance.  

B. Robby's performance.

C. Robby and his mom's story.  

D. The audience's applause.

单项选择题