阅读以下说明和Java源程序,将应填入(n)处的字句写在对应栏内。
【说明】
以下程序能够计算三角形、矩形和正方形的周长并输出。
程序由5个类组成:AreaTest是主类,类Triangle、Rectangle和Square分别表示三角形、矩形和正方形,抽象类Figure提供了一个计算周长的抽象方法。
【程序】
public class girthTest{
public static void 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[i]+"girth="+figures[i].getGirth());
}
}
}
public abstract class Figure{
public abstract double getGirth();
}
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 getGirth(){
return (2);
}
}
public class Square extends (3) {
public Square(double width){
(4);
}
public Stdng toString(){
return "Square:width='+width+":";
}
}
public class Triangle extends (5) {
double la;
double lb;
double lc;
public Triangle(double la,double lb,double lc){
this.la=la;this.lb=lb;this.lc=lc;
}
public String toString(){
return "Triangle:sides=" +la+"," +lb+"," +lc+":";
}
public double getGirth(){
return la+lab+lc;
}
}
第1题:
阅读以下说明和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;
}
}
}
}
第2题:
阅读以下说明和JAVA 2代码,将应填入(n)处的字句写在对应栏内。
[说明]
以下程序为类类型的变量应用实例,通过异常处理检验了类CCircle的变量的合法性,即参数半径应为非负值。仔细阅读代码和相关注释,将程序补充完整。
[JAVA代码]
//定义自己的异常类
class CCircleException extends Exception
{
}
// 定义类 CCircle
class CCircle
{
private double radius;
public void setRadius ( double r ) (1)
{
if ( r<0 ) {
(2)
}
else
(3)
}
Public void show ( ) {
System. out. println ( "area="+3.14*radius*radius );
}
}
public class ciusample
{
public static void main ( String args[] )
{
CCircle cir=new CCircle( );
(4) {
cir. setRadius ( -2.0 )
}
(5)
{
System. out. println ( e+" throwed" ) ;
}
cir. show( ) ;
}
}
第3题:
试题三(共 15 分)
阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。
第4题:
阅读下列程序说明和C++程序,把应填入其中(n)处的字句,写在对应栏内。
【说明】
阅读下面几段C++程序回答相应问题。
比较下面两段程序的优缺点。
①for (i=0; i<N; i++ )
{
if (condition)
//DoSomething
…
else
//DoOtherthing
…
}
②if (condition) {
for (i =0; i<N; i++ )
//DoSomething
}else {
for (i=0; i <N; i++ )
//DoOtherthing
…
}
第5题:
阅读以下说明和流程图,将应填入(n)处的字句写在对应栏内。
[说明]
下面的流程图用于计算一个英文句子中最长单词的长度(即单词中字母个数)MAX。假设该英文句子中只含字母、空格和句点“.”,其中句点表示结尾,空格之间连续的字母串称为单词。
[流程图]
第6题: