首页 > 软考
题目内容 (请给出正确答案)
[主观题]

阅读以下说明和C程序,将填入(n)处的字句在对应栏内。 [说明] 某旅游服务应用程序运行时,根据输入

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

[说明]

某旅游服务应用程序运行时,根据输入的两个城市名查找其问的距离。各城市问的距离如表4-1所示。表格中的第一行和第一列表示城市名,表中的每个元素是一个整数,代表该元素所在行和列对应的城市之间的距离(单位:km)。

表4-1

阅读以下说明和C程序,将填入(n)处的字句在对应栏内。 [说明] 某旅游服务应用程序运行时,根据输入

在程序中,城市名用一维全局数组cityTable存储,城市之间的距离矩阵用二维全局数组kmTable表示,并用相应的值对这两个数组进行初始化。

define NCities 8 /*城市个数*/

define TRUE 1

static char * cityTable[NCities]={ /*城市名按字典序升序排列*/

"Beijing",

…… /*其他城市名略去*/

"Sanya",

};

StatiC int kmTable[NCities][NCities]={

{0, 1697, 2695, 937, 1784, 1356, 926, 2543},

{1697, 0, 313, 1840, 533, 940, 1409,1505},

…… /*剩余元素的初始值略去*/

};

程序执行时,首先按提示输入两个城市名,然后在cityTable中查找与城市名对应的下标,最后用该下标在kmTable中找到这两个城市之间的距离。

程序中定义的函数FindCitylnSortedArray和GetCity说明如下:

(1)函数FindCitylnSortedArray的功能是用二分查找法在全局数组cityTable中查找城市名所对应的下标值。

(2)函数GetCity的功能是读入城市名,调用函数FindCityInSortedArray来获取城市所对应的下标值。如果该城市名不存在,则提示用户重新输入。

[C程序]

int main() {

int city1,city2;

city1=GetCity("输入第1个城市名:");

city2=GetCity("输入第2个城市名:");

printf("%S和%s之间的距离为:%d km.\n”,cityTable[city1],

cityTable[city2],

kmTable[cityl][city2]);

return 0;

}

StatiC int GetCity(char * prompt) {

char * CityName;

int index;

cityName=(char *)malloc(20*sizeof(char));

while(TRUE){

printf("%S",prompt);

gets(cityName); /*获取输入字符串*/

index=FindCityInSortedArray(cityName);

if((1) ________ )break;

printf("城市名不存在,请重新输入。\n");

}

free(cityName);

return (2)__________;

}

Static int FindCityInSortedArray(char * key) {

int lh, rh, mid, cmp;

lh=0;

rh=NCities-1;

while((3)________){

mid=(1h+rh)/2;

cmp=strcmp((4)______ ); /*比较两个城市名是否相同*/

if(cmp==0)return (5)_______; /*两个城市名相同*/

if(cmp<0){rh=mid-1;)

else {lh=mid+1;)

}

return (-1); /*城市名不存在时返回-1 */

}

查看答案
答案
收藏
如果结果不匹配,请 联系老师 获取答案
您可能会需要:
您的账号:,可能还需要:
您的账号:
发送账号密码至手机
发送
安装优题宝APP,拍照搜题省时又省心!
更多“阅读以下说明和C程序,将填入(n)处的字句在对应栏内。 [说…”相关的问题
第1题
阅读以下说明和C++码,将应填入(n)处的字名写在对应栏内。 从下列的3道试题(试题五至试题七)中任选

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

从下列的3道试题(试题五至试题七)中任选1道解答。

如果解答的试题数超过1道,则题号小的1道解答有效。

[说明] 编写程序,把从键盘上输入的一批整数(以-1作为终止输入的标志)保存到文本文件“a: xxk1. dat”中。

(1)

include <fstream. h >

include < stdlib. h >

void main () {

(2)

if (! four) {

cerr < <“文件没有找开!” < <end1;

exit (1);

}

int x;

cin > >x;

while((3)){

(4)

cin> >x;

}

(5)

}

点击查看答案
第2题
阅读以下说明及Visual Basic程序代码,将应填入(n)处的字句写在对应栏内。 【说明】 以下程序为求行

阅读以下说明及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

点击查看答案
第3题
阅读以下说明和Java程序,将应填入(n)处的字句写在对应栏内。 [说明] 下面程序实现十进制向其它

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

[说明]

下面程序实现十进制向其它进制的转换。

[Java程序]

ClasS Node{

int data;

Node next;

}

class Transform{

private Node top;

public void print(){

Node p;

while(top!=null){

P=top;

if(P.data>9)

System.out.print((char)(P.data+55));

else

System.out.print(p.data);

top=p.next;

}

}

public void Trans(int d,int i){//d为数字;i为进制

int m;

(1) n=false;

Node p;

while(d>0){

(2);

d=d/i;

p=new Node();

if((3) ){

p.data=m;

(4);

top=P;

n=true;

}

else{

p.data=m;

(5);

top=P;

}

}

}

}

点击查看答案
第4题
●试题八 阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 以下程

●试题八

阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。

【说明】

以下程序的功能是:从键盘上输入一个字符串,把该字符串中的小写字母转换为大写字母,输出到文件test.txt中,然后从该文件读出字符串并显示出来。

【程序】

#include<stdio.h>

main()

{FILE*fp;

charstr[100];inti=0;

if((fp=fopen("text.txt" (1) ))==NULL)

{printf("can't open this file.\n");exit(0);}

printf("input astring:\n");gest(str);

while(str[i])

{if(str[i]>=′a′ && str[i]<=′z′)

str[i]= (2) ;

fputc(str[i], (3) );

i++;

}

fclose(fp);

fp=fopen("test.txt", (4) );

fgets(str,100,fp);

printf("%s\n",str);

(5) ;

}

点击查看答案
第5题
阅读以下说明、Java代码,将应填入(n)处的字句写在对应栏内。【说明】 本程序输出10000之内的所有完全

阅读以下说明、Java代码,将应填入(n)处的字句写在对应栏内。

【说明】

本程序输出10000之内的所有完全数。完全数是指等于其所有因子和(包括1,但不包括这个数本身)的数。例如:6=1×2×3,6=1+2+3,则6是一个完全数。

【程序】

public class PerfectNum

{

Public static void main(String args[])

{

int count=1;

for(int i=1; i<10000; i++)

{

int y=0;

for(int j=1; j<i; j++)

if((1))

y=(2)

if((3))

{

System.out.print((4) +String.valueOf('\t'));

(5)

If(count%3==0)

System.out.printin();

}

}

}

点击查看答案
第6题
阅读以下说明和C语言函数,将应填入(n)处的字句写在对应栏内。【说明】 下面的程序构造一棵以二叉链

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

【说明】

下面的程序构造一棵以二叉链表为存储结构的二叉树算法。

【函数】

BTCHINALR *createbt (BTCHINALR *bt )

{

BTCHINALR *q;

struct node1 *s [30];

int j,i;

char x;

printf ("i,x =" ); scanf ("%d,%c",&i,&x );

while (i!=0 && x!='$')

{ q = (BTCHINALR* malloc (sizeof (BTCHINALR )); //生成一个结点

(1);

q->1child = NULL;

q->rchild = NULL;

(2);

if((3);)

{j=i/2 //j为i的双亲结点

if(i%2==0

(4) //i为j的左孩子

else

(5) //i为j的右孩子

}

printf ("i,x =" ); scanf ("%d,%c",&i,&x ); }

return s[1]

}

点击查看答案
第7题
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。[说明] 本程序中预设了若干个用户名和

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

[说明]

本程序中预设了若干个用户名和口令。用户输入正确的用户名后,可以查找对应的口令,一旦输入结束标记“end”,程序结束。

[C++程序]

include <iostream. h>

include <string. h>

class User

{ protected:

char user[10];

char pass[7];

public:

User(char[ ],char[]);

(1) {return user;}

(2) {return pass;}

};

User::User(char u[],char p[])

{ strcpy(user,u);

strcpy(pass,p); }

void main()

{ User ua[]={User("Li","123456"),User("wang","654321"),User("Song","666666")

char name[10];

while(1)

cout< < "输入用户名:";

cin> >name;

if((3)= =0) break;

for(int i=0;i<3;i+ +)

if(strcmp(name,ua[i].getuser()) = =0){

cout< <"密码:" < < ua[i].getpass() < <endl;

(4);

if((5))cout< <"该用户不存在!" < <endl;

}

}

点击查看答案
第8题
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。 [说明] 下面程序实现十进制向其它进

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

[说明]

下面程序实现十进制向其它进制的转换。

[C++程序]

include"ioStream.h"

include"math.h"

include

typedef struct node {

int data;

node*next;

}Node;

Class Transform.

{

DUDlic:

void Trans(int d,int i); //d为数字;i为进制

void print();

private:

Node*top;

};

void Transform.:Trans(int d,int i)

{

int m,n=0;

Node*P;

while(d>0)

{

(1);

d=d/i;

p=new Node;

if(!n){

p->data=m;

(2);

(3);

n++;

}

else{

p->data=m;

(4);

(5);

}

}

}

void Transform.:print()

{

Node*P;

while(top!=NULL)

{

p=top;

if(p->data>9)

cout<<data+55;

else

cout<<data;

top=p->next;

delete p;

}

}

点击查看答案
第9题
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【说明】 字符串在程序设计中扮演着重要

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

【说明】

字符串在程序设计中扮演着重要角色。现需要设计字符串基类string,包含设置字 符串、返回字符串长度及内容等功能。另有一个具有编辑功能的串类edlt_string,派生于string,在其中设置一个光标,使其能支持在光标处的插入、删除操作。

【程序】

include <iostream.h>

include <stdio.h>

include <string.h>

class string

{

int length;

char *data;

public:

int get_length() {return length;}

char *get_data() {return data;}

~string() {delete data;}

int set data(int in_length, char *in_data);

int set_data(char *data);

void print() {cout<<data<<endl;}

};

class edit_string: public string

{

int cursor;

public:

int get_cursor() {return cursor;}

void move_cursor(int dis) {cursor=dis;}

int add_data(string *new_data);

void delete_data(int num);

};

int string::set_data(int in_length,char *in_data)

{

length=in_length;

if(!data)

delete data;

(1)

strcpy(data,in_data);

return length;

}

int string::set data(char *in_data)

{

(2)

if(!data)

delete data;

(1)

strcpy(data,in_data);

return length;

}

int edit_string::add_data(string *new_data)

{

int n,k,m;

char *cp,*pt;

n=new_data->get_length();

pt=new_data->get_data();

cp=this->get_data();

m=this->get_length();

char *news=new char[n+m+1];

for(int i=0; i<cursor; i++)

news[i]=cp[i];

k=i;

for(int j=0; j<n; i++,j++)

news[i]=pt[j];

cursor=i;

for(j=k; j<m; j++,i++)

(3)

news[i]='\0';

(4)

delete news;

return cursor;

}

void edit string::delete_data(int num)

{

int m;

char *cp;

cp=this->get_data();

m=this->get_length();

for(int i=cursor; i<m; i++)

(5)

cp[i]='\0';

}

点击查看答案
第10题
阅读以下说明和C++ 程序,将应填入(n)处的字句写在对应栏内。 [说明] 试从含有n个int 型数的数组中

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

[说明]

试从含有n个int 型数的数组中删去若干个成分,使剩下的全部成分构成一个不减的子序列。设计算法和编写程序求出数组的不减子序列的长。

[C++ 程序]

include<stdio.h>

define N 100

int b[]={9,8,5,4,3,2,7,6,8,7,5,3,4,5,9,1};

int a [N];

define n sizeofb/sizeofb[0]

void main ()

{

kit k,i,j;

(1)

(2)

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

{

for (j=k;(3); j--);

(4); /*长为 j+1 的子序列的终元素存储在 a[j+1]*/

if ((5)k++; /*最长不减子序列长 k 增1*/

}

printf ("K = %d\n ",k );

}

点击查看答案
第11题
阅读以下说明、Java代码和HTML文档,将应填入(n)处的字句写在对应栏内。【说明】 当用户启动html浏览

阅读以下说明、Java代码和HTML文档,将应填入(n)处的字句写在对应栏内。

【说明】

当用户启动html浏览器并首次打开下面的html文档时,Java Applet小程序在显示面板上显示字符串“欢迎您!”;当html页面被其他窗口遮挡后再次显示时,小程序在显示面板上显示“欢迎您回来!”

[Java代码]

import java.awt.*;

import java.applet.*;

public class HelloApplet extends (1) {

public void paint((2) ){

g.drawString(message,10,20);

message="欢迎您回来!";

}

public void (3) (){

message="欢迎您!";

}

private (4) message;

}

[HTML文档]

<html>

<head>

<title>HTML Test HelloApplet Page</title>

</head>

<body>

Test HenoApplet 小程序<br>

<applet

codebase="."

code="(5)"

name="TestApplet"

width="400"

height="300"

</applet>

</body>

</html>

点击查看答案
退出 登录/注册
发送账号至手机
密码将被重置
获取验证码
发送
温馨提示
该问题答案仅针对搜题卡用户开放,请点击购买搜题卡。
马上购买搜题卡
我已购买搜题卡, 登录账号 继续查看答案
重置密码
确认修改