fabianmoronzirfas
5/11/2012 - 4:05 PM

a simple cpp program

a simple cpp program


// the string and io classes
#include <iostream>
#include <string>

//using namespace std; // if you use this you can remove all "std::"
class Object{ /* our object*/
public:
	std::string name; // its name

	Object(){}// basis constructor
	Object(std::string in){name = in;}// another constructor
	int compare(int a, int b);//Prototype for comparsion
	void setName(std::string in){name = in;} // to set the name
};

int Object::compare(int a, int b){/* the compare function*/
	if(a>b){return a;}else{return b;}
}

int main(){ /* now the main program*/
	Object* myObject = new Object("Hello World CPP");// make a new object

	int a = 23,b = 5;// declare some values
	// now the output directly with comparsion
	std::cout << "The Object named: "<< 
	myObject->name << "\nCompared: "
	<< a << " with "
	<< b << "\n" 
	<< myObject->compare(a,b) <<" is bigger\n" 
	<< std::endl;
	/* code */
	delete myObject; // remove the object from memory
	return 0; // everything went fine return 0
}