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

●试题三 阅读下列程序说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 下面的

●试题三

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

【说明】

下面的程序功能的功能是以行为单位对字符串按下面的条件进行排序。排序条件为:从字符串中间一分为二,右边部分按字符的ASCⅡ值降序排序,排序后左边部分与右边部分进行交换。如果原字符串长度为奇数,则最中间的字符不参加排序,字符仍放在原位置上

例如:位置:0 1 2 3 4 5 6 7

源字符串:h g f e a b c d

则处理后字符串:d c b a h g f e

函数ReadDat()实现从文件in.dat中读取数据(每行字符串长度均小于80),函数WriteDat()把结果dat输出到文件out.dat中。

【程序】

#include<stdio.h>

#include<siring.h>

#include<conio.h>

char dat[20][80];

void jsSort()

{

int i,j,k,strl;

char ch;

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

{

strl=strlen(dat[i]);

for(j= (1) ;j<strl;j++)/*对后半部分的字符串进行排序*/

for(k=j+1;k<strl;k++)

if((2) )

{

ch=dat[i][j];

dat[i][j]=dat[i][k];

dat[i][k]=ch;

}

for(j=0; (3) j++)/*前后两部分进行交换*/

{

ch=dat[i][j];

dat[i][j]=dat[i][(strl+1)/2+j];

dat[i][(strl+1)/2+j]=ch;

}

}

}

void main()

{

readDat();

jsSort();

writeDat();

}

readDat()

{

FILE*in;

int i=0;

char*p;

(4) ;

while(i<20 && fgets(dat[i],80,in)!=NULL)

{

p=strchr(dat[i],"\n");

if(p)*p=0;

i++;

}

fclose(in);

}

writeDat()

{

FILE*out;

int i;

clrscr();

out=fopen("out.dat","W");

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

{

printf("%s\n",dat[i]);

printf((5) );

}

fclose(out);

}

查看答案
答案
收藏
如果结果不匹配,请 联系老师 获取答案
您可能会需要:
您的账号:,可能还需要:
您的账号:
发送账号密码至手机
发送
安装优题宝APP,拍照搜题省时又省心!
更多“●试题三 阅读下列程序说明和C代码,将应填入(n)处的字句写…”相关的问题
第1题
●试题八 阅读下列函数说明和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) ;

}

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

●试题三

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

【说明】

函数diff的功能是:根据两个由整数(都大于-32768)按升序构成的单链表L1和L2(分别由A,B指向)构造一个单链表L3(由*r指向),要求L3中的所有整数都是L1,并且不是L2中的整数,还要求L3中的所有整数都两两不等。

【函数】

#include<mallo

C.h>

typedef struct node{

int d;

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->d<B->d)

{

lastnum=A->d;

p=(Node*)malloc(sizeof(Node));

p->d=lastnum;

p->next=*r; (2) ;

do

A=A->next;

while((3) );

}

else if(A->d>B->d)

B=B->next;

else{

(4) ;

lastnum=A->d;

while (A && A->d==lastnum)A=A->next;

}

while(A)

{

lastnum=A->d;

p=(Node*)malloc(sizeof(Node));

p->d=lastnum;

(5) ;

*r=p;

while (A && A->d==lastnum) A=A->next;

}

}

点击查看答案
第3题
试题五(共15分)阅读下列说明和C++-代码,将应填入 (n) 处的字句写在答题纸的对应栏内。【说明】某发

试题五(共15分)

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

【说明】

某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。

试题五(共15分)阅读下列说明和C++-代码,将应填入 (n) 处的字句写在答题纸的对应栏内。【说明

【C++代码】

include <iostream>

using namespace std;

class invoice{

public:

(1) {

cout《 "This is the content of the invoice!"《 endl;

}

};

class Decorator : public invoice {

Invoice *ticket;

public:

Decorator(lnvoice *t) { ticket = t; }

void printinvoice(){

if(ticket != NULL)

(2);

}

};

class HeadDecorator : public Decorator{

public:

HeadDecorator(lnvoice*t): Decorator(t) { }

void printinvoice0 {

cout《 "This is the header of the invoice! "<< endl;

(3) ;

}

};

class FootDecorator : public Decorator{

public:

FootDecorator(invoice *t): Decorator(t) { }

void printlnvoice() {

(4) ;

cout《 "This is the footnote of the invoice!"《 endl;

}

};

int main(void) {

Invoice t;

FootDecorator f(&t);

HeadDecorator h(&f);

H.printlnvoice();

cout< < “_____”< < endl;

FootDecorator a(NULL);

HeadDecorator b((5) );

B.printinvoice();

return 0;

}

程序的输出结果为:

This is the header of the invoice!

This is the content of the invoice!

This is the footnote of the invoice!

----------------------------

This is the header of the invoice!

This is the footnote of the invoice!

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

●试题四

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

【说明】

函数QuickSort是在一维数组A[n]上进行快速排序的递归算法。

【函数】

void QuickSort(int A[],int s,int t)

{int i=s,j=t+1,temp;

int x=A[s];

do{

do i++;while (1) ;

do j--;while(A[j]>x);

if(i<j){temp=A[i]; (2) ; (3) ;}

}while(i<j);

A[a]=A[j];A[j]=x;

if(s<i-1) (4) ;

if(j+1<t) (5) ;

}

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

●试题三

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

【说明】

设有一个带表头结点的双向循环链表L,每个结点有4个数据成员:指向前驱结点的指针prior、指向后继结点的指针next、存放数据的成员data和访问频度freq。所有结点的freq初始时都为0。每当在链表上进行一次L.Locate(x)操作时,令元素值x的结点的访问频度freq加1,并将该结点前移,链接到现它的访问频度相等的结点后面,使得链表中所有结点保持按访问频度递减的顺序排列,以使频繁访问的结点总是靠近表头。

【函数】

void Locate(int &x)

{<结点类型说明>

*p=first->next;

while(p!=frist && (1) )P=P->next;

if (p!=first)/*链表中存在x*/

{ (2) ;

<结点类型说明>

*current=p;/*从链表中摘下这个结点*/

Current->prior->next=current->next;

Current->next->prior=current->prior;

P=current->prior;/*寻找重新插入的位置*/

While(p!=first && (3) )p=p->prior;

Current->next= (4) ;/*插入在P之后*?

Current->prior=P;

P->next->prior=current;

P->next= (5) ;

}

else printf("Sorry.Not find!\n");/*没找到*/

}

点击查看答案
第6题
●试题七 阅读以下说明和Java代码,将解答写入答题纸的对应栏内。 【说明】 下面程序的功能是找出

●试题七

阅读以下说明和Java代码,将解答写入答题纸的对应栏内。

【说明】

下面程序的功能是找出所有三位数中,个、十、百位数字的立方和等于该数本身的三位数并显示。在程序的每条横线处填写一个适当的词或语句,使程序的功能完整。

public (1) class cube_Root{

public static void (2) main(String args[]){

System.out.println("个、十、百位数字的立方和等于该数本身的三位数有:");

for(int n=100;n<1000;n++)

{

int a,b,c;

(3)

b=n/10%10;

(4)

if((5) )

System.out.println(n);

}

}

}

点击查看答案
第7题
●试题六 阅读以下说明和Java代码,将解答写入答题纸的对应栏内。【说明】 下面程序的功能是显示已

●试题六

阅读以下说明和Java代码,将解答写入答题纸的对应栏内。【说明】

下面程序的功能是显示已定义的一个3行3列的二维数组每行的元素,并求所有元素的和并输出。请在程序的每条横线处填写一个适当的语句,使程序的功能完整。

public class Array{

(1) static (2) main(String args[])

{

int sum=0;

int b[][]={{11,12,13},{21,22,23},{31,32,33}};

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

{

System.out.print("b["+i+"]: ");

for(int j=0; (4) j++)

{

System.out.print(b[i][j]+" ");

(5)

}

System.out.println();

}

System.out.println("sum="+sum);

}

}

点击查看答案
第8题
●试题五 阅读下列程序说明和C++代码,将应填入(n)处的字句写在答卷的对应栏内。 【说明】 ①在类体

●试题五

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

【说明】

①在类体中添加函数move(double ax, double ay)的定义,使得点的坐标x和y分别移动ax和ay个单位。

②在类定义外完成重载的两个构造函数CPosition()和CPosition(double dx, double dy),其中前者为不带参数的构造函数,使CPosition对象的默认值为x=0,y=0,后者为带参数的构造函数,把数据成员x和y分别初始化为参数dx和dy的值。

③完成函数double distance(double bx, double by)的定义,该函数返回*this和点(bx,by)的距离。

注意:除在指定的位置添加语句外,请不要改动程序中的其他语句。

源程序文件test5.cpp清单如下:

#include<iostream.h>

#include <math.h>

class CPosition

{

public:

CPosition();

CPosition(double dx, double dy);

double getx();

double gety();

(1)

double distance(double bx, double by);

private:

double x;

double y;

};

(2)

{

x=0; y=0;

}

CPosition::CPosition(double dx, double dy)

{

x=dx; y=dy;

}

double CPosition::getx()

{

return x;

}

double CPosition::gety()

{

return y;

}

double CPosition::distance(double bx, double by)

{

(3)

}

void main()

{

double a,b;

cout << "Input x, y position of a point: ";

cin >> a >> b;

CPosition psA(a, b);

cout << "Input x, y position of another point: ";

cin >> a >> b;

cout << "The distance is " << psA.distance(a,b) <<endl;

}

点击查看答案
第9题
试题六(共 15 分) 阅读以下说明和 C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。 [说明]

试题六(共 15 分)

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

[说明]

C++标准模板库中提供了 vector 模板类,可作为动态数组使用,并可容纳任意数据类型,其所属的命名空间为 std。vector模板类的部分方法说明如下表所示:

试题六(共 15 分) 阅读以下说明和 C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。

[C++代码]

include <iostream>

include <vector>

using namespace (1) ;

typedef vector< (2) > INTVECTOR;

const int ARRAY_SIZE = 6;

void ShowVector(INTVECTOR &theVector);

int main(){

INTVECTOR theVector;

// 初始化 theVector,将 theVector的元素依次设置为 0 至 5

for (int cEachItem = 0; cEachItem < ARRAY_SIZE; cEachItem++)

theVector.push_back((3) );

ShowVector(theVector); // 依次输出 theVector中的元素

theVector.erase(theVector.begin() + 3);

ShowVector(theVector);

}

void ShowVector(INTVECTOR &theVector) {

if (theVector.empty()) {

cout << "theVector is empty." << endl; return;

}

INTVECTOR::iterator (4) ;

for (theIterator = theVector.begin(); theIterator != theVector.end(); theIterator++){

cout << *theIterator;

if (theIterator != theVector.end()-1) cout << ", ";

}

cout << endl;

}

该程序运行后的输出结果为:

0, 1, 2, 3, 4, 5

(5)

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