CSE 240 FINAL QUESTIONS & ANSWERS
What is printed by the following code?
int main () {
int array[5] = {10,30,50,70,90};
int *p = array;
cout << *(p+1) + *(&*p) + 1; return 0;
} - Answers :41
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 = new Exam;
cout << Exam::total;
} - Answers :4
a delete instruction is needed before the main() ends.
Which of the following options is correct?
#include<iostream>
using namespace std;
class MyClass {
public:
MyClass() {cout << "MyClass constructed\n";}
~MyClass() {cout << "MyClass destroyed\n";}
};
int main(){
MyClass * pt = new MyClass[3];
return 0;
} - Answers :delete [ ] pt;
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.
division by zero
statement should end with a ';'
unicity
a variable name should start with a letter, '$' or '_'
type matching - Answers :parameters type in a function declaration should match these
in the function call.
unicity
type matching
The syntactical structure of the imperative programming language reviewed in this
course include which of the following validations
unicity
statement should end with a ';'
type matching
a variable name should start with a letter, '$' or '_'
division by zero
parameters type in a function declaration should match these in the function call. -
Answers :statement should end with a ';'
Running the following program,
How many times the message "constructing" is printed on the screen?
#include<iostream>
using namespace std;
class Rectangle {
public:
Rectangle(){
cout <<"constructing"<<endl;
}
~Rectangle()
, {cout <<"destructing"<<endl;
}
};
class Box : public Rectangle {
public:
Box(){
cout <<"constructing"<<endl;
}
~Box()
{cout <<"destructing"<<endl;
}
};
int main(){
Box * a = new Box[5];
delete[] a;
return 0;
} - Answers :10
Features of the logic paradigm includes
expressing computation in terms of logic predicates
using lambda calculus
classes and objects
expressing computation in terms of boolean expressions - Answers :expressing
computation in terms of logic predicates
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
When the body of the method is not relevant to answer the question, it has been
replaced for a comment // code - Answers :class Person {
public:
Person() {
//code
}
Person(char* lName, int year) {
// code
}
private:
char* lastName;
int yearOfBirth;
};
What is printed by the following code?
int main () {
int array[5] = {10,30,50,70,90};
int *p = array;
cout << *(p+1) + *(&*p) + 1; return 0;
} - Answers :41
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 = new Exam;
cout << Exam::total;
} - Answers :4
a delete instruction is needed before the main() ends.
Which of the following options is correct?
#include<iostream>
using namespace std;
class MyClass {
public:
MyClass() {cout << "MyClass constructed\n";}
~MyClass() {cout << "MyClass destroyed\n";}
};
int main(){
MyClass * pt = new MyClass[3];
return 0;
} - Answers :delete [ ] pt;
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.
division by zero
statement should end with a ';'
unicity
a variable name should start with a letter, '$' or '_'
type matching - Answers :parameters type in a function declaration should match these
in the function call.
unicity
type matching
The syntactical structure of the imperative programming language reviewed in this
course include which of the following validations
unicity
statement should end with a ';'
type matching
a variable name should start with a letter, '$' or '_'
division by zero
parameters type in a function declaration should match these in the function call. -
Answers :statement should end with a ';'
Running the following program,
How many times the message "constructing" is printed on the screen?
#include<iostream>
using namespace std;
class Rectangle {
public:
Rectangle(){
cout <<"constructing"<<endl;
}
~Rectangle()
, {cout <<"destructing"<<endl;
}
};
class Box : public Rectangle {
public:
Box(){
cout <<"constructing"<<endl;
}
~Box()
{cout <<"destructing"<<endl;
}
};
int main(){
Box * a = new Box[5];
delete[] a;
return 0;
} - Answers :10
Features of the logic paradigm includes
expressing computation in terms of logic predicates
using lambda calculus
classes and objects
expressing computation in terms of boolean expressions - Answers :expressing
computation in terms of logic predicates
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
When the body of the method is not relevant to answer the question, it has been
replaced for a comment // code - Answers :class Person {
public:
Person() {
//code
}
Person(char* lName, int year) {
// code
}
private:
char* lastName;
int yearOfBirth;
};