软考中级

阅读以下说明和c++码,将应填入(n)处的字名写在的对应栏内。[说明] 以下函数完成求表达式的值,请填空使之完成此功能。float sum ( float x ){ float s=0.0;int sign = 1;(1);for(inti=1;(2); i+ +){t=t*x;s=s+(3);sign = - sign;(4);}

题目

阅读以下说明和c++码,将应填入(n)处的字名写在的对应栏内。

[说明] 以下函数完成求表达式

的值,请填空使之完成此功能。

float sum ( float x )

{ float s=0.0;

int sign = 1;

(1);

for(inti=1;(2); i+ +)

{

t=t*x;

s=s+(3);

sign = - sign;

(4);

}

如果没有搜索结果,请直接 联系老师 获取答案。
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

阅读下列说明和?C++代码,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
阅读下列说明和?Java代码,将应填入?(n)?处的字句写在答题纸的对应栏内。
【说明】
某快餐厅主要制作并出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种
类可能不同,但其制作过程相同。前台服务员?(Waiter)?调度厨师制作套餐。现采用生成器?(Builder)?模式实现制作过程,得到如图?6-1?所示的类图。






答案:
解析:

第2题:

试题三(共 15 分)

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


正确答案:

第3题:

阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。

[说明1]

函数void fun(char*w,char x,int*n)用来在w数组中插入x,w数组中的数已按由小到大顺序存放,n指存储单元中存放数组中数据的个数,插入后数组中的数仍有序。

[C函数1]

void fun(char*W,char x,int*n)

{ int i,P;

p=0;

w[*n]=x;

while(x>w[p]) (1) ;

for(i=*n,i>p;i--)w[i]=(2);

w[p]=x;

++*n;

}

[说明2]

函数void revstr(char*s)将字符串s逆置。例如:字符串“abcde”,经过逆置后变为“edcba”。

[C函数2]

void revstr(char*s)

{ char*p,c;

if(s==NULL)return;

p=(3); /*p指向字符串s的最后一个有效字符*/

while(s<p){ /*交换并移动指针*/

C=*s;

(4)=*p;

(5)=c;

}

}


正确答案:(1) p++ (2) w[i-1] (3) s+strlen(s)-1 (4) *s++或*(s++) (5) *p-或*(p--)
(1) p++ (2) w[i-1] (3) s+strlen(s)-1 (4) *s++或*(s++) (5) *p-或*(p--) 解析:函数1的fun()中的while循环是为了找到x的插入位置,因此(1)填“p++”,for循环是移动数组中的元素,因此(2)填“w[i-1]”。
对于函数2,设字符串的长度为n,则该函数的思想为将*(s+j)与*(s+n-1+i)对换,i=0....n/2。采用指针来实现,s为起始地址,p定位为最后一个字符的位置,所以空(3)应填“s+strlen(s)-1”;采用*s与*p交换后为s++与P--。即空(4)填“*s++”或“*(s++)”,空(5)填“*p-”或“*(p--)”。

第4题:

阅读以下说明和Visual Basic 码,将应填入(n)处的字名写在的对应栏内

[说明] 这是一个用户名校验程序,如用户名正确,即输出欢迎字样,否则,弹出警告窗并直接退出程序。下面是实现上述功能的程序,请填空。“Option Explicit”此语句的作用:强制显示声明

Dim UserName (2) As String

Dim Flag As Boolean

(1)

Private Sub Form. _ Load( )

UserName (0) = "AA": UserName (1) = "BB": UserName(2) = "CC"

Flag = False

inputName = InputBox( “请输入名称:“,”身份确认”“,”)

Dim i As Integer

For i = 0 To False

If inputName = UserName(i) Then

(2)

End If

Next i

If (3) Then

MsgBox “用户身份确失败!退出应用”, vbOKOnly, “警告”

End

End If

End Sub

Private Sub Form_ Paint( )

(4)

End Sub


正确答案:Dim inputName As String Flag = True Flag = False picShowMsg. Prin t “欢迎您!” + inputName
Dim inputName As String Flag = True Flag = False picShowMsg. Prin t “欢迎您!” + inputName

第5题:

阅读以下说明和C语言函数,将应填入(n)处的字句写在对应栏内。

[说明]

编写一个函数,输入为偶数时,调用函数求1/2+?/+…+1/n,当输入n为奇数时,调用函数1/1+1/3+…+1/n (利用指针函数)。

[函数]

include "stdio. h",

main()

{

float peven (),podd (),dcall ();

float sum;

int n;

while (1)

{

scanf("%d",&n);

if (n>1)

break;

}

if(n%2==0)

{

printf("Even="):

(1);

}

else

{

pfinff("Odd=");

(2);

}

printf("%f",sum);

}

float peven (int n)

{

float s;

int i

s=1;

for(i=2;i<=n;i+=2)

(3);

return (s);

}

float podd (n)

int n;

{

float s;

int i;

s=0;

for(i=1 i<=n;i+=2)

(4);

return (s);

}

float dcall(fp,n)

float (*fp) ();

int n;

{

float s;

(5);

returu (s);

}


正确答案:(1)array+10 (2)array+1 (3)*p>*max (4)k=*max (5)*p=array[0]
(1)array+10 (2)array+1 (3)*p>*max (4)k=*max (5)*p=array[0]

第6题:

阅读以下说明和C++码,将相应的文字填入(n)处,写在对应栏内。

[说明]

以下代码实现了对象引用作为函数参数,仔细阅读以下代码,分析运行结果,填入(n)处。

[代码]

include<iostream.h>

class Sample

{

int x,y;

public:

Sample() {x=y=0; }

Sample (int i, int j ) {x=i; y=j; }

void copy ( Sample &s ).,

void setxy ( int i, int j ) {x=i; y=j; }

void print ( {cout<<"x="<<x<<end1 ; cout <<"y="<<y<<end1;

};

void Sample: copy ( Sample &s )

{

X=S.X;

y=s.y;

}

void func ( Sample s1, Sample &s2 )

{

s1.setxy ( 10,20 );

s2.setxy ( 30,40 );

}

void main ( )

{

Sample p ( 1,2 ) ,q;

q.copy ( p );

time ( p,q );

p.print ( );

q.print ( );

}

运行结果

(1)

(2)

(3)

(4)


正确答案:(1)x=1 (2)v=2 (3)x=30 (4)y=40
(1)x=1 (2)v=2 (3)x=30 (4)y=40 解析:本题考查考生对C++面向对象语言的掌握程度和人工运算代码的能力。本题说明对象引用作为函数参数的作用。Sample类中的copy()成员函数进行对象拷贝。在main()中先建立对象p和q,p与q对象的x,y值相同,调用func( )函数,由于第2个参数为引用类型,故实参发生改变;而第1个参数不是引用类型,实参不发生改变。

第7题:

阅读以下说明和C语言函数,将应填入(n)处的字句写在对应栏内。

[说明]

完成以下中序线索化二叉树的算法。

[函数]

Typedef int datatype;

Typedef struct node {

Int ltag, rtag;

Datatype data;

*lchild,* rchild;

}bithptr;

bithptr pre;

void inthread ( p );

{if

{inthread ( p->lchild );

if ( p->lchild==unll ) (1);

if ( P->RCHILD=NULL) p->rtag=1;

if (2)

{if (3) pre->rchild=p;

if ( p->1tag==1 )(4);

}

INTHREAD ( P->RCHILD );

(5);

}

}


正确答案:(1) P->LTAG=0 (2) (PRE) (3) (PRE->RTAG==1) (4) P->LCHILD=PRE (5) PRE=P
(1) P->LTAG=0 (2) (PRE) (3) (PRE->RTAG==1) (4) P->LCHILD=PRE (5) PRE=P

第8题:

阅读以下说明及Visual Basic程序代码,将应填入(n)处的字句写在对应栏内。

【说明】

以下程序为求行列式X(5,5)的值S。

【Visual Basic代码】

Private Function col ( byval x ( 5,5 ) as integer ) as long

dim fesult as long

dim temp as long

dim I as integer

dim j as integer

dim k as imeger

result = 0

for I = to 5

(1)

for j = 1 to 5

if I+j>6 then

k= ( 1+j ) mod 5

else

k=1

endif

temp=temp*x ( k,j )

(2)

result=(3)

(4)

(5)

End function


正确答案:(1)temp=1 (2) next I (3) result+temp (4) next I (5) col=result
(1)temp=1 (2) next I (3) result+temp (4) next I (5) col=result

第9题:

函数 void fun(float *sn, int n)的功能是:根据以下公式计算S,计算结果通过形参指针sn传回;n通过形参传入,n的值大于等于0。请填空。

void fun( float *sn, int n)

{ float s=0.0, w, f=-1.0;

int i=0;

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

{ f=( )* f;

w=f/(2*i+1);

s+=w; }

( )=s;}


正确答案:
-1;*sn