Professional Documents
Culture Documents
Ira Pohl
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;
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
*/
3)
(6
2)
(2
1)
(9
5)
(3
1)
(5
4)
( 7
5)
(9 0)
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;
}