问答题

[说明]
下面代码实现类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= (1)
b= (2)
c= (3)
d= (4)

【参考答案】

(1)10
(2)20
(3)30
(4)40
热门 试题

问答题
[说明] 在一些财务软件中,经常需要将阿拉伯数字的账目转化为汉语习惯中的金额计数方法,例如: “3.45”转化为“叁元四角五分”; “3.4”转化为“叁元四角”; “3.40”转化为“叁元四角零分”; “3.456”转化为“叁元四角五分”; “345.00”转化为“叁百四十五元零角零分”; “345”转化为“叁百四十五元”; 以下Visual Basic代码实现了小写金额转换为大写金额。界面如图10-9所示。结合实际例子说明,仔细阅读下面代码,将 (n) 代码补充完整。 [代码7-1] Begin VB.FormForm1 Caption = 小写金额转换为大写金额 ...窗体描述(略) Begin VB.CommandButton Command1 Caption = 退出 ...窗体描述(略) End Begin VB.TextBox Text2 ...窗体描述(略) End Begin VB.TextBox Text1 Enabled = 0 ’False …窗体描述(略) End Begin VB.Labe1 Labe12 Caption = 转换为大写金额 ...窗体描述(略) End Begin VB.Labe1 Labe11 Caphon = 请输入数字 ...窗体描述(略) End End [代码7-2] Private Function setdata (num As Integer) As String ’数字转换 Select CaSe num Case 0 setdata= 零 Case 1 Setdata= 壹 Case 2 Setdata= 贰 Case 3 Setdata= 叁 Case4 Setdata= 肆 Case 5 Setdata= 伍 Case 6 Setdata= 陆 Case 7 Setdata= 柒 Case 8 Setdata= 捌 Case 9 Setdata= 玖 End Select End Function Private Function chang (aaa As Integer) As String ’位数转换 Select CaSe aaa Case 1 chang= Case 2 chang= 十 Case 3 chang= 百 Case 4 chang= 千 Case 5 chang= 万 Case 6 chang= 十 Case 7 chang= 百 Case 8 chang= 千 Case 9 chang= 亿 Case 10 chang= 十 End Select End Function [代码7-3] Private Sub Text2_Change ( ) ’小写转大写 Dim i As Integer Dim j As Integer Dim myint As Integer Dim myint1 As Integer Dim mydoub As Double Dim mystr As String Dim mystr1 As String Dim mystr2 As String Dim mystr3 As String Dim mystr4 As String Dim money As Long Dim money1 As Integer Dim money2 As Long mystr=Text2.Text myint=InStr (mystr, . ) If myint=0 Then mystr=Text2.Text Else mystr3=Right(Text2.Text, Len (Text2.Text ) - myint) If mystr3<> Then ’转换小数位 mystr4=Left(mystr3, 1) mystr3=Right(mystr3, Len(mystr3 ) - 1) If mystr4<> 0 Then (1) End If If mystr3<> Then mystr4=Left(mystr3, 1) (2) End If End If mystr=Left(Text2.Text,myint - 1) End If j=Len(mystr) For i=1 To Len(mystr,i) money2=Left(mystr,i) money1=Right(money2,1) If money1=0 Then Ifj=5 Then (3) Else (4) End If Else (5) End If j=j-1 Next i Text1.Text=mystr1& 元 &mystr2 ’显示大写 End sub