Listing 4

(a)
std::ios_base *p;

p = ast.wait(12000);  // Wait at most 12000 milliseconds
if (p == &std::cin) 
   std::cout << "From console: " << a << " " << b << std::endl;
else if (p == &fio)
   std::cout << "From file: " << c << " " << d << std::endl;
else
   std::cout << "Timeout" << std::endl;