面向对象程序设计选择题MultipleChoice_1
- 格式:doc
- 大小:43.00 KB
- 文档页数:3
ap考试选择题(multiple-choice)
AP考试中的选择题(Multiple-Choice)是一种常见的题型,通常由一个问题和若干个选项组成。
考生需要通过仔细阅读问题和选项,从中选择出最符合题意的答案。
在回答选择题时,考生需要注意以下几点:
1. 仔细阅读问题和选项,确保理解问题的要求和每个选项的含义。
2. 排除明显不符合题意的选项,缩小答案范围,提高答题效率。
3. 对于无法确定答案的问题,可以采用排除法或者猜测法进行选择。
4. 注意选择题的题干中是否有陷阱,避免因为疏忽而选错答案。
在AP考试中,选择题的分数通常占据了试卷总分的很大一部分,因此考生需要认真对待选择题的解答。
同时,考生还需要注意时间分配,避免因为时间不够而影响答题质量。
c++面向对象程序设计—考试题及习题讲解(免费下载)第一部分选择题(共20分)一、单项选择题(本大题共10小题,每小题2分,共20分)1.在C++中,函数原型不能标识( D )A.函数的返回类型B.函数参数的个数C.函数参数类型D.函数的功能p108有叙述2.在C++程序中,对象之间的相互通信通过( B ) ?A.继承实现B.调用成员函数实现C.封装实现D.函数重载实现3.对于任意一个类,析构函数的个数最多为( B )A.0B.1C.2D.3P288 析构函数不接受参数,也不返回数值。
类只可能有一个析构函数,不能进行析构函数的重载。
4.下面函数模板定义中不正确的是( A )A.templateB.templateQF(Q x){ QF(Q x){return Q+x; return x+x;} }C.templateD.templateTF(T x){ TF(T x){return x*x; return x>1;} }5.友元关系不能( c A )?A.继承B.是类与类的关系C.是一个类的成员函数与另一个类的关系p316D.提高程序的运行效率6.语句ofstream f(〃SALARY.DAT〃,ios::app|ios::binary);的功能是建立流对象f,试图打开文件SALARY.DAT并与之连接,并且( A )A.若文件存在,将文件写指针定位于文件尾;若文件不存在,建立一个新文件B.若文件存在,将其置为空文件;若文件不存在,打开失败C.若文件存在,将文件写指针定位于文件首;若文件不存在,建立一个新文件D.若文件存在,打开失败;若文件不存在,建立一个新文件7.下面说法正确的是( B )A.内联函数在运行时是将该函数的目标代码插入每个调用该函数的地方B.内联函数在编译时是将该函数的目标代码插入每个调用该函数的地方C.类的内联函数必须在类体内定义D.类的内联函数必须在类体外通过加关键字inline定义8.可以用p.a的形式访问派生类对象p的基类成员a,其中a是( D )A.私有继承的公有成员B.公有继承的私有成员C.公有继承的保护成员D.公有继承的公有成员9.在公有派生情况下,有关派生类对象和基类对象的关系,不正确的叙述是( A )A.派生类的对象可以赋给基类的对象B.派生类的对象可以初始化基类的引用C.派生类的对象可以直接访问基类中的成员D.派生类的对象的地址可以赋给指向基类的指针10.对于类定义class A{public:virtual void func1( ){ }void func2( ){ }};class B:public A{public:void func1( ){cout<<〃class B func 1〃<<end1;}< p="">virtual void func2( ){cout<<〃class B func 2〃<<end1;}< p="">};下面正确的叙述是( C )A. A::func2( )和B::func1( )都是虚函数B. A::func2( )和B::func1( )都不是虚函数C. B::func1( )是虚函数,而A::func2( )不是虚函数D. B::func1( )不是虚函数,而A::func2( )是虚函数第二部分非选择题(共80分)二、填空题(本大题共10小题,每小题2分,共20分)11.定义类的动态对象数组时,系统只能够自动调用该类的拷贝构造函数对其进行初始化。
一、单项选择题(本大题共10小题,每小题2分,共20分)在每小题列出的四个备选项中只有一个是符合题目要求的,请将其代码填写在题后的括号内。
错选、多选或未选均无分。
1.一个函数功能不太复杂,但要求被频繁调用,选用()A.内联函数B.重载函数C.递归函数D.嵌套函数2.C++的继承性允许派生类继承基类的()A.部分特性,并允许增加新的特性或重定义基类的特性B.部分特性,但不允许增加新的特性或重定义基类的特性C.所有特性,并允许增加新的特性或重定义基类的特性D.所有特性,但不允许增加新的特性或重定义基类的特性3.在C++中,封装是借助什么达到的?()A.结构B.类C.数组D.函数4.建立包含有类对象成员的派生类对象时,自动调用构造函数的执行顺序依次为()A.自己所属类、对象成员所属类、基类的构造函数B.对象成员所属类、基类、自己所属类的构造函数C.基类、对象成员所属类、自己所属类的构造函数D.基类、自己所属类、对象成员所属类的构造函数5.类的析构函数是对一个对象进行以下哪种操作时自动调用的?()A.建立B.撤消C.赋值D.引用6.下列不是..描述类的成员函数的是()A.构造函数B.析构函数C.友元函数D.拷贝构造函数7.所有在函数中定义的变量,连同形式参数,都属于()A.全局变量B.局部变量C.静态变量D.寄存器变量8.假定AB为一个类,则执行AB x;语句时将自动调用该类的()A.有参构造函数B.无参构造函数1 / 10C.拷贝构造函数D.赋值构造函数9.假定AA为一个类,a()为该类公有的函数成员,x为该类的一个对象,则访问x对象中函数成员a()的格式为()A.x.a B.x.a()C.x->a D.x->a()10.对于任一个类,用户所能定义的构造函数的个数至多为()A.0 B.1C.2 D.任意个二、填空题(本大题共10小题,每小题2分,共20分)请在每小题的空格中填上正确答案。
错填、不填均无分。
面向对象程序设计样卷一、选择题( 本大题共10小题, 每题2分, 共20分)4.在下列定义的引用中, ( B )是错误的。
A. int i;B. int i;int &j = i; float &j=i;C. float i;D. char d;float &j = i; char &e = d;5. 假定BB为一个类,则执行BB y;语句时将自动调用该类的( B )A. 有参构造函数B. 无参构造函数C. 拷贝构造函数D. 赋值重载函数7.下列对派生类的描述中, ( C )是错误的。
A. 一个派生类能够作为另一个派生类的基类B.派生类至少应有一个基类C. 基类中成员访问权限继承到派生类中都保持不变D.派生类成员除了自己定义的成员外, 还包含了它的基类成员10.控制输出格式的控制符中, ( D )是设置输出宽度的。
A.wsB.endsC. setfill()D.setw()二、填空题( 本大题共10小题, 每题2分, 共20分)1.以/*开始, 以*/结束, 在/*和*/之间的部分即为注释。
2.重载函数在参数类型或参数个数上不同, 但函数名和类名_相同。
3. 假如一个类的名称为MyClass, 使用这个类的一个对象初始化该类的另一个对象时, 能够调用__拷贝______构造函数来完成此功能。
4.当删除对象时, 程序自动调用析构函数。
5. 对于每一个类的非静态成员函数, 都有一个隐含的_this_______指针。
8. 抽象类是指类里有一个函数, 是纯嘘函数。
三、改错题( 下面程序或程序段中有一处错误, 请用注释标明错误所在行的出错原因。
本大题共5小题, 每题2分, 共10分) 1. #include<iostream>using namespace std;int main(){ cout<<"This is a program."<<endl;return 0;}2. #include<iostream>using namespace std;int main(){x=3;int y=x*x;cout<<"y="<<y<<"\n";return 0;}3. #include<iostream>using namespace std;class Aa{public:Aa(int i=0){a=i; cout<<"Constructor "<<a<<endl; } ~Aa(){ cout<<"Destructor "<<a<<endl; }void print( ){cout<<a<<endl;}private:int a;};int main(){Aa al(1),a2(2);al.print();cout<<a2.a<<endl;return 0;}4.class A{int a,b;public:A(int aa,int bb=78){a=aa;b=bb;} };int main(){A x(2), y(4,9);return 0;}5. #include<iostream>using namespace std;class Test{public:static int x;};int Test :: x=20;int main(){cout<<Test::x;return 0;}四、程序分析题( 分析程序, 写出运行结果。
模拟试题(1)一、判断对错题(10%)(对√,错×)()1.自动变量用堆方式创建,它与块共存亡。
()2.运算符+=是右结合的。
()3.表达式cout<<99的类型为int。
()4.++i是左值,但i++不是左值。
()5.Y[I][J]与*(*Y+I)+J不等价。
()6.从外部看类的private 成员和protected成员有区别。
()7.运算符&不可以重载。
()8.基类的protected成员经过protected派生,在派生类中它变成了private成员。
()9.2.0/-3.0是一个正确的表达式。
()10.字符'\12'的ASCII为12。
二、填空题(20%)#include <iostream.h>typedef struct node{long data;node * next;};class stack{private:node * head;①__________stack();~stack();void push (②__________);③__________ pop();④__________ print();};stack::stack(){ head = new ⑤__________head->next = ⑥__________ }stack::~stack(){node * p;p = head;while (p){head = head->next;⑦__________p = head;}}void stack::push(long x){node * p = new node;p->data = x;p->next = head->next;⑧__________ = p;cout<<"Push" <<x<<" ok !"<<endl;}long stack::pop(){node *p = head->next;if(p!=NULL){long x = p->data;head->next = p->next;⑨__________cout<<"pop "<<x<<" ok !"<<endl;return x;}elsecout<<"Stack is empty !"<<endl;return 0;}void stack::print(){node * p = head->next;cout<<"Stack_Top"<<endl;while (p){cout<<p->data<<endl;⑩__________;}cout<<"Stack_bottom"<<endl;}三、简答题(20%)(按条列出论点)1.注解。
电子系计控专业《面向对象的程序设计》期末试卷(A)答案一、选择题(每题1分,共20分)1、如果要改变窗体的标题,则需要设置的属性是 A 。
A. CaptionB. NameC. BackColorD. BorderStyle2、工程文件的扩展名是_C_。
A. frx B. bas C. vbp D.frm3、初始状态下,VB工具箱的控件称为_A_。
A. 标准控件(或内部控件)B. 外部控件C. ActiveX控件D. 可插入对象4、将命令按扭Command1设置为不可见,应修改命令按钮的 A 属性。
A. VisibleB. ValueC. CaptionD. Enable5、在窗体上画三个单选按钮,组成一个名为chkOption的控件数组。
用于标识各个控件数组元素的参数是 B 。
A. TagB. IndexC. ListIndexD. Name6、要改变控件的高度,应修改控件的_D_属性。
A. Top B. Left C. Width D. Height7、只能用来显示字符信息的控件是 B 。
A. 文本框 B. 标签 C. 图片框 D. 图象框8、InputBox$(函数返回值的类型为 B 。
A. 数值B. 字符串C. 变体D. 数值或字符串(视输入的数据而定)9、确定复选框是否选中,可访问的属性是_A_。
A. Value B. CheckedC. SelectedD. Caption10、选中复选框时,Value的值为 B 。
A. 0 B.1 C. True D. False11、添加列表框中的项目,应该用列表框的 C 属性。
A. Selected B. Value C. List D. Text12、若要在同一窗体中安排两组单选按扭,可用_D_控件来分隔。
A. 列表框B. 组合框C. 图片框D. 框架13、用户可以通过设置菜单项的_C_属性的值为False来使该菜单项失效。
A. HideB. VisibleC. EnableD. Checked14、在程序运行期间,如果拖动滚动条上的滚动块,则触发的滚动事件是 C 。
c面向对象程序设计考试试题C++面向对象程序设计考试试题C++是一种广泛应用于软件开发的编程语言,而面向对象程序设计是C++的核心概念之一。
在C++面向对象程序设计的考试中,学生需要掌握C++的基本语法和面向对象的思想,并能够灵活运用这些知识解决实际问题。
本文将介绍一些可能出现在C++面向对象程序设计考试中的试题,并给出相应的解答。
1. 什么是面向对象程序设计?面向对象程序设计是一种编程范式,它将程序中的数据和操作数据的方法封装在一起,形成对象。
对象可以通过定义类来创建,类是对象的抽象描述。
面向对象程序设计的核心概念包括封装、继承和多态。
2. 什么是类和对象?类是对一类具有相同属性和行为的对象的抽象描述。
它定义了对象的属性和方法。
对象是类的实例化,通过类可以创建多个对象。
对象具有类定义的属性和方法,并且可以通过调用方法来操作对象的属性。
3. 什么是封装?封装是面向对象程序设计的一种重要特性,它将数据和操作数据的方法封装在一起,对外部隐藏具体实现细节。
通过封装,可以保证数据的安全性和完整性,并提供接口供外部访问和操作数据。
4. 什么是继承?继承是面向对象程序设计的一种重要机制,它允许一个类继承另一个类的属性和方法。
被继承的类称为父类或基类,继承的类称为子类或派生类。
通过继承,子类可以重用父类的代码,并且可以添加自己的属性和方法。
5. 什么是多态?多态是面向对象程序设计的一种重要特性,它允许同一类型的对象调用不同类的方法。
多态通过虚函数和函数重写实现。
通过多态,可以提高代码的灵活性和可扩展性。
6. 请写一个简单的C++类和对象的例子。
```cpp#include <iostream>using namespace std;class Circle {private:double radius;public:Circle(double r) {radius = r;}double getArea() {return 3.14 * radius * radius;}};int main() {Circle c(5.0);cout << "Area: " << c.getArea() << endl;return 0;}```上述代码定义了一个Circle类,它具有一个私有的radius属性和一个公有的getArea方法。
Java面向对象程序设计试题一答案一、单项选择题:选择第1题:B选择第2题:A选择第3题:C选择第4题:B选择第5题:A选择第6题:A选择第7题:B选择第8题:C选择第9题:B选择第10题:B二、多项选择题多项选择第1题:AB多项选择第2题:BD多项选择第3题:AD多项选择第4题:AD多项选择第5题:BCD多项选择第6题:AB多项选择第7题:ABCD多项选择第8题:ABCD多项选择第9题:BC多项选择第10题:BC三、填空题答案填空第1题:x=10,a=3,b=4,c=5填空第2题:java.util填空第3题:(public )(static )(void)(main)(String args[])填空第4题:1填空第5题:26四、编程题答案1public class HelloWorld{public static void main(String args[]){System.out.println("Hello,World!");}}import java.awt.Graphics;import java.applet.Applet;public class HelloWorld extends Applet{String s;public void init(){s="Hello World!";}public void paint(Graphics g){g.drawString(s,25,25);}}2class yanghui{public static void main (String args[]){int i,j;int yhlevel=10;int yanghui[][];System.out.println("杨晖三角形:");yanghui=new int[yhlevel][];for(i=0;i<yanghui.length;i++)yanghui[i]=new int[i+1];yanghui[0][0]=1;for (i=1; i<yanghui.length;i++){yanghui[i][0]=1;for(j=1;j<yanghui[i].length-1;j++)yanghui[i][j]=yanghui[i-1][j-1]+yanghui[i-1][j];yanghui[i][yanghui[i].length-1]=1;}for (i=0; i<yanghui.length;i++){for(j=0;j<yanghui[i].length;j++)System.out.print(yanghui[i][j]+" ");System.out.println();}}}输出结果是:杨晖三角形:11 11 2 11 3 3 11 4 6 4 11 5 10 10 5 11 6 15 20 15 6 11 7 21 35 35 21 7 11 8 28 56 70 56 28 8 11 9 36 84 126 126 84 36 9 13import java.io.*;public class MemoController{FileOutputStream fos;OutputStreamWriter osw;BufferedWriter bw;public MemoController(){try{fos=new FileOutputStream("memo.txt",true);osw=new OutputStreamWriter(fos);bw=new BufferedWriter(osw);}catch(FileNotFoundException e){};}public synchronized void append(String s){try{bw.write(s,0,s.length());bw.flush();bw.close();osw.close();fos.close();}catch(IOException e){}}public static void main(String args[]){MemoController mmc=new MemoController();mmc.append("I am xubin ");}}4import java.io.*;class Phones{static FileOutputStream fos;public static final int lineLength = 81;public static void main(String args[]) throws IOException{byte[] phone = new byte[lineLength];byte[] name = new byte[lineLength];int I;try{fos = new FileOutputStream("phone.numbers");}catch(FileNotFoundException e){ }while (true){System.err.println("Enter a name (enter 'done' to quit)");readLine(name);if ("done".equalsIgnoreCase(new String(name,0,0,4))){break;}System.err.println("Enter the phone number");readLine(phone);for (int i=0;phone[i]!= 0;i++){fos.write(phone[i]);}fos.write(',');for (int i=0;name[i]!= 0;i++){fos.write(name[i]);}fos.write('\n');}fos.close();}private static void readLine(byte line[]) throws IOException{int i=0,b=0;while ((i<lineLength-1)&&((b=System.in.read())!='\n')){line[i++] = (byte)b;}line[i]=(byte) 0;}}5、import java.util.*;import java.text.*;class ThreeTimeThread extends Thread{public ThreeTimeThread(String str){super(str);}public void run(){while (true) {SimpleDateFormat formatter = new SimpleDateFormat ("yyyy.MM.dd G 'at' hh:mm:ss z");Date currentTime = new Date();try {sleep(1000);}catch (Exception e) {}String dateString = formatter.format(currentTime);System.out.println(getName()+":"+dateString);}}public static void main(String args[]) throws Exception{new ThreeTimeThread("first").start();new ThreeTimeThread("second").start();new ThreeTimeThread("third").start();}}。
第6章面向对象程序设计一. 选择题1.下面有关类和对象的说法中, 不对的的是【】。
A) 类是系统提供的一种数据类型B) 对象是类的实例C) 类和对象的关系是抽象和具体的关系D) 任何一个对象只能属于一个具体的类2. 面向对象的特点重要概括为【】。
A) 可分解性、可组合型性和可分类性B) 继承性、封装性和多态性C) 封装性、易维护性、可扩展性和可通用性D) 抽象性、继承性和封装性3. 要使一个类能被同一命名空间中的其他类访问, 但不能被这个命名空间以外的类访问, 该类可以【】。
A) 不使用任何修饰符B) 使用private修饰符C) 使用public修饰符D) 使用internal修饰符4. 在C#中, 【】访问修饰符修饰的字段只能由当前程序集访问。
A) private B) public C) protected D) internal5. 类的字段和方法的默认访问修饰符是【】。
A) public B) private C) protected D) internal6. 下列关于构造函数的描述中, 不对的的是【】。
A) 构造函数中, 不可以包含return语句B) 一个类只能有一个构造函数C) 实例构造函数在生成类实例时被自动调用D) 用户可以定义无参构造函数7. 下列关于构造函数的描述中, 【】是对的的。
A) 构造函数名必须与类名相同B) 构造函数不可以重载C) 构造函数不能带参数D) 构造函数可以声明返回类型8. 下列的【】不是构造函数的特性。
A) 构造函数的函数名与类名相同B) 构造函数可以重载C) 构造函数可以带有参数D) 可以指定构造函数的返回值类型9. 类ClassA有一个名为M1的方法, 在程序中有如下一段代码, 假设该段代码是可以执行的, 则声明M1方法时一定使用了【】修饰符。
ClassA Aobj=new ClassA();ClassA.M1();A) public B) public static C) private D) virtual10. 在C#中, 从属性的读写特性上来进行分类, 可以划分为以下3种, 除了【】。
Multiple-Choice Quiz 11. The name of a Java source file(a) must be the same as the class it defines, respecting case(b) has no restrictions(c) must use the extension .class(d) must be the same as the class it defines, ignoring case2. What will be output caused by the execution of the following Java program segment? String name = "Elvis";System.out.print(name + "was here");(a) name + was here(b) Elviswas here(c) name was here(d) Elvis was here3. What is the name of the wrapper class for the type int?(a) Integer (b) integer(c) Int (d) INT4. Consider the following Java program segment.int x = 5;int y = 2;System.out.println(x + "1" + y);Which of the following statements is true about the program segment?(a) The output caused by the code will be 512.(b) The code will cause a compilation error.(c) The output caused by the code will be 5 1 2.(d) The output caused by the code will be 8.5. A difference between the methods print and println of the class java.io.PrintWriter is that(a) print inserts a new line at the beginning of its output, but println does not(b) print appends a new line to the end of its output, but println does not(c) println appends a new line to the end of its output, but print does not(d) println inserts a new line at the beginning of its output, but print does not6. All Java exception classes are derived from the class(a) ng.RuntimeException(b) ng.Error(c) java.io.IOException(d) ng.Throwable7. What is the right way to handle abnormalities in input on Java?(a) By handling these problems by providing exception handlers(b) By always specifying the throws clause in every method header where file I/O is performed(c) By using the class FileFilter which gracefully filters out bad input data(d) By writing while loops to guard against bad input8. According to Javadoc convention, the first sentence of each Javadoc comment should be(a) an @author tag(b) a summary sentence of the declared entry(c) the order of lines is not important(d) an @version tag9. According to the Java code conventions, files longer than _____ lines should be _____.(a) 2000, encouraged (b) 100, avoided (c) 100, encouraged (d) 2000, avoided10. In a typical source-code debugger, a programmer can set a _____ to cause a program to stop executing at a particular line of code.(a) test case (b) print statement (c) breakpoint (d) stack trace11. Given the following code, how many tokens will be output?StringTokenizer st = new StringTokenizer("this is a test");while (st.hasMoreTokens()) {stdOut.println(st.nextToken() );}(a) 3 (b) 4(c) 1 (d) 012. What will be output when the following Java program segment is executed?int x = 5;int y = 2;System.out.println(x + y);(a) 7 (b) 5 2 (c) 5+2 (d) 5213. Consider the following Java program segment.import java.io.*;public class SomeClass{public void x() {throw new RuntimeException("Exception from x");}public void y(){throw new IOException("Exception from y");}}Which of the following is true concerning the definitions for the methods x and y?(a) x has an illegal definition, but y has a legal definition.(b) Both x and y have legal definitions.(c) x has a legal definition, but y has an illegal definition.(d) Neither x nor y has a legal definition.14. Which of the following patterns of characters opens a Javadoc comment block?(a) /** (b) // (c) **/ (d) /*15. Which of the following statements is true of the conventions outlined by Sun Microsystems in the document entitled Code Conventions for the Java Programming Language?They define a standard interface definition language that must be used for all Java classes.They provide recommendations intended to make source code easier to read and understand.They describe one mechanism for network communication between Java and C++ programs.(a) I and III only (b) II only (c) I, II, and III (d) III only16. The term wrapper classes refers to(a) the Java classes that contain themselves(b) a collection of Java classes that "wrap" Java primitive types(c) a collection of Java classes that contain other Java classes(d) the Java classes that contain at least two data fields17. In Java, exceptions that are not handled are passed up the(a) call stack(b) exception ladder (c) catch blocks (d) block hierarchy18. According to the Java code conventions, files that contain Java source code have the suffix _____, and compiled bytecode files have the suffix _____.(a) .class, .java (b) .java, .class (c) .class, .javac (d) .javac, .class19. As an aid in debugging a program in Java, print statements may be used to display which of the following types of information?The names of methods being calledThe values of the parameters of a methodThe values of the instance variables of a class(a) I, II, and III(b) II and III only (c) I and II only (d) I and III only20. Which method must exist in every Java application?(a) main (b) paint (c) init (d) begin21. Which of the following statements is (are) true about the use of an asterisk (*) in a Java import statement?It does not incur run-time overhead.It can be used to import multiple packages with a single statement.It can be used to import multiple classes with a single statement.(a) I and III only(b) I, II, and III (c) I only (d) III only22. Given the following code, what value will be output by the last statement? StringTokenizer st = new StringTokenizer("this is,a,test of tokens", ",");String s;int count = 0;while (st.hasMoreTokens()) {s = st.nextToken();++count;}stdOut.println(count);(a) 1 (b) 4 (c) 6 (d) 323.According to the document entitled Code Conventions for the Java Programming Language, file suffixes used by Java software include which of the following?.obj.class.h(a) I and III only (b) II and III only (c) I and II only (d) II only24. Which of the following is the string concatenation operator in Java?(a) & (b) + (c) ++ (d) ^25. A stack trace is(a) a sequence of method calls(b) only available through a typical debugger's step into feature(c) a fatal error that causes a typical debugger to terminate(d) a list of variables allocated on a program's stack。