#include "CosNaming_c.hh"
#include "Math_c.hh"
#include <fstream.h>

int main(int argc, char* const* argv) 
{
    try {

	//
	// The following is not application specific
	//

	// Initialize the ORB.
	CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

	// Get a reference to the Naming Service root_context
	CosNaming::NamingContext_var rootContext = 
	    CosNaming::NamingContext::_narrow(
                orb->resolve_initial_references("NameService"));

	//
	// Get access to object
	//


	// Locate an account manager through the Naming Service
	CosNaming::Name name;
	name.length(1);
	name[0].id = (const char *) "Math";
	name[0].kind = (const char *) "";
	Math::Std_var std = Math::Std::_narrow(rootContext->resolve(name));

	//
	// Use the object
	//

	// Add
	CORBA::Double x = std->add(2.4, 8.4);

	// sub
	CORBA::Double y = std->sub(2.4, 8.4);

	// Print out the result
	cout << "2.4 + 8.4 = " << x << ", 2.4 - 8.4 = " << y << endl;

    } catch(const CORBA::Exception& e) {
	cerr << e << endl;
	return 1;
    }

    return 0;
}
