问题 问答题

请编写一个函数unsigned short fun(unsigned short s)。其中s是一个大于10的无符号整数,若s是一个n(n≥2)位整数,函数求出s的n位数之和作为函数的返回值。 例如,s值为4315,则函数返回13。s值为13函数,则返回4。注意:部分源程序已存在文件PROC15.cpp中。 请勿修改主函数和其他函数中的任何内容,仅在函数fun()的花括号中填写若干语句。 文件PROC15.cpp的内容如下: //PROC15.cpp #include<iostream> using namespace std; unsigned short fun(unsigned short s); int main() { unsigned short a; cout<<"Enter a unsigned short integer number:"; cin>>a; if(a<10)cout<<"Data error!"; elsecout<<"The result: "<<fun(a)<<end1; return 0; } unsigned short fun(unsigned short s) { //* * * * * * }

答案

参考答案:

解析:函数fun()的定义如下: unsigned short fun(unsigned short s) { int a[5],i,sum=0; for(i=0;i<5;i++) { a[i]=(iht)(s/10000); s=s%1000000*10; sum+=a[i]; } return (sum); } fun()函数的功能是将一个数的各位值相加并返回相加的值。所以本题的重点是如何将各位上的数字求出来。本题可以采用穷举法计算,也可用类型转换法,即将这个数分别除以10000、1000、100、10(这是因为unsigned short类型的数不管在16位系统还是32位系统中,它总是占2个字节,其最大值为5位数65535),然后转化为int类型相加即可。

单项选择题 A3/A4型题
阅读理解

       Could you imagine your parents choosing your husband or wife for you? And can you imagine not setting eyes on him or her until your wedding day? This situation is common in India, the Middle East and many parts of Africa.Marriage customs around the world often differ from our own.We don’t realize that people in other places often get married in very different ways and with different motives.

In many countries, marriage is a practical matter.A marriage provides a safe and stable home for the husband and wife.It also joins two families, which benefits the couple’s parents and makes them happy.Marriage also brings children, making sure the couple will be taken care of in old age.Because a marriage is important for the whole family, some cultures don’t let young people choose whom to marry.

Just as there are many different reasons for marriage, there are also many different wedding rituals.Every culture has its own ways of bringing good luck to the happy couple.In a typical Western wedding, the bride seeks good luck by wearing “something old, something new, something borrowed and something blue”.Something old represents the past.Something new represents success in the future.Something borrowed reminds the bride she can get help from her friends and family.And something blue reminds her to be true to her husband.

In Poland, one wedding tradition is not only lucky, but also very practical.The wedding guests pin money to the bride’s dress while she is dancing.The money is meant to bring luck and to help the young couple build their new life.In Bermuda, the young couple plants a tree in the yard of their new home.Once they move in, they take good care of the tree and make it grow.The planting of the tree is a good metaphor(比喻) for marriage.A truly good marriage is something that grows with care.

小题1:Which of the following statements does NOT support the idea that marriage is a practical matter?

A.The couple may have a safe home through their marriage.

B.The parents had better help their children choose whom to marry.

C.A marriage benefits the couple’s parents and makes them happy.

D.A marriage brings children who will take care of the couple when they are old.小题2:The underlined word “rituals” (Para.3) means   

A.forms 

B.customs

C.traditions 

D.ceremonies小题3:Although cultures differ in different countries, one thing in common when a young couple gets married is that   

A.people wish them to take care of each other

B.people wish them to get practical benefits from the marriage

C.people wish them to have good luck in their new life

D.people wish them to make money at the wedding ceremony小题4:Which of the following statements best summarizes(总结) the subject of this passage?

A.People across the world get married in different ways and for different reasons.

B.Every culture has its own ways of bringing good luck to the young couple.

C.A truly good marriage is something that grows with care.

D.In many countries, marriage is a practical matter.