问题 问答题

函数ReadDat()的功能是实现从文件IN39.DAT中读取一篇英文文章存入到字符串数组xx中。请编制函数ChA(),该函数的功能是:以行为单位把字符串的第一个字符的ASCII值加第二个字符的ASCII值,得到第一个新的字符,第二个字符的ASCII值加第三个字符的ASCII值,得到第二个新的字符,以此类推一直处理到倒数第二个字符,最后一个字符的ASCII值加第一个字符的ASCII值,得到最后一个新的字符,得到的新字符分别存放在原字符串对应的位置上。最后把已处理的字符串逆转后仍按行重新存入字符串数组xx中,井调用函数WriteDat()把结果肛输出到文件OUT39.DAT中。
注意:部分源程序已给出。
原始文件存放的格式是:每行的宽度小于80个字符,含标点符号和空格。
请勿改动主函数main()、读函数ReadDat()和写函数WriteDat()的内容。
试题程序:
#include<stdio.h>
#include<string.h>
#include<conio.h>
char xx[50][80];
int maxline=0;
int ReadDat();
void WriteDat();


void ChA(void)


void main()

clrscr();
if (ReadDat())

printf("数据文件 IN39.DAT 不能打开!\n\007" );
return;

ChA( );
WriteDat();

int ReadDat(void)

FILE *fp;
int i=0;
char *p;
if((fp=fopen("IN39.DAT","r"))==NULL)
return 1;
while(fgets(xx[i],80,fp)!=NULL)

p=strchr(xx[i],’\n’);
if(p) *p=0;
i++;

maxline=i;
fclose(fp);
return 0;

void WriteDat()

FILE *fp;
int i;
clrscr();
fp=fopen("OUT39.DAT","w");
for(i=0;i<maxline;i++)

printf("%s\n",xx[i]);
fprintf(fp,"%s\n",xx[i]);

fclose(fp);

答案

参考答案:

void ChA(void)

{

int i,j,k,str;

char ch;

for(i=0;i<maxline;i++)

{

str=strlen(xx[i]); /*求各行字符串的总长度*/

ch=xx[i][0];

for(j=0;j<str-A;j++) /*将该字符的ASCII值与下一个字符的ASCII值相加,得到新的字符*/

xx[i][j]+=xx[i][j+A];

xx[i][str-A]+=ch; /*将最后一个字符的ASCII值与第一个字符的ASCII值相加,得到最后

一个新的字符*/

for(j=0,k=str-A;j<str/B;j++,k--) /*将字符串逆转后仍按行重新存入字符串数组xx中*/

{

ch=xx[i][j];

xx[i][j]=xx[i][k]

xx[i][k]=ch;

}

}

}

解析:

本题考查的知识点如下;

(1) 字符变量的整数运算。

(2) 字符的逆序排列。

因为是以行为处理单位,所以要先求得每一行中字符的个数。在C语言中,字符型数据可参与任何整数运算,实际参与运算的是字符的ASCII码。这里可以直接将字符的ASCII码相加,即可得到所要结果。使用循环结构依次对字符进行处理,最后一个字符要单独处理。逆序排列采用的方法是:从两边向中间移动。数组中第一个字符与最后一个字符交换,第二个与倒数第二个交换,按照此规律直到中间一个或两个字符(数组中字符个数为奇数时,最后中间只有一个字符,否则有两个字符)。

阅读理解

阅读理解

                                                    Decision-making under Stress

     A new review based on a research shows that acute stress affects the way the brain considers the

advantages and disadvantages, causing it to focus on pleasure and ignore the possible negative (负面的)

consequences of a decision.

     The research suggests that stress may change the way people make choices in predictable ways.

     "Stress affects how people learn," says Professor Mara Mather. "People learn better about positive

than negative outcomes under stress."

     For example, two recent studies looked at how people learned to connect images(影像) with either

rewards or punishments. In one experiment, some of the participants were first stressed by having to give

a speech and do difficult math problems in front of an audience; in the other, some were stressed by

having to keep their hands in ice water. In both cases, the stressed participants remembered the

rewarded material more accurately and the punished material less accurately than those who hadn't gone

through the stress.

     This phenomenon is likely not surprising to anyone who has tried to resist eating cookies or smoking

a cigarette while under stress -at those moments, only the pleasure associated with such activities comes

to mind. But the findings further suggest that stress may bring about a double effect. Not only are

rewarding experiences remembered better, but negative consequences are also easily recalled.

     The research also found that stress appears to affect decision-making differently in men and women.

While both men and women tend to focus on rewards and less on consequences under stress, their

responses to risk turn out to be different.

     Men who had been stressed by the cold-water task tended to take more risks in the experiment

while women responded in the opposite way. In stressful situations in which risk-taking can pay off big,

men may tend to do better, when caution weighs more, however, women will win.

     This tendency to slow down and become more cautious when decisions are risky might also help

explain why women are less likely to become addicted than men: they may more often avoid making the

risky choices that eventually harden into addiction.

1. We can learn from the passage that people under pressure tend to ______.

A. keep rewards better in their memory

B. recall consequences more effortlessly

C. make risky decisions more frequently

D. learn a subject more effectively

2. According to the research, stress affects people most probably in their ______.

A. ways of making choices

B. preference for pleasure

C. tolerance of punishments

D. responses to suggestions

3.The research has proved that in a stressful situation, ______.

A. women find it easier to fall into certain habits

B. men have a greater tendency to slow down

C. women focus more on outcomes

D. men are more likely to take risks

单项选择题