题目详情
当前位置:首页 > 计算机考试 > 中级软件设计师
题目详情:
发布时间:2023-10-26 19:28:41

[简答题][说明] 以下C++代码使用虚函数实现了同一基类shape派生出来的Class rectangle、Class triangle、Class circle实现了计算矩形、圆形面积的计算。仔细阅读以下代码,将 (n) 处语句补充完整。 [代码5-1] #include<iostream.h> #define PI 3.14159 class shape {//基类 protected: (1) ; public: (2) (3) ; }; [代码5-2] class rectangle: public shape { public: rectangle (int x2,int y2,int r2): (4) {}; double area ( ) {return x*y; }; }; class circle: public shape { public: circle (int x3,int y3,int r3): (5) {}; double area ( ) {return r*r*PI; }; }; [代码5-3] void main ( ) { rectangle r (10,20,0); circle c (0,0,30); shape (6) ; cout<<"长方形面积="<<s1->area ( ) <<endl; cout<<"圆形面积="<<s2->area ( ) <<endl; } [运行结果] 长方形面积=200 圆形面积=2827.43

更多"[说明] 以下C++代码使用虚函数实现了同一基类shape派生出来"的相关试题:

[多项选择][说明]
以下C++代码使用虚函数实现了同一基类shape派生出来的Class rectangle、Class triangle、Class circle实现了计算矩形、圆形面积的计算。仔细阅读以下代码,将 (n) 处语句补充完整。
[代码5-1]
#include<iostream.h>
#define PI 3.14159
class shape //基类
protected:
(1)
public:
(2)
(3)

[代码5-2]
class rectangle: public shape
public:
rectangle (int x2,int y2,int r2): (4) ;
double area ( ) return x*y; ;
;
class circle: public shape
public:
circle (int x3,int y3,int r3): (5) ;
double area ( ) return r*r*PI; ;
;
[代码5-3]
void main ( )

rectangle r (10,20,0);
circle c (0,0,30);
shape (6)
cout<<"长方形面积="<<s1->area ( ) <<endl;
cout<<"圆形面积="<<s2->area ( ) <<endl;

[运行结果]
长方形面积=200
圆形面积=2827.43
[单项选择]关于以下程序代码的说明正确的是( )
(1) class HasStatic
(2) private static int x=100:
(3) public static void main (String args[]
(4) HasStatic hs1=new Has Static( );
(5) hs1.x + +;
(6) Has Static hs2=new HasStatic( );
(7) hs2.x + +;
(8) hs1=new HasStatic( );
(9) hs1.x + +:
(10) System.out.println("x="+ x);
(11)
(12)
A. (5)行不能通过编译,因为引用了私有静态变量
B. (10)行不能通过编译,因为x是私有静态变量
C. 程序通过编译,输出结果为:x=103
D. 程序通过编译,输出结果为:x=100
[单项选择]关于以下程序代码的说明正确的是( ) (1) class HasStatic{ (2) private static int x=100: (3) public static void main (String args[]{ (4) HasStatic hs1=new Has Static( ); (5) hs1.x + +; (6) Has Static hs2=new HasStatic( ); (7) hs2.x + +; (8) hs1=new HasStatic( ); (9) hs1.x + +: (10) System.out.println("x="+ x); (11) } (12) }
A. (5)行不能通过编译,因为引用了私有静态变量
B. (10)行不能通过编译,因为x是私有静态变量
C. 程序通过编译,输出结果为:x=103
D. 程序通过编译,输出结果为:x=100
[简答题][说明]
以下代码实现了对象引用作为函数参数,仔细阅读以下代码,分析运行结果,填入 (n) 处。
[代码]
#include<iostream.h>
class Sample

int x,y;
public:
Sample( ) x=y=0;
Sample (int i, int j ) x=i; y=j;
void copy ( Sample &s ).,
void setxy ( int i, int j ) x=i; y=j;
void print ( cout<<"x="<<x<<end1 ; cout <<"y="<<y<<end1;
;
void Sample: copy ( Sample &s )

X=S.X;
y=s.y;

void func ( Sample s1, Sample &s2 )

s1.setxy ( 10,20 );
s2.setxy ( 30,40 );

void main ( )

Sample p ( 1,2 ) ,q;
q.copy ( p );
time ( p,q );
p.print ( );
q.print ( );

运行结果
(1)
(2)
(3)
(4)
[简答题][说明] 以下代码实现了对象引用作为函数参数,仔细阅读以下代码,分析运行结果,填入 (n) 处。 [代码] #include<iostream.h> class Sample { int x,y; public: Sample( ) {x=y=0; } Sample (int i, int j ) {x=i; y=j; } void copy ( Sample &s )., void setxy ( int i, int j ) {x=i; y=j; } void print ( {cout<<"x="<<x<<end1 ; cout <<"y="<<y<<end1; }; void Sample: copy ( Sample &s ) { X=S.X; y=s.y; } void func ( Sample s1, Sample &s2 ) { s1.setxy ( 10,20 ); s2.setxy ( 30,40 ); } void main ( ) { Sample p ( 1,2 ) ,q; q.copy ( p ); time ( p,q ); p.print ( ); q.print ( ); } 运行结果 (1) (2) (3) (4)
[简答题]阅读以下程序代码,写出程序的功能。
public class Class34

public static void main(String[] args)

int a=1,b;
while(a<=9)

b=1;
while(b<=a)

System. out. print(" "+a+"×"+b+"="+a*b);
b++;

System. out. println( );
a++;



[简答题]阅读以下程序代码,写出程序的输出结果。
public class Class35

public static void main(String[] args)

String s1=new String("0860371"),s2="0860371";
System. out. println(s1==s2);
System. out. println(s1. equals(s2));
System. out. println(s1. endsWith(s2)==s1. startsWith(s2));


[简答题]阅读以下程序代码,写出程序的输出结果。
public class Class32

public static void main(String[] args)

boolean x=true,y=false,z=false;
x=x&&y||z;
y=x||y&&z;
z=!(x!=y)||(y==z);
System. out. println(x+","+y+","+z);


[简答题]阅读以下程序代码,写出程序的输出结果。
public class Class33

public static void main(String[] args)

int a,b,c;
a=b=c=1;
boolean w;
w=a++>1&&++b>c++:
System. out. println(a+","+b+","+c+","+w);


[简答题][说明]
下面代码实现class C对class A和B的protected成员和public成员的调用。仔细阅读[代码5-1]、[代码5-2],在 (n) 处写出正确的运行结果。
[代码5-1]
#include <iostream.h>
class A
private:
int a1;
protected:
int a2;
public:
A ( int v1,int v2,int v3 ): a1 ( v1 ) ,a2 ( v2 ) ,a3 ( v3 )

int a3
;
class B : pubiic A
private:
int b1;
protected:
int b2;
public:
B ( int v1,int v2,int v3,int v4,int v5,int v6 )
: A(v1,v2,v3),b1 (v4),b2(v5),b3 (v6)
int b3;
;
class C : public B
private:
int c1;
protected:
int c2;
public:
int c3;
C (int v1,int v2,int v3,int v4,int v5,int v6,int v7,int v8,int v9 )
: B ( v1,v2,v3,v4,v5,v6 ) ,c1 ( v7 ),c2 ( v8 ) ,c3 v9
void disp ( )

cout << "a2 in class C =" << a2 << endl;
cout << "a3 in class C =" << a3 << eudl;
cout <
[简答题][说明]
下面代码实现class C对class A和B的protected成员和public成员的调用。仔细阅读[代码5-1]、[代码5-2],在 (n) 处写出正确的运行结果。
[代码5-1]
#include <iostream.h>
class A {
private:
int a1;
protected:
int a2;
public:
A ( int v1,int v2,int v3 ): a1 ( v1 ) ,a2 ( v2 ) ,a3 ( v3 )
{}
int a3
};
class B : pubiic A{
private:
int b1;
protected:
int b2;
public:
B ( int v1,int v2,int v3,int v4,int v5,int v6 )
: A(v1,v2,v3),b1 (v4),b2(v5),b3 (v6) {}
int b3;
};
class C : public B{
private:
int c1;
protected:
int c2;
public:
int c3;
C (int v1,int v2,int v3,int v4,int v5,int v6,int v7,int v8,int v9 )
: B ( v1,v2,v3,v4,v5,v6 ) ,c1 ( v7 ),c2 ( v8 ) ,c3 v9
void disp ( )
{
cout << "a2 in class C =" << a2 << endl;
cout << "a3 in class C =" << a3 << eudl;
cout << "b2 in class C =" << b2 <
[填空题]以下代码的运行结果是______。 public class exl5 { public static void main(String args []) { int i = 5; do { i--; if(i > 2) continue; }while(i < 0); System.out.println(i); } }
[填空题]以下代码的运行结果是______。 public class exl4 { public static void main(String args []) { int i = O; while(i < 10) { i++; if(i == 5) continue; } System.out.println(i); } }
[简答题]

阅读下列说明,回答问题1至问题3。

【说明】
以下代码由C语言书写,能根据指定的年、月计算当月所含天数。
int GetMaxDay( int year, int month )
{
int maxday = 0;
if ( month >= 1 && month <= 12 )
{
if ( month == 2 )
{
if ( year % 4 == 0 )
{
if ( year % 100 == 0 )
{
if ( year % 400 == 0 )
maxday = 29;
else
maxday = 28;
}
else
maxday = 29;
}
else
maxday = 28;
}
else
{
if ( month == 4 || month == 6 || month == 9 || month == || )
maxday = 30;
else
maxday = 31;
}
}
return maxday; } 请计算上述控制流图的环路复杂度V(G)。
[简答题]

阅读下列说明,回答问题1至问题3。
【说明】
以下代码由C语言书写,能根据指定的年、月计算当月所含天数。
int GetMaxDay( int year, int month )
{
int maxday = 0;
if ( month >= 1 && month <= 12 )
{
if ( month == 2 )
{
if ( year % 4 == 0 )
{
if ( year % 100 == 0 )
{
if ( year % 400 == 0 )
maxday = 29;
else
maxday = 28;
}
else
maxday = 29;
}
else
maxday = 28;
}
else
{
if ( month == 4 || month == 6 || month == 9 || month == || )
maxday = 30;
else
maxday = 31;
}
}
return maxday; }

请画出以上代码的控制流图。
[简答题]

阅读下列说明,回答问题1至问题3。
【说明】
以下代码由C语言书写,在输入3个整数后,能够输出最大数和最小数。
int main(void)
{
int a, b, c, max, min;
printf("input three numbers: ");
scanf("%d%d%d", &a, &b, &c);
if(a>b) /*判断1*/
{
max=a;
min=b;
}
else
{
max=b;
min=a;
}
if(max<c) /*判断2*/
max=c;
else if(min>c) /*判断3*/
min=c;
printf("max=%d/nmin=%d", max, min);
return 0;
}

请画出该程序段的控制流图,并分析该控制流图中有多少条线性独立路径(V(G)的值)。

我来回答:

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

订单号:

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