Created
May 11, 2012 16:05
-
-
Save ff6347/2660651 to your computer and use it in GitHub Desktop.
a simple cpp program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This Gist is part of MT4D coming soon on fabiantheblind.info