题目详情
当前位置:首页 > 计算机考试 > 中级软件设计师
题目详情:
发布时间:2023-10-09 06:49:23

[多项选择]阅读下列程序说明和C程序,将应填入 (n) 处的字句写在答卷纸的对应栏内。
【程序说明】
该程序定义了两个子函数strsort和strmerge。它们分别实现了将一个字符串按字母顺序排序和将两个字符串合并排序,并删去相同字符。在主函数里,先输入两个字符串s1和s2,然后调用strsort函数对它们分别排序,然后调用strmerge函数将s1和s2合并,将合并后的字符串赋给字符串s3,最后输出字符串s3。
【程序】
#include <stdio.h>
void strmerge(char *a,char *b,char *c) //将字符串a,b合并到字符串c

char t,*w;
W=c;
while( (1) )

//找到字符串a,b当前字符中较小的字符
if(*a<*b)

t=-*a,
(2)

else if(*a>*b)

t=*b;
(3)

else //字符串a,b 当前字符相等

t=-*a;
a-H-;
b-H-;

if( (4) ) //开始,可直接赋值
*w=t;
else if(t!=*w)
//如果a,b中较小的当前字符与c中当前字符不相等,才赋值
(5)

if(*a!=’/O’) //如果字符串a还没有结束,则将a的剩余部分赋给c
while(*a!=’/0’)
if(*a!=*w)

*(++w)=*a;
a++;

else
(6)
if(*b!=",’

更多"阅读下列程序说明和C程序,将应填入 (n) 处的字句写在答卷纸的对应栏"的相关试题:

[简答题]试题八(15 分,每空3 分) 阅读以下说明和C++程序,将应填入 (n) 处的字句写在答题纸的对应栏内。 [说明] 下面程序的功能是计算并输出某年某月的天数。 [C++程序] #include using namespace std; (1) Month{Jan, Feb, Mar, Apr,May,Jun, Jul, Aug, Sep,Oct,Nov,Dec}; class Date{ public: Date(int year, Month m_month){ (2) = year; if(m_month< Jan || m_month > Dec) month = Jan; else month = m_month; }; ~Date( ){}; bool IsLeapYear( ){ return ((year % 4 == 0 && year % 100 != 0) || year % 400 ==0); }; int CaculateDays( ){ switch( (3) ){ case Feb:{ if( (4) ) return 29; else return 28; } case Jan: case Mar: case May: case Jul: case Aug: case Oct: case Dec: return 31; case Apr: case Jun: case Sep: case Nov: return 30; } }; private: int year; Month month; }; void main( ){ Date day(2000,Feb); cout << day. (5) ( ); }
[简答题]阅读下列程序说明和C程序,将应填入 (n) 处的字句写在答卷纸的对应栏内。 【程序说明】 该程序定义了两个子函数strsort和strmerge。它们分别实现了将一个字符串按字母顺序排序和将两个字符串合并排序,并删去相同字符。在主函数里,先输入两个字符串s1和s2,然后调用strsort函数对它们分别排序,然后调用strmerge函数将s1和s2合并,将合并后的字符串赋给字符串s3,最后输出字符串s3。 【程序】 #include <stdio.h> void strmerge(char *a,char *b,char *c) //将字符串a,b合并到字符串c { char t,*w; W=c; while( (1) ) { //找到字符串a,b当前字符中较小的字符 if(*a<*b) { t=-*a, (2) } else if(*a>*b) { t=*b; (3) } else //字符串a,b 当前字符相等 { t=-*a; a-H-; b-H-; } if( (4) ) //开始,可直接赋值 *w=t; else if(t!=*w) //如果a,b中较小的当前字符与c中当前字符不相等,才赋值 (5) } if(*a!=’/O’) //如果字符串a还没有结束,则将a的剩余部分赋给c while(*a!=’/0’) if(*a!=*w) { *(++w)=*a; a++; } else (6) if(*b!=",’/0’) //如果字符串b 还没有结束,则将 b 的剩余部分赋给 c while(*b !=’/0’) if(*b!=*w) { *(++w)=*b; b++; }
[简答题]
阅读以下程序说明和C程序,将应填入(n)处的字句,写在对应栏内。
【程序说明】
某网络由n个端点组成,这些端点被物理地分成若干个分离的端点组。同一组内的两件端点i和j,它们或直接相连,或间接相连(端点i和端点j间接相连是指在这两件端点之间有一个端点相连序列,其中端点i和j分别与这相连序列中的某个端点直接相连)。网络的n个端点被统一编号为0,1,…,n-1。本程序输入所有直接相连的端点号对,分别求出系统各分离端点组中的端点号并输出。
程序根据输入的直接相连的两件端点号,建立n个链表,其中第i个链表的首指针为s[i],其结点是与端点i直接相连的所有端点号。
程序依次处理各链表。在处理s[i]链表中,用top工作链表重新构造s[i]链表,使s[i]链表对应系统中的一个端点组,其中结点按端点号从小到大连接。
【程序】
#inelude
#define N 100
typeef struct node{
int data;
struct node *link;
}NODE;
NODE * s[N];
int i,j,n,t;
NODE *q,*p,*x,*y,*top;
main( )
{
printf(“Enter namber of components.”);
scanf(“%d”,&n);
for(i=0;i<n;i++) printf(“Enter pairs./n”);
while(scanf(“%d%d”,&i,&j)==2)
{ /*输入相连端点对,生成相连端点结点链表*/
p=(NODE*)malloc(sizeof(NODE));
p→data=j;p→link=s[i];s[i]=p;
p=(NODE*)malloc(sizeof(NODE));
p→data=i;p→link=s[j];s[j]=p;
}
for(i=0;i<n;i++) /*顺序处理各链表*/

[填空题]阅读以下说明和Java程序,将应填入 (n) 处的字句写在对应栏内。 [说明] 下面程序是为汽车市场编制的一个程序的一部分。其中automobile是基类。 [Java程序] class MainJava{ public static void main(String agr[]){ car sedan=new car( ); sedan.initialize(24,20.0,4); System.out.println ("The sedan can travel" + (1) +"miles./n"); System.out.println ("The sedan has" + (2) +"doors./n"); } } class automobile{ protected int miles_per_gallon; //汽车每加仑行驶公里数 (3) double fuel_capacity; //油箱容积 public void initialize(int in_mpg,int in_fuel){ miles_per_galion=in_mpg; fuel_capacity=in_fuel; } public int get_mpg( ){//提供一辆特定汽车每加仑公里数 return miles_per_gallon; } public double get_fuel( ){//提供油箱容积 return fuel_capacity; } public double travel_distance( ){//计算满油箱情况下的可行驶总公里数 return (4) ; } } class car (5) { private int Total_doors; public void initialize(int in_mpg,double in_fuel,int doors){ Total_doors=doors; miles_per_gallon=in_mpg;
[填空题]阅读以下说明和Java程序,将应填入 (n) 处的字句写在对应栏内。
[说明]
下面程序输出一个矩形面积,以及矩形区域上的假想的作物产量。
[Java程序]
public class MainJava
public static void main(String[] args)
Lot_size small=new Lot_size( );
Lot_size medium=new Lot_size( );
small.set(5,5,5,25);
medium.set(10,10,10,50);
System.out.println("For a small lot of area"
+small.get_area( )+"/n");
System.out.println("the actual crops are $"
+small.get_data2( )+"/n");
System.out.println("and ideal crops are $"
+small.get data( )+"/n");
System.out.println("For a medium lot of area"
+medium.get_area( )+“/n”);
System.out.println("the actual crops are $"
+medium.get_data2( )+"/n");
System.out.println ("and ideal crops are $"
+medium.get_data( )+"/n");
class Crop_assessment
private int actual_crop;
private int ideal_crop;
public void set(int
[简答题]
阅读下列说明和C++程序,将应填入(n)处的字句写在对应栏内。
【程序1说明】
程序1中定义了数组的类模板,该模板使得对于任意类型的二维数组,可以在访问数组元素的同时,对行下标和列下标进行越界判断,并给出相应的提示信息(C++语言本身不提供对下标越界的判断)。
【程序1】
#include < iostream. h >
template < class T > class Array2D;
template < class T > class Array2DBody {
friend (1) ;
T * tempBody;
int iRows, iColumns, iCurrentRow;
Array2DBody(int Rows,int Cols) {
tempBody = (2) ;
iRows = Rows;
iColumns = Cols;
iCurrentRow = -1;
}
public:
T& operator[ ] (int j){
bool row_ error, column_ error;
row_ error = column_ error = false;
try {
if ( iCurrentRow < 0||iCurrentRow > = iRows)
row_ error = true;
if( j < 0||j > = iColumns)
column_error = true;
if( row_error = = true [ [ column_ error = = true)
(3) ;
}
catch(char) {
if (row_error = = true)
cerr < < "行下标越界"[" < < iCurrentRow < < "]";

[填空题]阅读以下说明和Java程序,将应填入 (n) 处的字句写在对应栏内
[说明]
以下程序的功能时三角形、矩形和正方形的面积输出。
程序由5个类组成:areatest是主类,类Triangle,Rectangle和Square分别表示三角形、矩形和正方形,抽象类Figure提供了一个计算面积的抽象方法。
[Java程序]
public class areatest {
public static viod main(string args[]){
Figure[]Figures={
New triangle(2,3,3),new rectangle(5,8),new square(5)
};
for(int i=0; i<Figures.length;i++){
system.out.println(Figures+"area="+Figures.getarea( ));
}
}
}
public abstract class figure {
public abstract double getarea( );
}
public class rectangle extends (1) {
double height;
double width;
public rectangle (double height,double width){
this.height=height;
this.width=width;
}
public string tostring( ){
return"rectangle:height="+height+",width="+width+":";
}
public double getarea( ){
return (2)
}
}
public class square exends (3)
{
public square(double width
[填空题]阅读以下说明和C++程序,将应填入 (n) 处的字句写在对应栏内。
[说明]
下面程序输出一个矩形面积,以及矩形区域上的假想的作物产量。
[C++程序]
#include <iostream.h>
class crop_assessment

int actual_crop;
int ideal_crop;
public:
void set(int in_actual,int in_ideal)

actual crop=in_actual;
ideal_crop=in_ideal;

int get_actual_crop(void) (1) ;
int get_ideal_crop(void) (2) ;)
;
Class lot_size

int length;
int width;
(3) crop;
public:
void set(int 1,int w,int a,int i)

length=1;
width=w;
crop.set(a,i);

int get_area(void)return length*width;
int get_data(void)return (4) ;
int get_data2(void)freturn (5) ;

int main( )

Los_size small,medium;
small.set(5,5,5,25);
medium.set(10,10,10,50);
cout<<"For a small lot of area"<<smallget_area( )<<“/n”;
cout<<"the actual
[填空题]阅读以下说明和C++程序,将应填入 (n) 处的字句写在对应栏内
[说明]
以下程序的功能是计算三角形、矩形和正方形的面积并输出。
程序由4个类组成:类Triangle,Rectangle和Square分别表示三角形、矩形和正方形;抽象类Figure提供了一个纯虚拟函数getArea( ),作为计算上述三种图形面积的通用接口。
[C++程序]
#include<iostream.h>
#include<math.h>
class Figure{
public:
virtual double getArea( )=0; //纯虚拟函数
};
class Rectangle: (1) {
protected:
double height;
double width;
public:
Rectangle( ){};
Rectangle(double height,double width){
This->height=height;
This->width=width;
}
double getarea( ){
return (2) ;
}
};
class Square: (3)
public:
square(double width){
(4) ;
}
};
class triangle: (5) {
double la;
double lb;
double lc;
public:
triangle(double la,double lb,double lc){
this->la=la;thiS->ib;this->lc;
}
double getArea( ){
double s=(la+lb+lc)/2.0;
return sqrt(s*(s-la)
[填空题]

阅读以下说明和C程序,将应填入 (n) 处的字句写在对应栏内。
[说明]
假设需要将N个任务分配给N个工人同时去完成,每个人都能承担这N个任务,但费用不同。下面的程序用回溯法计算总费用最小的一种工作分配方案,在该方案中,为每个人分配1个不同的任务。
程序中,N个任务从0开始依次编号,N个工人也从0开始依次编号,主要的变量说明如下:
c[i][i]:将任务i分配给工人j的费用。
task[i]:值为0表示任务i未分配;值为j表示任务i分配给工人j。
worker[k]:值为0表示工人k未分配任务;值为1表示工人k已分配任务。
mincost:最小总费用。
[程序]
#include<stdio.h>
#define N 8 /*N表示任务数和工人数*/
int c[N][N];
unsigned int mincost=65535; /*设置min的初始值,大于可能的总费用*/
int task[N],temp[N],worker[N];
void plan(int k,unsigned int cost)
int i;
if( (1) &&cost<mincost)
mincost=cost;
for(i=0;i<N;i++)temp[i]=task[i];

eise
for(i=0;i<N;i++) /*分配任务k*/
if(worker[i]==0 && (2) )
worker[i]=1;task[k]= (3)
plan( (4) ,cost+c[k][i]);
(5) ;task[k]=0;
/*if*/

/*plan*/
void main( )
int i,j;

我来回答:

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

订单号:

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