You are on page 1of 3

Final Exam Sample Questions CMPS 109

Ira Pohl

March 11, 2014

Problem 1.Answer true or false.


a. The operators binary * and integer remainder % have the same
precedence.
b. Classes cannot be all public members.
c. In the C++ STL library, the map is a sequence container.
d. In the STL library <thread> there is a join method.
Problem 2. Multiple Choice
a. Which is NOT one of the
a) input
b) output

STL iterator types?


c) backward
d) bidirectional

b. For which STL container type is the random access iterator available?
a) map
b) set
c) vector
d) any associative container
c) When opening a file for reading make sure :
a) it has at least 5 characters b) an ascii table is in the file
c) it exists in the specified directory d) it has an EOF e) it is
encrypted
Problem 3. True or false :which initializations are legal?
a. long mmm = 013;
b. double f = -412;
c. int flag = reinterpret_cast<int>(true);
d. short d = 0x12345678;
e. boolean s = 10;

Problem 4. What gets printed?


#include <iostream>
using namespace std;
class language {
public:
virtual void say_hello(void) = 0;
};
class japanese : public language {
public:
void say_hello(void) {
cout << "Konichiwa!" << endl;
}
};
class english : public language {
public:
void say_hello(void) {
cout << "Hello!" << endl;
}
};
class british_english : public english {

public:
void say_hello(void) {
cout << "Hello chap!" << endl;
}
};
int main()
{
language *l;
l = new japanese();
l->say_hello();
free(l);
l = new british_english();
l->say_hello();
english eng_lan = *dynamic_cast<british_english*>(l);
eng_lan.say_hello();
return 0;
}
Problem 5. What gets printed? (Yan Li)
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int sum = 0, in_var;
fstream in;
in.open ("test_file", ios::in);
if (in.fail ())
{
cerr << "Couldn't open file" << endl;
return 1;
}
while (!in.eof ())
{
in >> in_var;
sum += in_var;
cout << "Output: " << in_var << endl;
}
cout << "Sum: " << sum << endl;
return 0;
}
/* Sample Input:for test_file
1
2
3
4
*/

Problem 6. For the following leaf nodes as shown.


tree. Assume it is a complete binary tree.
(4

3)

(6

2)

(2

1)

(9

5)

For this tree evaluated with


evaluated?

(3

1)

(5

4)

( 7

Draw the Min-Max

5)

(9 0)

alpha-beta; what nodes need not be

Can you reorder the leaf nodes to get more alpha-beta cut-offs?
Problem 7. What gets printed?
/Ira Pohl Test question
#include<exception>
#include<stdexcept>
#include<iostream>
using namespace std;
class myexception: public exception
{
virtual const char* what() const throw()
{
return "My exception happened";
}
} myex;
int main () {
try
{
char data[100] = "Dr. Who" ;
cout << "Print my Name" << endl;
cerr << "my name is " << data << endl;
throw myex;
throw 7;
throw "I want water?";
}
catch(bad_alloc e){ cout<< e.what() << " bad allocation " << endl;}
catch(exception& e){ cout << e.what() << endl;}
catch(int){ cout << "int exception" << endl;}
catch(...){ cout << "all else failed" << endl;}
return 0;
}

You might also like