1. Trang chủ
  2. » Giáo án - Bài giảng

WM nguyên lý ngôn ngữ lập trình nguyễn hứa phùng tests quizzes sinhvienzone com

46 62 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 46
Dung lượng 674,93 KB

Nội dung

Quiz 1: INTRO Question of 10 1.0 Points int x[10]; x[10] = 10; C++ lets you write to an element outside the array Based on this design, which criteria of C++ is negative? om Readability Reliability Cost Writability C A B C D 1.0 Points ne Question of 10 1.0 Points nh Question of 10 en Reliability Cost Readability Writability Vi A B C D Zo In Algol There is no reserved word, so there may be a valid if statement like: if if = then then…Based on this design, which criteria is negative? Si Although being statically type checking, Java performs dynamic type checking For example, Java is able to prevent an access to an element outside an array such as int a[10], y; y = 12; x[y] = 12; which criteria is negative by this design? A B C D Cost Writability Readability Reliability CuuDuongThanCong.com https://fb.com/tailieudientucntt Question of 10 1.0 Points Given the following code that contains an syntax error at the second line: cout D y.foo() -> B z.foo() -> A om not match -> C 1.0 Points C Question of 10 Question of 10 en Zo A.foo() may call foo defined in A, in B or in C B.foo() may call foo defined in A or in B B.foo() may call foo defined in B or in C A.foo() may call just foo defined in A B.foo() may call just foo defined in B 1.0 Points Vi A B C D E ne Assume that class A is the superclass of class B and class B is the superclass of class C There are declarations of static method foo in class A, B and C Add the following line in class ABC, var sfields: Int Add the following line in object ABC, static var sfields: Int Add the following line in object ABC, var sfields: Int Add the following line in class ABC, static var sfields: Int Si A B C D nh To declared a static fields sfields for class ABC in Scala, how must programmers write? Question of 10 1.0 Points In Scala, to declare class ABC as a subclass of class DEF, how must programmers write? A B C D class DEF extends ABC class DEF super ABC class ABC extends DEF class ABC: DEF CuuDuongThanCong.com https://fb.com/tailieudientucntt Question of 10 1.0 Points Given the following code in Scala, abstract class A { def cal(x: Int): Int } trait B extends A { abstract override def cal(x: Int): Int = super.cal(x * 2) } trait C extends A { abstract override def cal(x: Int): Int = super.cal(x + 1) } class D extends A { def cal(x: Int): Int = x } om val t = new D with B with C println(t.cal(5)) ne 11 12 Other value Zo A B C D .C What is the printed value? 1.0 Points en Question of 10 Vi How to define a member which can only be accessed inside the object? For example, class X { var f: Int // n * n List(1, , 9) n => n + n n*n en A B C D ne Select the right answer to fill the blank to return List(1, 4, 9) 1.0 Points Vi Question of 10 Which is the implementation of the factorial function? nh def fact(n: Int) = 1.to(n).foldLeft(0)(_ * _) def fact(n: Int) = 0.to(n).foldLeft(1)(_ * _) def fact(n: Int) = 1.to(n).foldLeft(0)(_ + _) def fact(n:Int)= 1.to(n).fodLeft(1)(_ * _) Si A B C D Question of 10 1.0 Points Select the right implementation(s) for the sum function? (There are some syntax error in the code to prevent copy and paste) A B C D def sum(lst: List[Int]): Int = if (lst.isEmpty) else lst.head + lst.tail def sum(lst: List[Int]) = lst.foldLeft(0)(_ + _) def sum(lst: List[Int]): Int = lst.head + sum(lst.tail) def sum(lst: List[Int]): Int = if (lst.isEmpty) else lst.head + sum(lst.tail) CuuDuongThanCong.com https://fb.com/tailieudientucntt Quiz 8: Name Question of 10 1.0 Points Given the following C code, int p[10]; int foo(int x) { static int q [10] ; om int r [10] ; int s = new int [10] ; switch ( x ) { C case : return p ; ne case : return q ; case : return r ; Zo case : return s ; default : foo ( x+1); en } Vi } Which following statements are WRONG? Check all that apply nh A Array r is allocated in stack memory Si B Array q is allocated in stack memory C Array p is allocated in stack memory D Array p is allocated in static memory E Array r is allocated in heap memory F Array pointed by s is allocated in heap memory G Array q is allocated in static memory H Array pointed by s is allocated in stack memory CuuDuongThanCong.com https://fb.com/tailieudientucntt Question of 10 1.0 Points Given the code in question 1, which following statements are CORRECT? Check all that apply A The lifetime of array p is equal to the lifetime of foo B The lifetime of array p is equal to the lifetime of whole program C The lifetime of array q is equal to the lifetime of foo D The lifetime of array p is equal to the lifetime of whole program om E The lifetime of array r is equal to the lifetime of foo F The lifetime of array r is equal to the lifetime of whole program C G The lifetime of array pointed by s is equal to the lifetime of foo ne H The lifetime of array pointed by s is equal to the lifetime of whole program 1.0 Points Zo Question of 10 en Given the code in question 1, which statements may cause runtime problem (dangling reference)? B return s; nh C return q; Vi A return r; Si D return p; Question of 10 1.0 Points Given the code in question 1, when foo is called recursively, which arrays are the same among foo executions? Check all that apply A p B q C r D pointed by s CuuDuongThanCong.com https://fb.com/tailieudientucntt Question of 10 1.0 Points Given the code in question 1, which array may become garbage? Check all that apply A pointed by s B q C r om D p Question of 10 C What will happen when executing the following code? 1.0 Points ne int *p = new int; int *q = p; *p = 1; Zo A dangling reference en B polymorphism C garbage Vi D alias nh E undeclared pointer 1.0 Points Si Question of 10 What is the binding time of the real address of variable count in the following C code? static int count; A programming B compiling C running D loading E implementation CuuDuongThanCong.com https://fb.com/tailieudientucntt Question of 10 1.0 Points Given the following program var x; //1 procedure sub1() { var x;//2 call sub2(); om } procedure sub2() { C x // use x ne } main(){ Zo call sub1(); } en Assume that the program is written in a static-scoping language and calling chain is main to sub1 to sub2, which declaration is referred by x in sub2? Vi A it is referred to x that is declared at //1 in one time and at //2 in another time nh B it is referred to x that is declared at //2 C it is referred to x that is declared at //1 Si D error message: x is undeclared Question of 10 1.0 Points Given the code in question 8, assume that the program is written in a static-scoping language, select all statements that are CORRECT A The referencing environment of x declared at //2 is sub2 and main B Scope of main is x declared at //1, sub1 and sub2 C The referencing environment of main is x declared at //1, sub1 and sub2 D Scope of x declared at //1 is sub2 and main CuuDuongThanCong.com https://fb.com/tailieudientucntt Question 10 of 10 1.0 Points Given the code in question 8, if the program is written in a dynamic-scoping language and calling chain is main to sub1 to sub2, which declaration of x is referred by x in sub2? A it is referred to x that is declared at //1 B it is referred to x that is declared at //2 C it is referred to x that is declared at //1 in one time and at //2 in another time Si nh Vi en Zo ne C om D error message: x is undeclared CuuDuongThanCong.com https://fb.com/tailieudientucntt Quiz 9: Data Type Question of 10 1.0 Points Which statement is NOT true? (Character) A C and C++ use ASCII code B Java uses UNICODE code C A value in character type is stored as a number representing the ASCII/UNICODE code of the value .C 1.0 Points ne Question of 10 Which statement is NOT true? (Enumerate) om D UNICODE code is originally used in C# Zo A In C#, enumerate type variable can't be assigned a value outside its defined range B Enumerate types make program more readability en C In C#, enumerate type variables are coerced into integer types 1.0 Points nh Question of 10 Vi D Enumerate types are implemented as integers Which statement is NOT true? (Float) Si A 011111000 equals to 28 (using IEEE 754 standard with exponent part has bits) B In IEEE 754 standard, floating point data type needs at least bytes C Floating point data type can't model real number exactly D In floating point data type, the number of bits use for fraction part is larger than the number of bits use for exponent part CuuDuongThanCong.com https://fb.com/tailieudientucntt Question of 10 1.0 Points Which statement is NOT true? (Boolean) A To implement Boolean data type, we use at least bits B Boolean data type is the simplest one C Boolean data type has only two values om D Using Boolean data type makes program more readability Question of 10 C Which statement is NOT true? (Integer) 1.0 Points B C and C++ offer unsigned integers C Java doesn't offer unsigned integers ne A Integer data type is the simplest data type en Zo D Integer data type is supported directly by hardware Question of 10 1.0 Points Vi Which statement is NOT true? (Union) nh A The size of a union variable is identified at run time B C and C++ don't support type checking in union type Si C Union type is an unsafe construct D Java and C# don't have union type Question of 10 1.0 Points Which statement is NOT true? (Array) A Storage allocation of stack-dynamic array is done at run time B Heap-dynamic array size can change at run time C Fixed stack-dynamic array does not run efficiently D Static arrays are efficient and flexible CuuDuongThanCong.com https://fb.com/tailieudientucntt Question of 10 1.0 Points Which statement is NOT true? (Record) A Elements in record may have different types B Record use dynamic subscripting C In C++, objects are used as records om D In C++, there are two main types of record member reference Question of 10 C Which statement is NOT true? (Decimal) 1.0 Points A Java offers decimal data type ne B COBOL is used essentially in business application Zo C C# offers decimal data type en D Decimal data type uses effectively memory Question 10 of 10 1.0 Points Vi Which statement is NOT true? (String) nh A In C, C++, string is implemented as character array B COBOL is used essentially in business application Si C Java string length is identified at compile time D C and C++ store the string length in the run time descriptor CuuDuongThanCong.com https://fb.com/tailieudientucntt Quiz 10: Sequence Control Question of 10 1.0 Points Rewrite the following infix expression using Cambridge Polish prefix format? a+b*c+d+e*f A + + + a * b c d * e f B + a * b c d * e f C (+ (+ (+ a (* b c)) d) (* e f)) om D (((a + (b * c)) + d) + (e * f)) C E (+ a (* b c) d (* e f)) ne Question of 10 1.0 Points Zo Rewrite the following infix expression using the Polish postfix format? Assume that all operators have operands A a b c * d e f * + Vi B a + b c * d + e f * + en a+b*c+d+e*f C a b + c * d + e f * + nh D a b c * + d + e f * + Si E a b c * d e f * + + + CuuDuongThanCong.com https://fb.com/tailieudientucntt Question of 10 1.0 Points Rewrite the following infix expression using the Polish prefix format? Assume that every operator has only operands a+b*c+d+e*f A + a * b c d * e f B + + a * b c + d * e f C + a * b c + + d * e f om D + + + a * b c d * e f C E + a * b c + d * e f 1.0 Points ne Question of 10 Select all possible result of the following C expression: Zo a + (a = 2) * a Assume that variable a contains value before the above expression is evaluated en A Vi B D 10 Si E nh C CuuDuongThanCong.com https://fb.com/tailieudientucntt Question of 10 1.0 Points In some language like ADA, there are two kinds of AND/OR operator: short-circuit (AND THEN) and non-short circuit(AND).Select logical expressions that are required shortcircuit evaluation? A (a > 0) && (b > 0) B (a != b) && (a * b > 0) C (a > 0) && (sqrt(a) > 2) //sqrt is the function to calculate the square root of its om parameter D (i < a.length) && (a[i] > 0) C E (a == 0) || ((b / a) > 5) 1.0 Points ne Question of 10 Zo Given the grammar of if statement, select the language that there is NO dangling else problem en A → if then else | if then Vi B → if () else nh | if () C → if then else Si | if then endif D → E → if n else the if \n ( \n)+ else \n ( \n)+ | if \n ( \n)+ CuuDuongThanCong.com https://fb.com/tailieudientucntt goto out C i = i + goto loop ne out: Zo How many times does the following for statement iterate? j = 1; Vi for i:= to n by j j++; D Si C 15 nh A 10 B infinite en n := 10; CuuDuongThanCong.com https://fb.com/tailieudientucntt Question of 10 1.0 Points C om Given the following control flow, ne Select the code that implements the above control flow? A while (condition) { Zo action } B action nh action Vi while (condition) { en action } Si action C for (action 1;condition;action 1) action D { action if (condition) break action } while (true); CuuDuongThanCong.com https://fb.com/tailieudientucntt E while (true){ action if (! condition) break; action }; 1.0 Points om Question 10 of 10 Given the following C code, while (i > n) { // line while (k > p) { // line s += k; Zo if (s > 1000) break; // line en k ; nh } Vi } j ; //line8 ne C while (j > m) { //line } //line 12 Si i ; //line 10 Where does the control come when the break at line is executed? A Line B Line C Line 12 D Line E Line 10 CuuDuongThanCong.com https://fb.com/tailieudientucntt ... → ID COMMA | ID A → (ID COMMA ID)* B → ID (COMMA ID)+ C → ID D → (ID CuuDuongThanCong .com (COMMA ID)* COMMA)* ID https://fb .com/ tailieudientucntt... used? om Compiler Hybrid Compiler and Interpreter Just-In-Time Compiler Pure Interpreter C A B C D 1.0 Points ne Question of 10 Vi en Compiler Hybrid Compiler and Interpreter Just-In-Time Compiler... CuuDuongThanCong .com https://fb .com/ tailieudientucntt Question of 10 1.0 Points Given the following C++ code that contains the error in the first line: int wrong@id; Which phase of compilation process

Ngày đăng: 30/01/2020, 22:17

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN