CIS 346 Final Exam

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

The array below is stored in memory in row-major order: Array X 1 2 3 578 642

1, 2, 3, 5, 7, 8, 6, 4, 2

Given the grammar below, what is an example of a terminal? assign --> <id > = <expr> <id> --> A. | B. | C <expr> --> <id> + <expr>. | <id> - <expr> | (<expr>). |. <id>

A

In Python, Which statement is true about inheritance? Select one:

A class can serve as a base class for multiple derived classes.

Which of the following is true regarding subclasses?

A subclass inherits methods and instance variables from its superclass

Designed by a committee and ancestor of many languages

ALGOL

Which of the looping statements is/are supported by PHP? i) for loop ii) while loop iii) do-while loop iv) foreach loop

All of the mentioned

Compare and contrast an interpreter and a compiler including function, speed, and a language example

An interpreter produces a result of a program whereas a compiler produces a program written from assembly language. An interpreter takes less time to analyze the source code and a compiler takes more time to analyze the source code. The execution of a compiler is faster than an interpreter. An example of an interpreted language is python An example of a compiler language is COBOL.

Homogeneous Complex Data Structure

Array

In the production rule: <id> --> A | B |C, what is an example of a terminal?

B

First creator of a way to describe languages using terminals, non-terminals, and rules

Bachus

Identify which relationship of the everyday items is an isa relationship.

Basketball/Sport

Used for system software. Language often used for systems programming

C

This language was used for business and written by Grace Hopper Business oriented language with many key words

COBOL

Explicit change of type by the programmer

Cast

Like a global variable used when all members of a class use the same variable

Class variable

Change in type by the compiler

Coercion

Implicit change of type by the complier

Coercion

Implicit change of variable type carried out by the compiler

Coercion

Implicit type change by the compiler

Coercion

Scheme term used for multiple selection

Cond

What is the major problem a top-down parser must solve?

Determining the correct grammar rule RHS for the leftmost terminal.

Which loop is an example of a post-test loop?

Do-While loop

Type checking at run time

Dynamic

Compact version of BNF, using {} and

EBNF

Which of the following is not a portion of a grammar?

End Symbol

The context free grammar S --> SS. | 0S1. | 1 S). |. e

Equal number of 0's and 1's

Word used in Java to create a subclass

Extends

Oldest high level language, beloved by engineers

FORTRAN

All variable names in programming languages begin with a letter.

False

In Python, lists, strings and tuples are all mutable

False

It is possible to create integers, strings, floats, and arrays in PHP. but not objects.

False

Name and briefly describe four of the six attributes of a variable; give an example of 3.

Four out of the six attributes of a variable are an identifier, data location, type, and value. An identifier is a name you give a variable. An example of that is a social security number or an employer identification number. The type is an attribute that tells the compiler or the interpreter how the data will be used. For example information that contains text has a data type of a string. A value is the representation of that particular variable. Values belong to different times. For example a value of a type might be the character string HelloWorld.

Data with no path to it

Garbage

Accessor methods

Get methods are commonly referred to as,

Show the output: class Person: def __init__(self, name): print('Hello,', name) self.__name = name def talk(self): print('What do you want me to say?') def getName(self): return self.__name class Spaniard(Person): def __init__(self, name): print('Spanish power!') super().__init__(name) def talk(self): class Russian(Person): def __init__(self, name): print('Long live the Federation!') super().__init__(name) def main(): person2 = Russian('Vladimir') person3 = Spaniard('Jose') person3.talk() person2.talk() main()

Hello Vladimir Long live the Federation! Hello Jose Spanish power! What do you want me to say?

In the production rule: <id> --> A | B |C, what is an example of a non-terminal?

ID

Allows a new class to use members of its parent's class

Inheritance

_____ is a concept where the derived class acquires the attributes of its base class

Inheritance

Which of these are primitive data types?

Integer, double, boolean,float

Which of the following is considered an object-oriented language?

JAVA, C++

A multi-dimensional array with uneven length rows is called:

Jagged

popular Language born as Sun Microsystems Modern object-oriented language

Java

One of the first AI languages

LISP

Smallest Unit of a language

Lexeme

The smallest unit of a language is a(n):

Lexeme

Part of the compiler that finds lexemes

Lexer

Parameter passing method using pointers

Pass by reference

This language supports dynamic arrays

Python

Heterogenous Complex data structure

Record

A Functional Language

Scheme

Functional language used for AI

Scheme

Mutator methods

Set methods are commonly referred to as,

Describe in English sentences the action of the Scheme function below. (DEFINE (fun1 atm lis) (COND ((NULL? lis) #F)) ((EQ? atm (CAR lis)) #T) (ELSE (fun1 atm (CDR lis))) ) )

The function fun1 takes an atom and a list and returns True if the atom is in the list otherwise returns False.

Describe the process of mark-sweep and reference counter methods of reclaiming garbage. What is the major difference between them?

The mark phase is when an object is created its mark bit is set to false (0). In the Mark phase, we set the marked bit for all the reachable objects (or the objects which a user can refer to) to 1(true). To perform this operation we do a depth-first search . In the sweep phase, it clears the heap memory for all the unreachable objects. All objects set to false are cleared from the heap memory, for all other objects (reachable objects) the marked bit is set to true. Reference counting. Reference counting garbage collection is where each object has a count of the number of references to it. Garbage is identified by having a reference count of zero. An object's reference count is incremented when a reference to it is created, and decremented when a reference is destroyed.

Each object of a Java class can refer to itself with this key word

This

Category of smallest unit of a language

Token

location in memory associated with a variable

address

Explicit change of type by the programme

cast

In Python, which of the following is the correct syntax for defining a class, table, which inherits from the furniture class?

class table(furniture):

Happens at run time

dynamic binding

Which of the following is a User-defined data type?

enum (Mon, Tue, Wed, Thur Fri, Sat, Sun);

Parameters found in a function

formal

address of a variable

lvalue

The ____ of a declaration is the portion of a program that can refer to the entity in question by name.

scope

part of program where a variable is visible

scope

range of statement over which a variable is visible

scope

Meaning of language statements

semantics

T/F : 3 < 2. and ( X > 7)

short circuit evaluation

__________________ may be either primitive data types of complex data types depending on the language.

strings

Interface to and actions of a subprogram

subprogram definition

The rules of a language

syntax

Each object of a Java class can refer to itself with this key word

this

Which of the following is the correct syntax for creating an array in PHP?

$basket = array("Watermelon", "Chicken", "Grape Drink");

class Car { // constructor should be public public function __construct($model, $year) { $this->model = $model; $this->year = $year; } // for external use public function print_details() { echo "This car is" . $this->year. " ". $this->model . "\n"; } } Give the code to create a 2020 Prius named myCar.

$myCar = new car ("Prius", 2020);

All variable names in programming languages begin with a letter.

'False'.

Which of the following is not a possibility for short circuit evaluation?

(X > 2 ) || (z < 7)

Given the list (This (is just) another quiz}, which sequence will get "another" out of the list?

(car (cdr (cdr lst)))

Which of the answers is correct? i) in a BNF rule, the LHS must always be a non-terminal ii). terminals may be lexemes iii) In a BNF rule, the RHS is always a terminal iv). in a BNF rule, both RHS and LHS must be the same, either terminal or non-terminal.

(i) and (ii)

(define (DoList Lst) (if (null? Lst ) 0 (+ (car Lst) (DoList (cdr Lst))))) (define things ' (1 3 4 2 6)) What is: (DoLst things)?

16

Class Healthcare has the methods Pharmacy() and Labs(). Class Hospitals is derived from Healthcare and has the methods Doctor(), Patients(), and Nurses(). After h = Hospitals() executes, how many different methods can h call, ignoring constructors? Select one:

5

Given the grammar below, what is an example of a non-terminal? assign --> <id > = <expr> <id> --> A. | B. | C <expr> --> <id> + <expr>. | <id> - <expr>

<id>, <expr>

First language designed with BNF Designed by a committee; ancestor of many languages.

ALGOL

Another word for a "getter" method is

Accessor

Parameters found in the main program

Actual

When an object in a program has more than one name, we say it has a(n )

Alias

Designed for beginners, but still in use

BASIC

Notations for describing Language Rules

Bacchus-Naur Form,

Give the result for 4, 6, 3: a, b, c = eval(input('Enter three numbers:')) if a > b if b > c: print("Spam please") else: print("It is a late parrot") elif b > c: print("cheese shoope") if a >= c: print ("Checcar") elif a < b: print("gouda") elif c == b: print("Swiss") else: print("trees") print("done")

Cheese shoppe, Cheddar, done

This language translator converts the source code into 0s and 1s, using syntax rules.

Compiler

Change in type by the programmer

Conversion

Pointer pointing nowhere useful

Dangling pointer

What is the size of an int data type?

Depends on the system/compiler

True or False? One of the main advantages of Java is that it allows multiple inheritance.

False

Older language, used for mathematics and engineering. Early high level language good for engineering

Fortran

var x, y, z; function sub1() { var a, y, z; function sub2() { var a, b, z; . . . } . . . } function sub3() { var a, x, w; . . . } List all the variables, along with the program units where they are declared, that are visible in the bodies of sub1, sub2, and sub3, assuming static scoping is used.

In Sub1, a, y, z is declared there while the declaration of x is found in main. In Sub2, a, b, z is declared, declaration of y is found in sub1 and declaration of x is found in main. In Sub3, a, x, w is declared while the declaration of y, z is from the main.

____________. Allows a new class to use members and methods of the class it extends.

Inheritance

This language translation software processes code 1 line at a time.

Interpreter

A grammar is ambiguous if:

It has more than one leftmost derivation for a sentence

class Item: def __init__(self): self.name = 'None' self.quantity = 0 def dsp_item(self): print("Name: {}, Quantity:{}" .format(self.name, self.quantity)) class Produce(Item): # Derived from Item def __init__(self): Item.__init__(self) # Call base class constructor self.expiration = '01-01-2000' def dsp_item(self): Item.dsp_item(self) print("Expiration: {}".format(self.expiration)) n = Produce() n.dsp_item() Select one:

Name: None, Quantity: 0 Expiration: 01-01-2000

A ______________________ conversion converts a value to a type that cannot hold even approximations of all of the values of the original type

Narrowing

Given the following grammar: <S> --> a<S>c<B> | <A> |b <A> --> c <A> | c <B> --> d | <A> <A> is :

Non-Terminal

Given the list mylist =( 0 2. 4 0. 6. 8. 0) what is the result of (fun2 mylist)? (define fun2 (lambda (lst) (cond ((null? lst) 0) ((= 0 (car lst)) (+ 1(fun2(cdr lst)))) (else(+0(fun2(cdrlst)) ) ))

Not given

___________ constructors enable objects of a class to be initialized in different ways.

Overloaded,

Part of the compiler that builds a syntax tree

Parser

Parameter passing method using copy-in, copy-out

Pass by value result

___ is the ability to define a method in a superclass and then define a method with the same name differently in a subclass.

Polymorphism

[ ] and. [ ] are interpreted languages. Select two different languages.

Python and Scheme

The ease with which programs can be read and understood.

Readability

Type checking affects this

Reliability

Arrays may be stored in Row major or Column major order. Describe this and give an example of the difference. Name a language that uses row major and one that uses column major order.

Row major and column-major order are methods used for storing multidimensional arrays in a linear storage such as random access to memory. The difference between row-major and column-major order is simply that the order of the dimensions is reversed. C and C++ both use row-major order. Fortran uses column-major order.

Name and give an example of 3 simple data types. Name two complex data types.

Simple data types are integers, floats, and strings. An integer is any number from -2147483648 to 2147483647. A float is any floating-point value number such as 3.15 A string is a textual data such as "Hello world". Complex data types are arrays and a list. An example of an array is the array fruit[4] has 5 slots or elements where we can store values. In a list, we can have multiple different data types it such as the list of integers, strings, and floats.

Type checking at compile time

Static

How would you output the value stored in a variable named studentAge and make the next output begin on a new line?

System.out.println(studentAge);

Using complete sentences, name and briefly describe the three characteristics of object oriented languages.

Three major features of object-oriented languages is encapsulation, inheritance, and polymorphism. Encapsulation refers to the creation of self-contained modules that binds processing functions of the data. Inheritance is when one class inherits attributes from another class. Polymorphism performs different things based on the object's class.

What is the output of the code below class car: def __init__(self, name): self.__name=name self.speed = 0 self.engineExploded = False def accelerate(self): if self.engineExploded == False: self.speed += 5 if self.speed > 50: self.engineExploded = True self.speed = 0 def brake(self): if self.speed > 0: self.speed -= 5 def __str__(self): outString = self.__name + ':' + str(self.speed) if self.engineExploded == True: outString += ' (Engine Exploded)' return outString class racecar(car): def __init__(self, name): super().__init__(name) def accelerate(self): if self.engineExploded == False: self.speed += 5 if self.speed > 200: self.engineExploded = True self.speed = 0 def main(): myCar = car('Toyota') myRaceCar = racecar('Chevy') print (myCar) print (myRaceCar) myCar.brake() myRaceCar.brake() for i in range(20): myCar.accelerate() myRaceCar.accelerate() print (myCar) print (myRaceCar) main()

Toyoto: 0 Chevy :0 Toyoto: 0 (Engine Exploded) Chevy: 100

One of the advantages of interpreted over compiled languages is that they tend to offer more run-time debugging support

True

True or False: All variables in Java must be declared before they can be used

True.

Hypertext publication that can be collaboratively edited is called a:

WIKI

Measure of how easily a language can be used to create programs for a chosen problem.

Writability

Some binding times after language implementation are load time, link time and

[compile time] and [run‑time]

Function automatically called in Python when an object is created

__init__

Function used in Python to print an object

__str__

Which of the strings are legal in the language defined? S --> <A> a <B> b <A> --> <A> b | b <B> --> a <B> | a a). baab b) bbbab c) bbaab

a and c

With Dynamic scoping; what variables are visible during the execution of the last function called and where are they defined? •void fun1(void); /* prototype */ void fun2(void); /* prototype */ void fun3(void); /* prototype */ void main() { int a, b, c; . . . } void fun1(void) { int b, c, d; } . . . void fun2(void) { int c, d, e; . . . } void fun3(void) { int d, e, f; . . . }

a) main calls fun1; fun1 calls fun3; fun3 calls fun2. b) main calls fun3; fun3 calls fun1.

Consider the following program: void fun1(void); / *prototype*/ void fun2(void); void fun3(void); void main() { int a, b, c, .....} void fun1(void) { int b, c, d; ....} void fun2(void) { int c, d, e; ...} void fun3 (void) { int d, e, f; ...} Given the following calling sequence and assuming dynamic scoping, what variables are visible during the last function called? Include with each visible variable the name of the function in which it was declared. main calls fun2; fun2 calls fun3; fun3 calls fun1.

a. main calls fun1; fun1 calls fun2; fun2 calls fun3. d, e, f fun3 c fun2 (d and e of fun2 are hidden) b fun1 ( c and d of fun1 are hidden) a main (b and c of main are hidden) b. main calls fun2; fun2 calls fun3; fun3 calls fun1. b, c, d fun1 e, f fun3 ( d of fun3 is hidden ) a main ( b and c of main are hidden ) (c, d and e of fun2 are hidden)

Which of the sentences are in the grammar? <S> ::= a <S> c <B> <S> ::= <A> | b <A> ::= c <A> | c <B> ::= d | <A>

acd → No abcd → Yes acccbd → No

Two names for the same location in memory; represented by & parameters in C++.

alias

If two different syntax trees may be built for a statement in a language, the language is said to be:

ambiguous

multi-member homogeneous data type

array

Which in-built function will add a value to the end of an array?

array_push()

Qualities or properties of a variable

attributes

association between an attribute and an entity

binding

If class B is subclassed from class A, what is the correct Java syntax?

class B extends A

You are creating a Python Motorcycle class which is supposed to inherit from the Vehicle class. Which of the following class declaration statements will accomplish this?

class Motorcycle(Vehicle):

Java Method with same name as the class and not return type a.

constructor

function in Java whose name is the same as the class

constructor

associative array in Python, accessed via keys

dictionary

Loop using a post-test; always executes at least once.

do while loop,

with ______ scoping, the runtime state of the program stack determines what variables you are referring to.

dynamic

Storage space for dynamic variables

heap

storage location for dynamic variables

heap

We can recognize an object-oriented language because it has objects, polymorphism, and

inheritance

What is the result? lst = (This (is. just). another test question) (car (car (cdr lst)))

is

Smallest unit of a language such as sum

lexeme

reads input and finds lexemes and token

lexer

time during which a variable is bound to a specific memory location

lifetime

operator has operands of different types

mixed-mode expression

multiple use of an operator

overloading

Number, order, and type of formal parameters

parameter profile

produces error messages and a syntax tree

parser

Parameter passing method using copy-in

pass by value

Object oriented languages can be recognized because they have objects, inheritance, and

polymorphism

A LL parser:

processes the input symbols from left to right, produces a left-most derivation

List of a function's parameters

profile

What will be the output of the following PHP code? <?php $color =

r

Complete the code to generate "Inside the child class" as the output. class ParentClass: def action(self): print('Method is not overridden') class ChildClass(ParentClass): def action(self): print('Inside the child class') if __name__ == "__main__": # Fill in the missing code

r = ChildClass() r.action()

Which of the functions is used to sort an array in descending order in PHP?

rsort()

part of program where a variable is visible

s

portion of an array

slice

selected portion of an array

slice

variable assigned value at compile time

static

variable bound to memory before execution begins

static

with ____ scoping, the structure of the program source code determines what variables you are referring to.

static

Happens at compile time

static binding

Function used in Java to print an object

toString()

Category of language units

token

Which of the following shows the correct syntax for a Java while loop? a. while(){ String userInput = input.next(); if(userInput equals("yes")){ isOnRepeat = false;} } b. while (isOnRepeat){ String userInput = input.next(); } c. while (isOnRepeat) { String userInput = input.next(); if (userInput.equals ("yes")) { isOnRepeat = false;} }

while (isOnRepeat) { String userInput = input.next(); if (userInput.equals ("yes")) { isOnRepeat = false;} }


संबंधित स्टडी सेट्स

3.8 Plagiarism Quiz: Writing Skills

View Set

Principles of Management: Chapter 12 (Wesson)

View Set

Agile questions and explanations

View Set

Survey of the Bible First Test: Introduction to the Bible

View Set

Microbiology ch 24 Digestive System Infections

View Set

Chapter 22: Biotechnology (Test 4)

View Set

Chapter 63: Management of Patients with Neurologic Trauma

View Set