更多"[说明]以下代码实现了对象引用作为函数参数,仔细阅读以下代码,分析运行"的相关试题:
[简答题][说明]
以下代码实现了对象引用作为函数参数,仔细阅读以下代码,分析运行结果,填入 (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)
[简答题][说明]
以下程序实现了在applet里移动图形文件,仔细阅读代码和相关注释,将程序补充完整。
[代码6-1]
import j ava. awt. *;
import j ava.awt.event.*;
import java.applet. Applet;
public class AppCIU extends Applet implements MouseMotionListener, MouseListener
{
Image IMG onClick=over(this) title=放大; // 声明 Image 类类型的变量 IMG onClick=over(this) title=放大
int x=70,y=60,posX=70,posY=60,dx,dy;
public void init ( )
{
IMG onClick=over(this) title=放大=getImage ( getCodeBase ( ) ,"mouse.gif" ); //载入影像
addMouseListener ( this );
addMouseMotionListener ( this );
}
public void mousePressed ( MouseEvent e )
{
dx=e.getX( )-posX; //取得按下之点与基准点X方向的距离
dy=e.getY( )-posY; //取得按下之点与基准点Y方向的距离
}
public void mouseDragged ( MouseEvent e )
{
(1)
(2)
if ( dx>0 && dx<120 && dy>0 && dy<60 ) //如果指针落在图形上方
{
Graphics g=getGraphics ( );
(3)
}
}
public void paint ( Graphics g )
{
(4)
(5
[多项选择][说明]
以下程序实现了在applet里移动图形文件,仔细阅读代码和相关注释,将程序补充完整。
[代码6-1]
import j ava. awt. *;
import j ava.awt.event.*;
import java.applet. Applet;
public class AppCIU extends Applet implements MouseMotionListener, MouseListener
Image img; // 声明 Image 类类型的变量 img
int x=70,y=60,posX=70,posY=60,dx,dy;
public void init ( )
img=getImage ( getCodeBase ( ) ,"mouse.gif" ); //载入影像
addMouseListener ( this );
addMouseMotionListener ( this );
public void mousePressed ( MouseEvent e )
dx=e.getX( )-posX; //取得按下之点与基准点X方向的距离
dy=e.getY( )-posY; //取得按下之点与基准点Y方向的距离
public void mouseDragged ( MouseEvent e )
(1)
(2)
if ( dx>0 && dx<120 && dy>0 && dy<60 ) //如果指针落在图形上方
Graphics g=getGraphics ( );
(3)
public void paint ( Graphics g )
(4)
[填空题]【说明】
以下程序实现了利用鼠标任意移动该圆形的位置,仔细阅读代码和相关注释,将程序补充完整。
【代码6】
import java.awt.*;
import java.awt.event.*;
public class CIUSAMPLE extends Frame implements MouseMotionListener, MouseListener
{
static CIUSAMPLE frm=new CIUSAMPLE ( );
int x=70,y=60,posX=70,posY=60,dx,dy;
public static void main ( String args[])
{
frm.setTitle ("Dragging a circle");
frm.setSize ( 200,150 );
(1)
frm.addMouseMotionListener ( frm );
frm. setVisible ( true );
}
public void mousePressed ( MouseEvent e )
{
(2)
dy=e.getY ( ) -posY;
}
public void mouseDragged ( MouseEvent e )
{
(3)
y=e.getY ( ) -dy;
if ( dx>0 && dx<50 && dy>0 && dy<50 ) //如果指我落在正方形区域内
{
Graphics g=getGraphics ( );
(4)
}
}
public void paint ( Graphics g )
{
g.setColor ( Color. pink ); // 设置绘图颜色为粉红
g.fillOval ( x,y,50,50 ); //以基准点为图形的左上角绘出圆形
(5)
pos
[简答题][说明]
以下程序实现了利用鼠标任意移动圆形的位置,仔细阅读代码和相关注释,将程序补充完整。
[代码6-1]
import java.awt.*;
import java.awt.event.*;
public class CIUSAMPLE extends Frame implements MouseMotionListener, MouseListener
static CIUSAMPLE frm=new CIUSAMPLE ( );
int x=70,y=60,posX=70,posY=60,dx,dy;
public static void main (String args[])
frm.setTitle ("Dragging a circle");
frm.setSize (200,150);
(1)
ffm.addMouseMotionListener (frm);
frm.setVisible (true);
public void mousePressed (MouseEvent e)
(2)
dy=e.getY ( ) -posY;
public void mouseDragged (MouseEvent e)
(3)
y=e.getY ( ) -dy;
if(dx>0&&dx<50&&dy>0&&dy<50) //如果指针落在正方形区域内
Graphicsg=getGraphics ( );
(4)
public void paint (Graphics g)
g.setColor (Color.pink); //设置绘图颜色为粉红
g.fillOval(x,y,50
[简答题][说明]
下面代码实现类A、B、C、D的继承定义和应用。仔细阅读[代码5-1],在 (n) 处写出正确的运行结果。
[代码5-1]
#include<iostream.h>
class A {
public:
int a;
A (int v1): a(v1) {} //构造函数
void disp ( )
{
cout<<"a in class A="<<a<<endl;
}
};
class B: virtual public A {
public:
int b;
B (int v1,int v2): A(v1),b v2) {} //构造函数
void disp ( )
{
cout<<"a in class B="<<a<<endl
cout<<"b in class B="<<b<<endl;
}
};
class C: virtual public A {
public:
int c;
C (int v1,int v2): A(v1) ,c(v2) {} //构造函数
void disp ( )
{
cout<<"a in class C="<<a<<endl;
cout<<"c in class C="<<c<<endl;
}
};
class D: public B, public C {
public:
int d;
D (int v1,int v2,int v3,int v4 ): A(v1) ,B(v1,v2) ,C(v1,v3),d(v4) {} //构造函数
void disp ( )
{
cout<<"a="<<a<<endl;
cout<<"b="<< b<<endl;
cout<<"c="<<c<<endl;
cout<<"d="<<d<<endl;
}
};
void main( )
{
D demo (10,20,30,40);
demo.disp ( );
}
[运行
[简答题][说明]
下面代码实现类A、B、C、D的继承定义和应用。仔细阅读[代码5-1],在 (n) 处写出正确的运行结果。
[代码5-1]
#include<iostream.h>
class A
public:
int a;
A (int v1): a(v1) //构造函数
void disp ( )
cout<<"a in class A="<<a<<endl;
;
class B: virtual public A
public:
int b;
B (int v1,int v2): A(v1),b v2) //构造函数
void disp ( )
cout<<"a in class B="<<a<<endl
cout<<"b in class B="<<b<<endl;
;
class C: virtual public A
public:
int c;
C (int v1,int v2): A(v1) ,c(v2) //构造函数
void disp ( )
cout<<"a in class C="<<a<<endl;
cout<<"c in class C="<<c<<endl;
;
class D: public B, public C
public:
int d;
D (int v1,int v2,int v3,int v4 ): A(v1) ,B(v1,v2) ,C(v1,v3),d(v4) //构造函数
void disp ( )
cout<<"a="<<a<<endl;
cout<<"b="<< b<<endl;
cout<<"c="<<c<<endl;
c
[简答题][说明]
以下JAVA程序实现了在接口interface iShape2D的定义和应用,仔细阅读代码和相关注释,将程序补充完整。
[代码6-1]
interface iShape2D //定义接口
{
(1)
(2)
}
(3) //实现CRectangle类
{
int width, height;
(4) CRectangle (int w,int h) {
width=w;
height=h;
}
public void area ( ){ //定义area( )的处理方式
System. out.println ("area="+width*height);
}
}
(5) //实现CCircle类
{
double radius;
(6) CCircle (double r) {
radius=r;
}
public void area ( ) { //定义area( )的处理方式
System.out.println ("area="+pi*radius*radius);
}
}
[代码6-2]
public class app10_4
{
public static void main(String args[])
{
CRectangle rect=new CRectangle (5,10);
rect.area ( ); //调用CRectangle类里的area ( ) method
CCircle cir=new CCircle (2.0);
cir.area ( ); //调用CCircl类里的area ( ) method
}
}
[简答题][说明]
以下JAVA程序实现了在接口interface iShape2D的定义和应用,仔细阅读代码和相关注释,将程序补充完整。
[代码6-1]
interface iShape2D //定义接口
(1)
(2)
(3) //实现CRectangle类
int width, height;
(4) CRectangle (int w,int h)
width=w;
height=h;
public void area ( ) //定义area( )的处理方式
System. out.println ("area="+width*height);
(5) //实现CCircle类
double radius;
(6) CCircle (double r)
radius=r;
public void area ( ) //定义area( )的处理方式
System.out.println ("area="+pi*radius*radius);
[代码6-2]
public class app10_4
public static void main(String args[])
CRectangle rect=new CRectangle (5,10);
rect.area ( ); //调用CRectangle类里的area ( ) method
CCircle cir=new CCircle (2.0);
cir.area ( ); //调用CCircl类里的area ( ) method
[填空题]对象的使用包括引用对象的成员变量和方法。通过 ______ 运算符就能实现对对象成员变量的访问和对象方法的调用。
[简答题][说明]
以下代码实现了当用户推出界面时,判断TextEdit中的文字是否发生改变,弹出对话框判断,让用户选择选择是否保存文件或取消退出界面操作。阅读下面代码,补充完整。
[代码7-1]
Begin VB.Form Forml
//...窗体描述(略)
Begin VB.TextBox TextEdit
Height = 1830
Left = 180
TabIndex = 0
Text = "TextEdit"
Top = 360
Width = 3885
End
//...窗体描述(略)
End
[代码 7-2]
Dim txtchange As Boolean
Dim myval As String
Private Sub Form Load ( )
TextEdit.Text = "CIU, 中国软考联盟!
txtchange = False
End Sub
[代码 7-3]
Private Sub TextEdit_Change ( )
Static notchange As Boolean
(1)
(2)
End Sub
Private Sub Form_Unload ( Cancel As Integer )
Dim myval As String
If (3) Then
myval = MsgBox ( "保存文件的更改吗", vbYesNoCancel, "提示信息" )
If (4) Then
MsgBox "保存成功"
End
End If
If (5) Then End
If (6) Then Cancel = 1
End If
End Sub
[简答题][说明]
以下代码实现了当用户推出界面时,判断TextEdit中的文字是否发生改变,弹出对话框判断,让用户选择选择是否保存文件或取消退出界面操作。阅读下面代码,补充完整。
[代码7-1]
Begin VB.Form Forml
//...窗体描述(略)
Begin VB.TextBox TextEdit
Height = 1830
Left = 180
TabIndex = 0
Text = "TextEdit"
Top = 360
Width = 3885
End
//...窗体描述(略)
End
[代码 7-2]
Dim txtchange As Boolean
Dim myval As String
Private Sub Form Load ( )
TextEdit.Text = "CIU, 中国软考联盟!
txtchange = False
End Sub
[代码 7-3]
Private Sub TextEdit_Change ( )
Static notchange As Boolean
(1)
(2)
End Sub
Private Sub Form_Unload ( Cancel As Integer )
Dim myval As String
If (3) Then
myval = MsgBox ( "保存文件的更改吗", vbYesNoCancel, "提示信息" )
If (4) Then
MsgBox "保存成功"
End
End If
If (5) Then End
If (6) Then Cancel = 1
End If
[填空题]【说明】
以下代码实现了当用户退出界面时,判断TextEdit中的文字是否发生改变,弹出对话框判断,让用户选择是否保存文件或取消退出界面操作。阅读下面的代码,将其补充完整。
【代码7-1】
Begin VB.Form Forml
//...窗体描述(略)
Begin VB.TextBox TextEdit
Height = 1830
Left = 180
Tablndex = 0
Text = "TextEdit"
Top = 360
Width = 3885
End
//...窗体描述(略)
End
【代码7-2】
Dim txtchange As Boolean
Dim myval As String
Private Sub Form Load ( )
TextEdit.Text: "CIU, 中国软考联盟!"
txtchange = False
End Sub
【代码7-3】
Private Sub TextEdit_Change ( )
Static notchange As Boolean
(1)
notchange = Tree
End Sub
Private Sub Form_Unload ( Cancel As Integer )
Dim myval As String
If (2) Then
myval = MsgBox ( "保存文件的更改吗", vbYesNoCancel, "提示信息" )
If (3) Then
MsgBox "保存成功"
End
End If
If (4) Then End
If (5) Then Cancel = 1
End If
End Sub
[填空题]在对象流中,对象的传送首先要将所传送的对象串行化,也就是实现Serializable接口。下列代码中必须要实现Serializable接口的类是______。
ObjectInput in=
new ObjectInputStream(new FileInputStream("employee.dat"));
Employee[]newStaff=(Employee[])in.readObject);
[简答题]仔细阅读以下3个案例,试分析案例中是否涉及到缴纳土地增值税,并说明理由。(不用计算出应纳税额)
(1) 某村将集体所有的100亩果园转让给某房地产公司,用于建造高级公寓,取得收入1800万元。
(2) 某市国土资源局将国有的50亩土地出让给某房地产公司,用于建造度假村,取得土地出让金600万元。
(3) 某事业单位与某房地产企业签订协议合作建商品房,事业单位提供一块80亩的土地,房地产公司提供1000万元的资金,房屋建成后,双方按照5:5的比例分配,事业单位将分得的房产销售给自己的职工。