阅读下面程序
import javax.swing.JOptionPane;
public class Comparison{
public static void main(String args[]){
String firstNumber, //用户输入第1个数据变量
second Number, //用户输入第2个数据变量
result; //输出结果变量
int number1, //用于比较的第1个数
number2; //用于比较的第2个数
//用户输入第1个数据的字符串
firstNumber=JOptionPane. showInputDialog(“输入第1个整数:”);
//用户输入第2个数据的字符串
secondNumber=JOptionPane.showlnputDialog(“输入第2个整数:”);
//将字符串转换为整数类型
number1=Integer.parseInt(firstNumber);
number2=Integer.parseInt(secondNumber);
//初始化结果变量
___________________;
//比较两个数据
if(number1=number2)
result += number1 +" =" + number2;
if(number1 != number2 )
result += numberl +" !=" + number2;
if( number1 < number2 )
result = result + "\n" + numberl +" <" + number2;
if(number1 > number2 )
result = result + "\n" + number1 + ">" + number2;
if( number1 <= number2 )
result = result + "\n" + number1 +" <=" + number2;
if (number1 >= number2 )
result = result + "\n" + number1 + ">=" + number2;
//显示结果
JOptionPane.showMessageDialog(null,result," 比较结果",
JOptionPane. INFORMATION_MESSAGE);
System.exit(0);
}
}
为使程序能正确运行并得到合理的输出结果,初始化结果变量语句(下划线处)应是
A.result = ""
B.result = null
C.result = number1
D.result = number2
第1题:
将下面程序补充完整。
include <iostream>
using namespace std;
class Base{
public:
【 】 fun(){return 0;} //声明虚函数
};
class Derived:public Base{
public:
x,y;
void SetVal(int a,int b){}
int fun(){return x+y;}
};
void 【 】 SetVal(int a,int b){x=a;y=b;} //类Derived成员函数
void main(){
Derived d;
cout<<d.fun()<<endl;
}
第2题:
下面程序的结果是 ______。 #include<iostream.h> class A{ public: virtual void fun()=0{}; }; class B:public A{ public: void fun () {cout<< "new file" ;} }; class C: public A{ public: void fun (){cout<<"open file"<< " " } }; class D: public A{ public: void fun () {cout<< "save file\n" ;} }; void main() { A a,*p; B b; C c; D d; p=&c; p->fun (); p=&b; p->fun (); p=&d; p->fun(); }
A.new file open file save file
B.new file new file new file
C.编译出错
D.open file new file save file
第3题:
第4题:
请写出下面的输出:
class B
{
public:
virtual void Print(void)
{
printf(“B::Print\n”);
}
virtual void Reprint(void)
{
printf(“B:Reprint\n”);
}
void Algo(void)
{
Print();
Reprint();
}
};
class D : public B
{
public:
virtual void Print(void)
{
printf(“D::Print\n”);
}
};
void main()
{
B *p = new D();
p->Print();
p->Algo();
}
第5题:
第6题:
阅读下面的程序, 写出运行后输出的结果。 #include<iostream> using namespace std; class A { public: A(){cout<<"A";} }; class B :public A { public: B(){cout<<"B";} }; void main() { B b1; }