国家开放大学《面向对象程序设计》形考任务4(预备知识:第7,8章;分值:25分)(2022-2023春季)[答案]
![国家开放大学《面向对象程序设计》形考任务4(预备知识:第7,8章;分值:25分)(2022-2023春季)[答案]](http://m.omarabdo.com/uploads/allimg/240110/aa3cc63820360ebf55624ca7346cc99c.jpg)
题目类型:
单选题
题目:
下面( )既可以作为流的数据源,又可以作为流的目的地.
选项:
键盘
磁盘文件
显示器
扫描仪
题目类型:
单选题
题目:
进行文件输入输出操作时,最常用的系统包是
选项:
java.io
java.lang
java.util
java.awt
题目类型:
单选题
题目:
java中有3个标准输入/输出流,下面的( )不包含在内.
选项:
system.in
system.out
system.err
system.cur
题目类型:
单选题
题目:
在读字符文件 employee.dat 时,使用该文件作为参数的类是
选项:
bufferedreader
datainputstream
dataoutputstream
fileinputstream
题目类型:
单选题
题目:
下列不是 inputstream 子类的是
选项:
fileinputstream
objectinputstream
fileoutputstream
zipinputstream
题目类型:
单选题
题目:
下列哪个类不是异常类的父类?
选项:
error
throwable
exception
object
题目类型:
单选题
题目:
下面的关键字( )与异常处理无关.
选项:
throw
void
throws
try
题目类型:
单选题
题目:
下面的异常( )为数组下标越界异常.
选项:
arithmeticexception
nullpointerexception
arrayindexoutofboundsexception
filenotfoundexception
题目类型:
单选题
题目:
下面( )既可以作为流的数据源,又可以作为流的目的地.
选项:
键盘
磁盘文件
显示器
扫描仪
题目类型:
单选题
题目:
java中有3个标准输入/输出流,下面的( )不包含在内.
选项:
system.in
system.out
system.err
system.cur
题目类型:
判断题
题目:
在java中将信息的输入与输出过程抽象为输入/输出流.输入是指数据流入程序,输出是指数据从程序流出.
选项:
对
错
题目类型:
判断题
题目:
向文本文件中写入字符数据,在任何时候都只需要用到文件写入器类(filewriter),不需要用到缓冲写入器类(bufferedwriter).
选项:
对
错
题目类型:
判断题
题目:
filewriter和filewriter类的构造函数的参数都需要一个文本文件名.
选项:
对
错
题目类型:
判断题
题目:
在对文件进行的输入/输出(i/o)方法的调用中,当遇到错误时通常会抛出一个ioexception异常.
选项:
对
错
题目类型:
判断题
题目:
当一个方法进行文件访问操作可能生成一个ioexception异常时,该方法必须在方法头声明抛出该异常,别无其他选择.
选项:
对
错
题目类型:
判断题
题目:
输入流类(inputstream)和输出流类(outputstream)是用来处理字节流的抽象基类.
选项:
对
错
题目类型:
判断题
题目:
java.io包中的outputstream及其子类专门用于把字节数据写入二进制数据文件中.
选项:
对
错
题目类型:
判断题
题目:
文件输出流类(fileoutputstream)和数据输出流类(dataoutputstream)不是outputstream类的子类.
选项:
对
错
题目类型:
判断题
题目:
dataoutputstream类的文件流能够把各种基本类型的数据写入到二进制数据文件中.
选项:
对
错
题目类型:
判断题
题目:
java.io包中提供的objectoutputstream类能够把对象信息存储到文件中.
选项:
对
错
题目类型:
单选题
题目:
public class xxk2 { private final int a; public xxk2(int a) {this.a=a;} public int f1(int x) { if(x%2==1) return 2*(ax); else return 3*ax; } public int get() {return a;} public static void main(string[] args) { xxk2 x=new xxk2(8); int y=x.f1(20); y=x.get(); system.out.println("y="y); } }
选项:
y =52
y =62
题目类型:
单选题
题目:
public class xxk2 { private int a; public xxk2(int aa) {a=aa;} public int f1(int x) { if(x%2==1) return 2*(ax); else return 3*ax; } public int get() {return a;} public static void main(string[] args) { xxk2 x=new xxk2(5); int y=x.f1(9); y=x.get()*x.get(); system.out.println("y="y); } }
选项:
y =53
y =62
题目类型:
单选题
题目:
public class xxk2 { private int a; public xxk2() {a=3;} public xxk2(int aa) {a=aa;} public double f1() { return 2*math.pow(a,3)a; } public static void main(string[] args) { xxk2 x=new xxk2(), y=new xxk2(5); system.out.println(x.f1()", "y.f1()); } }
选项:
67.0, 255.0
57.0, 255.0
题目类型:
单选题
题目:
class rectangle { private int a,b; public rectangle(int aa, int bb) {a=aa; b=bb;} public int area() {return a*b;} public int girth() {return 2*(ab);} } public class xxk3 extends rectangle { private int c; public xxk3(int aa, int bb, int cc) {super(aa,bb); c=cc;} public int volume() {return area()*c;} public int arrislength() {return 2*girth()4*c;} public static void main(string[] args) { xxk3 x=new xxk3(2,3,4); int y1=x.volume(); int y2=x.arrislength(); system.out.println(y1", "y2); } }
选项:
34, 36
24, 36
题目类型:
单选题
题目:
public class settest { public static void main(string[] args) { hashset hs = new hashset(); boolean b1 = hs.add("a"); hs.add("b"); hs.add("c"); hs.add("d"); hs.add("d"); boolean b2 = hs.add("a"); system.out.println("size="hs.size()); } }
选项:
size=5
size=4
东北农业大学20秋《面向对象程序设计》作业考核试题
试卷总分:100 得分:100
一、单选题 (共 5 道试题,共 10 分)
1.假定有“struct BOOK{char title[40]; float price;}; BOOK *book;”,则不正确的语句为( )。.
A.BOOK *x=new book;
B.BOOK x={"C++ Programming",27.0};
C.BOOK *x=new BOOK;
D.BOOK *x=book;
2.假设所有变量均为整型,表达式(a=2,b=5,a>b?a++:b++,a+b)的值是( ) 。
A.7
B.8
C.9
D.2
3.当类中一个字符指针成员指向具有n个字节的存储空间时,它所能存储字符串的最大长度为( )。.
A.n
B.n+1
C.n-1
D.n-2
4.当一个类对象离开它的作用域时,系统自动调用该类的( )。.
A.无参构造函数
B.带参构造函数
C.拷贝构造函数
D.析构函数
5.一个类的成员函数也可以成为另一个类的友元函数,这时的友元说明( )。.
A.需加上类域的限定
B.不需加上类域的限定
C.类域的限定可加可不加
D.不需要任何限定
二、简答题 (共 5 道试题,共 30 分)
6.简述什么是对象,并举例说明。
7.简述类对其成员的三种存储控制及作用结果。
8.简述什么是浅拷贝和深拷贝。
9.简述静态成员函数与一般成员函数的主要差别。
10.简述多继承中构造函数被调用顺序。
三、其他题 (共 4 道试题,共 60 分)
11.请写出下面程序的运行结果: #include class Tdate{ public: Tdate(); Tdate(int d); Tdate(int m,int d); Tdate(int m,int d,int y); //其他公共成员 protected: int month; int day; int year; }; Tdate::Tdate() { month=4; day=15; year=1995; cout < 12.请写出下面程序的运行结果: 程序:#include class OBJ1{public: OBJ1(){ cout <<"OBJ1 "; }}; class OBJ2{public: OBJ2(){ cout <<"OBJ2 "; }}; class Base1{public: Base1(){ cout <<"Base1 "; }}; class Base2{public: Base2(){ cout <<"Base2 "; }}; class Base3{public: Base3(){ cout <<"Base3 "; }}; class Base4{public: Base4(){ cout <<"Base4 "; }}; class Derived :public Base1, virtual public Base2, public Base3, virtual public Base4{ public: Derived() :Base4(), Base3(), Base2(), Base1(), obj2(), obj1() { cout <<"Derived ok. "; } protected: OBJ1 obj1; OBJ2 obj2;}; void main(){ Derived aa; cout <<"This is ok. ";} 13.根据下面类中Reverse1函数成员的原型和注释写出它的类外定义。 class AA { int* a; int n; int MS; public: void InitAA(int aa[], int nn, int ms) { if(nn>ms) {cout<<"Error!"< 14.程序: #include #include class Point{ public: void Set(double ix,double iy) //设置坐标 { x=ix; y=iy; } double xOffset() //取y轴坐标分量 { return x; } double yOffset() //取x轴坐标分量 { return y; } double angle() //取点的极坐标 { return (180/3.14159)*atan2(y,x); } double radius() //取点的极坐标半径 { return sqrt(x*x+y*y); } protected: double x; //x轴分量 double y; //y轴分量 }; void main() { Point p; double x,y; for(;;){ //重复输入x和y轴分量,直到x分量值小于0 cout >x >>y; if(x<0) break; p.Set(x,y); cout <<"angle=" <



