问题 单项选择题

下面程序的功能是( )。
#include <iostream>
#include <string>
using namespace std;
int main ()

int i=1, n=0;
char s[80],*p;
p=s;
strcpy(p,"It is a book..");
for (; *p !=’ \0’ ;p++)

if(*p==’’)
i=0;
else if (i==0)
n++; i=1;

cout<<"n=" <<n<<end1;
return 0;

A.统计字符串中的单词个数

B.统计字符串中的空格个数

C.统计字符串中的字母个数

D.统计字符串中的全部字符个数

答案

参考答案:B

解析: 本题通过for循环对字符串进行扫描,遇到’\0’结束扫描。程序首先将i的值置为1,n的值置为0。在for循环中,通过if语句判断*p指向的字符是否为空格,如果是空格则将i的值置为0,而在else if语句,如果i的值为0,则n++,然后将i的值重新置为1。如此反复,最后统计出字符串中的空格个数。

填空题
问答题

Although Henry Ford’s name is closely associated with the concept of mass production,he should receive equal credit for introducing labor practices as early as 1913 that would be considered advanced even by today’s standards. Safety measures were improved, and the workday was reduced to eight hours, compared with the ten-or-twelve-hour day common at the time. In order to accommodate the shorter work day, the entire factory was converted from two to three shifts.
In addition, sick leaves as well as improved medical care for those injured on the job were instituted. (47)The Ford Motor Company was one of the first factories to develop a technical school to train specialized skilled laborers and an English language school for immigrants. Some efforts were even made to hire the handicapped and provide jobs for former convicts.
(48)The most widely acclaimed innovation was the five-dollar-a-day minimum wage that was offered in order to recruit and retain the best mechanics and to discourage the growth of labor unions. Ford explained the new wage policy in terms of efficiency and profit sharing. He also mentioned the fact that his employees would be able to purchase the automobiles that they produced—in effect creating a market for the product. (49)In order to qualify for the minimum wage, an employee had to establish a decent home and demonstrate good personal habits,including sobriety,thriftiness,industriousness,and dependability. (50)Although some criticism was directed at Ford for involving himself too much in the personal lives of his employees,there can be no doubt that,at a time when immigrants were being taken advantage of in frightful ways,henry Ford was helping many people to establish themselves in America.