[简答题]
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。
【说明】
下面程序的功能是计算并输出某年某月的天数,函数IsLeap Year( )能够判断是否是闰年。
【C++程序】
#
include < iostream >
using namespace std;
(1)
Month {Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec
};
class Date {
public:
Date(
int year, Month m_ month) {
this→year = year;
if(
(2) ) month: Jan;
else month = m_ month;
};
~Date( ){};
bool IsLeap Year( ) {
return ((year%4= =0 &&year% 100 ! =0)||
year%400= =0);
};
int
CaculateDays( ) {
switch(m_month )
{
case (3)
;{
if (4) return 29;
else return 28;
}
case Jan: case Mar: case May: case Jul: case Aug: case Oct: case Dec:
return 31;
case Apr: case Jun: case
Sop: case Nov: return 30;
}
}
private:
int year;
Month month;
};
void
main( ) {
Date day(
[单项选择]下面程序的功能是统计字符串中“array”的个数,在程序的空白处应填入的正确选项是 public class FindKeyWords{ public static void main(String[]args) { String text="An array is a data structur that stores a collection of" +"values of the same type. You access each indMdual value" +"through an integer index. For example,if a is an array" +"of inergers,then a[i]is the ith integer in the array."; int arrayCount=0; int index=-1; String arrayStr="array"; index=text.indexOf(arrayStr); while(index>=0) { ++arrayCount; index+=arrayStr.length( ); index=text.indexOf(arrayStr,index); } System.out.println("the text contains"+arrayCount+"arrays"); } }
A. <
B. =
C. <=
D. >=
[简答题]
阅读下列程序说明和C代码,把应填入其中n处的字句写在对应栏内。
【说明】
下面的程序能够计算不同图形的面积。程序中把每个图形的数据定义成结构类型,利用共同体类型描述2种图形的数据。程序根据输入参数代表的图形类型,求出图形的面积并输出。
【程序】
struct Circle
{
float x,y; /*圆心位置*/
float r; /*圆半径*/
};
struct
Rectangle
{
float width;
/*矩形宽*/
float length;
/*矩形长*/
};
union shape
{
struct Circle circle;/*圆数据结构*/
struct Rectangle rectangle;/*矩形数据结构*/
};
main( )
{
union shape a;
float area;
int i;
printf(“input number:
1circle,2rectangle,3 end/n”);
scanf("%d",&i);
while (1)
/*循环接收输入,并计算输出*/
{
switch(i)
{
case
1:printf(“input radius:/n”);
scanf(“%f”, (2) ;/*共同体类型变量接收输入*/
area=3.1415926* (3)
;
printf(“the area of circle=%f/n”,area);
break;
case 2:printf(“input width and length :/n”);
seanf(“%f,%f”, (4)
;/*共
[单项选择]在下面程序中,括号里应填( )。
#include <iostream>
using namespace std;
class A
public:
void fun( )
cout << "Hello" << endl;
;
class B:: public A
void fun( )
( ) //调用基类的函数fun( )
tout << "HI" << endl;
;
A. fun()
B. fun()
C. A::fun()
D. A->fun(
[单项选择]在下面程序的空白处,应填入的正确选项是 import java.io.*; public class ObjectStreamTest { public static void main(String args[])throws IOExeeption } ObjectoutputStream oos=new ObjectOutputStream(new FileOutputStream("serial.bin")); java.util.Date d=new java.util.Date( ); oos. ______(d); ObjectInputStream ois=new ObjecttInputStream(new FileInputStream("serial.bin")); try{ java.util.Date restoredDate=(java.util.Date)ois.readObject( ); System.out.println("read object back from serial.bin file:"+restoredDate); } catch(classNotFoundException cnf) { System.out.println("class not found"); } } }
A. WriterObject
B. write
C. BufferedWriter
D. writerObject