CSE240 final summer

¡Supera tus tareas y exámenes ahora con Quizwiz!

Write in LISP the operation of 3 multiplied by 4?

(* 3 4)

"What is printed on screen when you run the following program? #include <iostream> using namespace std; void recursive(int x){ if(x<10){ cout <<x<<"",""; recursive(x+1); cout<<x<<"",""; }else{ cout<<""A,"";}} int main(){ recursive(1);}"

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

What is the output of this code? (setf a 0) (defun fun(n) (if (= n 0) (setf a (+ a n)) (progn (setf a (+ a n)) (fun (- n 1))) ) ) (fun 4) (print a)

10

What is printed on the screen after executing the lines below? int x[3] = {1,2,3}; printf("%d",sizeof x) ;

12

In the following code, how many times the destructor of the class "Derived" is executed? #include<iostream> using namespace std; class Base{ public: Base(int n){ cout<< "Base Constructor"<< end1; } void function(){ cout<< "function"<< end1; } ~Base(){ cout<<"Base destructor"<<end1; } }; class Derived : public base{ public: Derived(int n) : Base(n){ cout<< "Derived constructor"<<end1; } ~Derived() { cout<< "Derived constructor"<<end1; } }; int main(){ Derived myPQ1(50); myPQ1.function(); myPQ1.function(); Derived *(ask)myPQ2; myPQ2 = new Derived(50); myPQ2->function(); myPQ2->function(); delete myPQ2; }

2

What is printed by the following program? #include <iostream> using namespace std; int i = 5; class A { public: A() {i=10;} ~A() {i=20;} }; int foo() { i=30; A a; return 0; } int main() { foo(); cout<<i; return 0; }

20

What is printed by the print instruction in the second line? (setf theList '(2 3 7 9 10) ) (print (first ( rest theList ) ) )

3

What is the value in the variable Exam::total that is printed when this program is executed? #include <iostream> using namespace std; class Exam{ public: static int total; Exam() { total++; } }; int Exam::total=0; int main(){ Exam a, b, c; Exam *d, *e, *f; cout<<Exam::total;}

3

"What is printed on screen after running this program? #include <iostream> using namespace std; int main(){ int array[5] = {10, 20, 30, 40, 50}; int *(ask)p = array; cout << *(ask)(p+1) + *(ask)(&*(ask)p) +1;}"

31

"What is printed on screen after running this program? #include <iostream> using namespace std; int main(){ int Employees[3][3] = {{10,20,30},{15,25,35},(1,2,3}}; cout << Employees[1][2] - Employee[2][1]<<endl;}"

33

What is the output of the following code #include <stdio.h> void main() { char a[10][5] = {"hi", "hello", "fellows"}; printf("%d", sizeof(a[2])); }

5

what is printed by the following code? (defun fun(n) (if (= n 0) () (fun (- n 1)) ) n ) (print (fun 5))

5

What is printed by the following program? #include <stdio.h> void fun(int x) { if (x>0) { printf("%d", x); fun(x-1); printf("%d", x); } else { printf("@"); } } int main() { fun(5); }

54321@12345

Assume that a string is declared as char str[ ] = "heLLo"; What is the return value of sizeof(str) ?

6

How many times the message "constructing" is printed on the screen? #include <iostream> using namespace std; class Rectangle { public: Rectangle(){ cout<<"contructing"<<end1; } ~Retangle(){ cout<<"decontructing"<<end1; } }; class Box: public Retangle { public: Box(){ cout<<"constructing"<<end1; } ~Box(){ cout<<"destructing"<<end1; } }; int main(){ Box *(ask)a= new Box[3]; delete[]a; return 0; }

6

What is the value returned for the following LISP expression (+ 1 (if (< 2 1) (* 3 3) 6 ) )

7

What is the last value printed on the screen after running the following LISP code? (setf num 1) (dotimes (x 3) (setf num (+ num num) ) ) (print num)

8

What is the last value printed on the screen after running the following LISP code? (setf num 1) (dotimes (x 3) (setf num (+ num num))) (print num)

8

What is the value of the variable total printed by the following program? #include <iostream> using namespace std; int total = 0; class A { public: A() {total++;} ~A() {total++;} }; class B: public A { public: B() {total++;} ~B() {total++;} }; class C: public B { public: C() {total++;} ~C() {total++;} }; int main() { A a; B b; C *c(pointer) = new C; delete c; cout << total; return 0; }

9

Which of the following options is the code in C++ for >A class Student that inherits from a class Person. >A constructor in Student that calls (is able to call) a constructor in Person A) class Person { public: Person() { //code } Person(char*(ask) lName, int year) { // code } private: char*(ask) lastName; int yearOfBirth; }; class Student : public Person { public: Student() { //code } Student(char*(ask) lName, int year, char*(ask) univer) :Person(lName, year) { //code } private: char *(ask)university; }; ------------------------------------ B)class Person { public: Person() { //code } Person(char*(ask) lName, int year) { // code } private: char*(ask) lastName; int yearOfBirth; }; class Student extends Person { public: Student() { //code } Student(char*(ask) lName, int year, char*(ask) univer) { Person(lName, year); //code } private: char *(ask)university

A

Which rules in Prolog match the following definition of a bad dog: A dog is bad if it bites the postman, chews the newspaper, or chases the cat. A)bad_dog(Dog) :- is_dog(Dog), bites(Dog, Postman), is_postman(Postman). bad_dog(Dog) :- is_dog(Dog), chews(Dog, Newspaper), is_newspaper(Newspaper). bad_dog(Dog) :- is_dog(Dog), chases(Dog, Cat), is_cat(Cat). B) bad_dog(Dog) :- is_dog(Dog); bites(Postman). bad_dog(Dog) :- is_dog(Dog); chews(Newspaper). bad_dog(Dog) :- is_dog(Dog); chases(Cat). C)is_dog(Dog), bites(Dog, Postman), is_postman(Postman):-bad_dog(Dog). is_dog(Dog), chews(Dog, Newspaper), is_newspaper(Newspaper):-bad_dog(Dog). is_dog(Dog), chases(Dog, Cat), is_cat(Cat):-bad_dog(Dog). D)bad_dog(Dog) :- is_dog(Dog); bites(Postman); is_postman(Postman). bad_dog(Dog) :- is_dog(Dog); chews(Newspaper); is_newspaper(Newspaper). bad_dog(Dog) :- is_dog(Dog); chases(Cat); is_cat(Cat).

A

Given the following struct: struct contact { char name[32]; int phone; char email[32]; }; Which code can be used to create a contact and store data ? A. struct contact x; scanf("%s", x.name); scanf("%d", &x.phone); scanf("%s", x.email); B. struct contact x; scanf("%s", &x.name); scanf("%d", &x.phone); scanf("%s", &x.email); C. struct contact x; scanf("%s", x.name); scanf("%d", x.phone); scanf("%s", x.email); D. struct contact x; scanf("%s", &x.name); scanf("%d", x.phone); scanf("%s", &x.email)

A.

Given the following facts. instructor(john,cse300). instructor(mary,cse400). instructor(paul,cse500). enrolled(joseph,cse300). enrolled(joseph,cse400). enrolled(joseph,cse500). enrolled(james,cse300). enrolled(james,cse500). Which query provides a list of all the students enrolled in cse300? A)enrolled(cse300). B) enrolled(Who, cse300). C) enrolled(cse300, Who). D) X is enrolled cse300.

B

In the code below: #include <iostream> using namespace std; class MyClass{ public: MyClass(){cout<<"MyClass constructed\n"; ~MyClass(){cout<<"MyClass destroyed\n"; }; int main(){ MyClass *(ask) pt; pt = new MyClass[3]; //add code here return 0;} a delete instruction is needed before the main() ends. Which of the following options is correct? A.delete * pt; B.delete [ ] pt; C.for (int i =0; i<3; i++) { delete pt[i]; } D.delete pt;"

B

What is printed after running this program? #include <iostream> using namespace std; class Grandpa{ public: virtual void foo(){ cout<<"HI, I am a grandpa"<<endl;} }; class Dad: public Grandpa{ public: void foo(){ cout<<"Hi, I am a Dad"<<endl;} }; class Kid: public Dad{ public: void foo(){ cout<<"Hi, I am a Kid"<<endl;} }; int main(){ Grandpa *(ask)johnDoe = new Kid; johnDoe->foo(); delete johnDoe; return 0; } A)Hi, I am a GrandPa B)Hi, I am a Kid C)Hi, I am a Dad D)Nothing

B

Given the class definition: #include <iostream> using namespace std; class Rectangle { private: int width, height; public: void setValues(int a, int b); int area(); }; void Rectangle::setValues (int a, int b){ width = a; height = b; } int Rectangle::area(){ return width*height; } Which of the following instruction(s) create an array of 3 Rectangles and initialize all the 3 of them with values. A) Rectangle a = new Rectangle[3]; a[0].setValues(1,1); a[1].setValues(2,2); a[2].setValues(3,3); B)Rectangle *a[3]; a[0] = new Rectangle; a[0]->setValues(1,1); a[1] = new Rectangle; a[1]->setValues(2,2); a[2] = new Rectangle; a[2]->setValues(3,3); C)Rectangle a[3]; a[0].setValues(1,1); a[1].setValues(2,2); a[2].setValues(3,3); D)Rectangle *a = new Rectangle[3]; a[0]->setValues(1,1); a[1]->setValues(2,2); a[2]->setValues(3,3); E)Rectangle *a = new Rectangle[3]; a[0].setValues(1,1); a[1].setValues(2,2); a[2].s

B, C & E

"Which of the following methods receive as a parameters an array of integers and the size of the array, and return the sum of all elements in the array? For instance, the following lines will print 15 int balance[5] = {1, 2, 3, 4, 5}; printf(""%d"", getAverage( balance, 5 ) ); A. int getAverage(int arr[], int size) { int sum = 0; for (int i = 0; i < size; ++i) { sum = sum + *(arr+i); } return sum; } B. int getAverage(int *arr, int size) { int sum = 0; for (int i = 0; i < size; ++i) { sum = sum + arr[i]; } return sum; } C. int getAverage(int arr[], int size) { int sum = 0; for (int i = 0; i < size; ++i) { sum = sum + arr[i]; } return sum; } D. int getAverage(int *arr, int size) { int sum = 0; for (int i = 0; i < size; ++i) { sum = sum + *(arr+i); } return sum; }"

B, C, D

What is equivalent code in C++ for the following LISP statement (if (< 1 2) (* 3 4) (/ 5 6) ) A)if (1 < 2) { cout<< 3 * 4; return 5 / 6; } B)if (1 < 2) { cout<< 3 * 4; cout << 5 / 6; } C) if (1 < 2) return 3 * 4; else return 5 / 6; D) if (1 < 2) cout<< 3 * 4; else cout << 5 / 6;

C

What is printed by this program? #include <iostream> using namespace std; class A { public: void m() {cout << "AAA";} }; class B: public A { public: virtual void m() {cout << "BBB";} }; class C: public B { public: void m() {cout << "CCC";} }; int main() { B *b <ask b> = new C; b->m(); return 0; }

CCC

What is the error type (lexical, syntactic, or semantic) or with "correct" when there are no errors (lexical, syntactic, or semantic) in the line int $ = 1; // in C/C++

Correct

What is the error type (lexical, syntactic, or semantic) or with "correct" when there are no errors (lexical, syntactic, or semantic) in the line int x = 0/1; // Java

Correct

Which of the following lines (in Java, C, or C++) is equivalent to this expression in LISP (- (* 1 2) (+ 3 4) (/ 5 6) 7 ) A) (1 - 2) * (3 - 4) * (5 - 6) / 7 B)1 - 2 * 3 - 4 / 5 - 6 - 7 C) ( 1- 2) + (3 * 4) / ( 5* 6) - 7 D) (1 * 2) - (3 + 4) - (5 / 6) - 7

D

?- 10 + 5 is 15. How will prolog respond to this query?

False

Given the following fact and rule: fun(1, 2). fun(N, F) :- N>0, N1 is N - 1, fun(N1, F1), F is N * F1. What is the result of the query ?- fun (2,2).

False

Is the following true or false with respect to inheritance? When a base class is privately inherited, a private member of base class becomes private member of derived class

False

The Java programming language is weakly typed

False

#include <stdio.h> int main(){ int i= 0; char a[] = "H202"; while (a[i]!= '\0') { *(ask)(a+1) =*(ask)(a+i) +1; i++; } char *q; q = a; q[2] = '#'; printf("%s", a); return 0; }

H3#2

What is the error type (lexical, syntactic, or semantic) or with "correct" when there are no errors (lexical, syntactic, or semantic) in the line char @ = 'A'; // in C/C++

Lexical

Prolog is based on

Predicate logic

Select all the options that apply to complete the following sentence. A Prolog program consist of

Rules, Goals / Questions & Facts

What is the error type (lexical, syntactic, or semantic) or with "correct" when there are no errors (lexical, syntactic, or semantic) in the line int If = (1<2 <3); // in C/C++

Semantic

What is the error type (lexical, syntactic, or semantic) or with "correct" when there are no errors (lexical, syntactic, or semantic) in the line int If = (1<2 <3); // in Java

Semantic

What is the error type (lexical, syntactic, or semantic) or with "correct" when there are no errors (lexical, syntactic, or semantic) in the line if = 5; // in C/C++

Syntactical

What is a similarity between a struct and enum?

They let you define new data structures

A programming language can belong to multiple paradigms

True

Compilation of a program is the translation of all statements of a program into assembly language before any statement is executed.

True

Given the following fact and rule. (some extra white-spaces has been added to facilitate reading) fun(1, 2). fun(N, F) :- N>0, N1 is N - 1, fun(N1, F1), F is N * F1. What is the result of the query? ?- fun (1,2).

True

Given the following fact and rule. fun(1, 2). fun(N, F) :- N>0, N1 is N - 1, fun(N1, F1), F is N * F1. What is the result of the query ?- fun (2,4).

True

Is the following line correct in LISP ( + 1 2 3 4 5 6 7 8 9 0)

True

Is the following true or false with respect to inheritance? When a base class is privately inherited, public members of the base class become private members of the derived class

True

Is the following true or false with respect to inheritance? When a base class is publicly inherited, protected members of base class becomes protected members of derived class

True

Is the following true or false with respect to inheritance? When a base class is publicly inherited, public members of the base class becomes public members of derived class

True

Logic programming describes what the problem is by a set of conditions and constraints, and leaves the computer to match the problem to the existing knowledge of facts and rules and to find solutions to the problem

True

One feature of the functional paradigm is a higher level of abstraction compared with Imperative and Object-Oriented paradigms

True

What is printed on the screen by the print instruction in the code below? (print ( and (< (* 3 5 ) ) ( not (>= 4 6 ) ) ) )

True

Features of the imperative or procedural paradigm includes

conditional statements & manipulation of named data (variables)

functions are created by calling a function-making macro. This macro is called

defun

Features of the functional paradigm includes

expresses computations in terms of mathematical functions & simpler semantics

Features of the logic paradigm includes

expressing computation in terms of logic predicates

Write in Prolog the statement "pizza is a food"

food(pizza).

What is printed : #include <stdio.h> int i = 1; void foo(int m, int *(ask)n){ printf("i = %d m = %d n = %d\n", i,m,*(ask)n); i = 5; m = 3, *(ask)n=4; printf("i = %d m = %d n = %d\n", i,m,*(ask)n); } void main(){ int j = 2; foo(j, &i); printf("i = %d j = %d\n", i, j);

i = 1 m = 2 n = 1 i = 4 m = 3 n = 4 i = 4 j = 2

What is equivalent code in C++ for the following LISP statement (if (< 1 2) (+ 3 4) (- 5 6) )

if (1 < 2) return 3 + 4; else return 5 - 6;

What would be the English meaning for this Prolog statement ?- owner(jane, dog(X)) :- big(X),spots(X). A)a big dog with spots is the owner of jane B) jane is a owner of a dog and the owner of something big and the owner of something with spots. C) if jane is the owner of X then X is big and has spots . D ) jane is the owner of some dog if that dog is big and has spots.

jane is the owner of some dog if that dog is big and has spots.

The semantic structure of imperative programming languages normally include which of the following validations

parameters type in a function declaration should match these in the function call., unicity and type matching


Conjuntos de estudio relacionados

common ambient air pollutants (apes)

View Set

Chapter 3 - Cost-Volume-Profit Analysis

View Set

Biology 101 With A Lab CH. 2 Basic Terms and Skills in Biological Science

View Set