题目详情
当前位置:首页 > 计算机考试 > 初级程序员
题目详情:
发布时间:2023-10-23 08:39:44

[填空题]阅读以下说明和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) 处的字句写在对应栏内 ["的相关试题:

[填空题]阅读以下说明和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) 处的字句写在对应栏内
[说明]
以下程序的功能时三角形、矩形和正方形的面积输出。
程序由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
[填空题]阅读以下说明和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;




[填空题]阅读以下说明和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
[填空题]阅读以下说明和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
[简答题]
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。
【说明】
以下程序的功能是计算三角形、矩形和正方形的周长并输出。
程序由4个类组成:类Triangle、Rectangle和Square分别表示三角形、矩形和正方形;抽象类 Figure提供了一个纯虚拟函数getGirth( ),作为计算上述3种图形周长的通用接口。
【C++程序】
# include < iostream. h >
# include < math. h >
class Figure {
public:
virtual double getGirth( ) =0; //纯虚拟函数 };
class Rectangle: (1) {
protected:
double height;
double width;
public:
Rectangle( ){};
Rectangle( double height, double width) {
this→height = height;
this→width = width;
}
double getGirth ( ) {
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→Lb = lb; this→lc = lc;
}
double ge
[简答题]
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。
【说明】以下程序实现了二叉树的结点删除算法,若树中存在要删除的结点,则删除它,否则返回。 FindNode ( )函数能够在二叉树中找到给定值的结点,并返回其地址和父结点。
【C++程序】
template < class T >
void BinSTree < T >: :Delete( const T& item)
{
TreeNode < T > * DelNodePtr, * ParNodePtr, * RepNodePtr;
if(( DelNodePtr = FindNode (item,ParNodePtr)) = = NULL)
(1)
if(DelNodePtr→right = = NULL) //被删除结点只有一个子结点的情况
RepNodePtr = DelNodePtr→left;
else if( DelNodePtr→left = = NULL)
(2) ;
else // 被删除结点有两个子结点的情况
{
TreeNode < T >* PofRNodePtr = DelNodePtr;
RepNodePtr = DelNodePtr→left;
while(RepNodePtr→right ! = NULL)
{ //定位左子树的最右结点
PofRNodePtr =RepNodePtr;
RepNodePtr = RepNodePtr→right;
}
if(PofRNodePtr = = DelNodePtr) //左子树没有右子结点
(3) ;
else //用左子顷的最右结点替换删除的结点
{
(4)

[填空题]阅读以下说明和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;


[填空题]阅读以下说明和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
[简答题]

阅读以下说明和Java程序,将应填入__(n)__处的字句写在答题纸的对应栏内
【说明】
以下程序的功能时三角形、矩形和正方形的面积输出。
程序由5个类组成:areatest是主类,类Triangle,Rectangle和Square分别表示三角形、矩形和正方形,抽象类Figure提供了一个计算面积的抽象方法。
【程序】
           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 string tostring( ){
    return”rectangle: height=”+ height +”, width=”+ width +”:”;
   }
   public double getarea( ){
    return __(2)__
   }
  }
  public class square exends __(3)__
  {
   public square(double width) {
    __(4)__ ;
   }

   public string tostring(

[填空题]

阅读以下说明和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
我已记住账号密码