Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (0)

Powered by Vanilla. Made with Bootstrap.
Simple Structure/OOP Example
  • Sh3llc0d3
    Posts: 1,910
    Well I'm back toying with C++ and OOP at the moment so I thought I'd give a little example of some OOP and the use of structures. This program takes user input and attributes it to an object (you) :)

    Code:
    #include <iostream>

    // Definition of SELF using a struct
    struct SELF
    {
    std::string name; // name attribute of SELF
    char sex[10]; // sex/gender attribute of SELF
    double height; // height of SELF
    };

    int main(void)
    {
    using std::cin; // using std namespace for
    using std::cout; // cin, cout
    using std::endl; // and endline

    SELF you; // Define the new object 'you' based on the SELF structure

    //title
    cout << \"Sh3llc0d3's OOP/Structures Simple Example\"
    // Enter first name
    cout << \"Enter your name: \" << endl;
    // your name will now be defined as the 'name' of 'you'
    std::getline(cin,you.name);
    // Enter your gender
    cout << \"Enter your gender [male or female]: \" << endl;
    // your gender will now be defined as the 'sex' of 'you'
    cin >> you.sex;
    // Enter your height
    cout << \"Enter your height in metres: \" << endl;
    // your height will now be defined as the 'height' of 'you'
    cin >> you.height;

    // print the values
    cout << \"Your name is: \" << you.name << endl
    << \"Your gender is: \" << you.sex << endl
    << \"Your height is: \" << you.height << endl;

    return 0;
    }


    Output:

    Sh3llc0d3's OOP/Structures Simple Example

    Enter your name:
    Sh3llc0d3 - iExploit.org
    Enter your gender [male or female]:
    male
    Enter your height in metres:
    1.80


    Your name is: Sh3llc0d3 - iExploit.org
    Your gender is: male
    Your height is: 1.8

    Process returned 0 (0x0) execution time : 28.834 s
    Press any key to continue.

  • sangf
    Posts: 203
    nice~ i love the OO features of C++.
  • Sh3llc0d3
    Posts: 1,910
    Gotta admit I love programming in C++ (even tho I'm not amazing at it), there are much more flexible languages (and easier ones but hey it's awesome! :)