题目详情
当前位置:首页 > 计算机考试 > 中级软件设计师
题目详情:
发布时间:2023-10-05 08:24:59

[填空题][说明] 设计一个普通函数distance (Point &p1,Point &p2),用于计算p1和p2点之间的距离。本程序执行结果如下:(2,2)与(5,5)之间距离=4.24264 # include < iostream. h > # include < math. h > class Point { int x, y; public: Point(int i, int j) { (1) int getx( ) { return x;} int gety( ) { return y; } void disp( ) { (2) } }; float distance( Point &p1, Point &p2 ) { float d; (3) return d; } void main( ) { (4) p1. disp ( ); cout < <“与”; p2. diap( ); cout< <“之间距离=” < <distance (p1,p2) < <end1; }

更多"[说明] 设计一个普通函数distance (Point &p1,Po"的相关试题:

[填空题]将关键字const写在函数头之后,函数体之前,说明该函数是一个const成员函数。此时const不是指定函数的返回值,而是修饰______指针。
[填空题]阅读以下函数说明和C语言函数,将应填入 (n) 处的字句写在对应栏内。
[说明]
这是一个模拟渡口管理的算法。某汽车轮渡口,过江渡船每次能载10辆车过江。过江车辆分为客车类和火车类,上船有如下规定:同类车先到先上船,客车先于货车上渡船,且每上4辆客车,才允许上一辆货车;若等待客车不足4辆,则以货车代替,若无货车等待则允许客车都上船。
程序中用到的函数有enqueue(queue*sq,elemtype*x)在队列sq中入队一个元素x;outqueue(queue*sq,elemtype*x)在队列sq中出队一个元素,并将其值赋给x;empty(queue*sq)判断队列sq是否为空队,若为空,返回1;否则返回0。
[C程序]
#include<stdio.h>
void pass( )
queue bus,truct; /*bus表示客车队列,truck表示货车队列*/
char ch;
int n,tag; /* ]n为车号,tag为标志,tag=0表示客车,tag=1表示货车*/
intcount=0,countbus=0,counttruck=0; /*分别表示上渡船汽车数、客车数、货车数*/
while(1)
printf("输入命令: /n");
Scanf("%c",&ch);
switch(ch)
case’e’:
case’E’: printf("车号: /n");
Scanf("%d",&n);
printf("客车/货车(0/1): /n");
scanf("%d",&tag);
if( (1) )
enqueue(&bus,n);

[填空题]阅读以下函数说明和C语言函数,将应填入 (n) 处的字句写在对应栏内。
[说明]
设一个环上有编号为0~n-1的n粒颜色不尽相同的珠子(每粒珠子颜色用字母表示,n粒珠子的颜色由输入的字符串表示)。从环上的某两粒珠子间剪开,则环上珠子形成一个序列然后按以下规则从序列中取走珠子:首先从序列左端取走所有连续的同色珠子;然后从序列右端在剩下的珠子中取走所有连续的同色珠子,两者之和为该剪开处可取走珠子的粒数。在不同位置剪开,能取走的珠子也不尽相同。
本程序所求的是在环上哪个位置剪开,按上述规则可取走的珠子粒数最多。程序中用数组存储字符串。例如:10粒珠子颜色对应字符串为“aaabbbadcc”,在0号珠子前剪开,序列为aaabbbadcc,从左端取走3粒a色珠子,从右端取走2粒c色珠子,共取走5粒珠子。若在3号珠子前剪开,即bbbadccaaa,共取走6粒珠子。
[C函数]
int count(char*s,int start,int end)
{inti,c=0,color=s[start],step=(start>end)-1:1;
for(i=start;s[i]==color;i+=step){
if(step>0 && i>end || (1) ) break;
(2) ;
}
return c;
}
void main( )
{ char t,s[120];
int i,j,C,len,maxc,cut=0;
printf("请输入环上代表不同颜色珠子字符串:");
scanf("%s",s );
len=strlen(s);
for(i=maxc=0;i<len;i++){ /*尝试不同的剪开方式*/
c=count(s,0,len-1);
if(c<len) C+=count( (3) );
if(c>maxc){cut=i;maxc=c; )
/*数组s的元素循环向左移动一个位置<
[填空题]阅读以下函数说明和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;
}
}
[填空题]阅读以下函数说明和C语言函数,将应填入 (n) 处的字句写在对应栏内。
[说明1]
函数int factors(int n)的功能是判断整数n(n>=2)是否为完全数。如果n是完全数,则函数返回0,否则返回-1。
所谓“完全数”是指整数n的所有因子(不包括n)之和等于n自身。例如:28的因子为1,2,4,7,14,而28=1+2+4+7+14,因此28是“完全数”。
[C函数1]
int factors(int n)
int i,S;
for(i=l,s=0;i<=n/2;i++)
if(n%i==O) (1) ;
if( (2) )return 0;
rerurn -1;

[说明2]
函数int maxint(int a[],int k)的功能是用递归方法求指定数组中前k个元素的最大值,并作为函数值返回。
[C函数2]
int maxint(int a[],int k)
int t;
if( (3) )return (4) ;
t=maxint(a+1, (5) )j
return(a[0]>t) a[0] :t;

[填空题]阅读以下函数说明和C语言函数,将应填入 (n) 处的字句写在对应栏内。
[说明]
函数void diff(Node*A,Node*B,Node**r)的功能是:根据两个由整数按升序构成的单链表L1和L2(分别由A,B指向)构造一个单链表L3(由*r指向),要求L3中的所有整数都是L1,并且不是L2中的整数,还要求L3中的所有整数都两两不等。
[C函数]
#include<malloc.h>
typedef struct node {
int data;
struct node*next;
}Node;
void diff(Node*A,Node*B,Node**r)
{ int lastnum;
Node*P;
*r=NULL;
if(!A) return;
while( (1) >
if(A->data<B->data)
{lastnum=A->data;
p=(Node*)malloc(sizeof(Node));
P->data=lastnum;
P->next=*r;
(2) ;
do
A=A->next;
while( (3) >;
}
else iffA->data>B->data)
B=B->next;
else{
(4) ;
lastnum=A->data;
while (A &&A->data==lastnum)A=A->next;
}
while(A){
lastnum=A->data;
p=(Node*)malloc(sizeof(Node));

[填空题]
阅读以下函数说明和C语言函数,将应填入 (n) 的字句写在答题纸的对应栏内。
[说明1]
函数int fun1(int m, int n)的功能是:计算并返回正整数m和n的最大公约数。
[函数1]
int fun1(int m, int n)
{
while ( (1) ) {
if (m>n) m=m-n;
else n=n-m;
}
(2) ;
}
[说明2]
函数long fun2(char*str)的功能是:自左至右顺序取出非空字符串str中的数字字符形成一个十进制整数(最多8位)。
例如,若字符串str的值为“f3g8d5.ji2e3p12fkp”,则函数返回值为3852312。
[函数2]
long fun2(char *str)
{
int i=0;
long k=0;
char *p=str;
while (*p!=’\0’ && (3) ) {
if (*p>=’0’ && *p<=’9’) {
k= (4) + *p - ’0’;
++i;
}
(5) ;
}
return k;
}


[填空题][说明] 编写一个函数,输入为偶数时,调用函数求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); }
[简答题]

阅读下列函数说明和C函数,将应填入▁处的字句写在答题纸的对应栏内。
[函数5说明]
  函数DeleteNode(Bitree *r,int e)的功能是:在树根结点指针为r的二叉查找(排序)树上删除键值为e的结点,若删除成功,则函数返回0,否则函数返回-1。二叉查找树结点的类型定义为:
  typedef struct Tnode{
    int data; /*结点的键值*/
    struct Tnode *Lchild,*Rchild; / * 指向左、右子树的指针 * /
     }*Bitree;
在二叉查找树上删除一个结点时,要考虑三种情况:
①若待删除的结点p是叶子结点,则直接删除该结点;
②若待删除的结点p只有一个子结点,则将这个子结点与待删除结点的父结点直接连接,然后删除结点p;
③若待删除的结点p有两个子结点,则在其左子树上,用中序遍历寻找关键值最大的结点s,用结点s的值代替结点p的值,然后删除结点s,结点s必属于上述①、②情况之一。[函数5]
int DeleteNode(Bitree *r,int e){
Bitree p=* r,pp,s,c;
while( (1) ){/ * 从树根结点出发查找键值为e的结点 * /
pp=p;
if(e<p->data) p=p->Lchild;
else p=p->Rchild
}
if(! p)return-1;/ * 查找失败 * /
if(p->Lchild && p->Rchild){/ * 处理情况③ * /
s= (2) ;pp=p;
while( (3) ){pp=s;s=s->Rchild;}
p->dara=s->data;P=s;
}
/ * 处理情况①、② * /
if( (4) )c=p->Lchild;
else c=p->Rchild
if(p==*r) *r=c;

[简答题]试写出能够将一个子函数的数据加工的结果回传给调用函数的方式有几种,分别说明。
[填空题][说明] 编写一个函数根据用户输入的偶对(以输入。表示结束)建立其有向图的邻接表。一个图的邻接表存储结构定义如下:
# include < stdio. h >
# define MAXVEX 30
struct edgenode

int adjvex;
char info;
struct edgenode * next;

struct vexnode

char data;
struct edgenode * link;

typedef struct vexnode adjlist [MAXVEX];
实现要求的函数如下:
void creatadjlist ( adjlist g)

int i, j, k;
street vexnode * s;
for( k=1; k< =n; k+ +)

(1)
g [k]. link = NULL;

printf ( “输一个对:” );
scanf ("%d, %d", &i, &j);
while (2)

(3)
s- >adjvex =j;
(4)
g [i].link =s;
(5)


[填空题]

阅读以下说明和C函数,填充函数中的空缺,将解答填入答题纸的对应栏内。

【说明】

函数GetDateld(DATE date)的功能是计算并返回指定合法日期date是其所在年份的第几天。例如,date表示2008年1月25日时,函数的返回值为25,date表示2008年3月3日时,函数返回值为63。

函数Kday_Date(int theyear,int k)的功能是计算并返回指定合法年份theyear(theyear≥1900)的第k天(1≤k≤365)所对应的日期。例如,2008年的第60天是2008年2月29日,2009年的第60天是2009年3月
1日。

函数isLeapYear(int y)的功能是判断Y代表的年份是否为闰年,是则返回1,否则返回0。

DATE类型定义如下:

typedef struct{
int year,month,day;
}DATE;
【C函数1】
int GetDateId(DATE date)
{
Const int days_month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int i,date_id=date.day;
for(i=0;i<____(1)____;i++)
date_id+=days_month[i];
if( ____(2)____&&isLeapYear(date.year))date_id++;
return date_id;
}
【C函数2】
____(3)____Kday_Date(int theyear,int k)
{
int i;
DATE date;
int days_month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31);
assert(k>=1&&k<=365&&theyear>=1900);/*不

我来回答:

购买搜题卡查看答案
[会员特权] 开通VIP, 查看 全部题目答案
[会员特权] 享免全部广告特权
推荐91天
¥36.8
¥80元
31天
¥20.8
¥40元
365天
¥88.8
¥188元
请选择支付方式
  • 微信支付
  • 支付宝支付
点击支付即表示同意并接受了《购买须知》
立即支付 系统将自动为您注册账号
请使用微信扫码支付

订单号:

请不要关闭本页面,支付完成后请点击【支付完成】按钮
恭喜您,购买搜题卡成功
重要提示:请拍照或截图保存账号密码!
我要搜题网官网:https://www.woyaosouti.com
我已记住账号密码