Skip to content

Instantly share code, notes, and snippets.

@ff6347
Created May 11, 2012 16:05
Show Gist options
  • Save ff6347/2660651 to your computer and use it in GitHub Desktop.
Save ff6347/2660651 to your computer and use it in GitHub Desktop.
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
}
@ff6347
Copy link
Author

ff6347 commented May 11, 2012

This Gist is part of MT4D coming soon on fabiantheblind.info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment