Thread: intro to c++

Results 1 to 3 of 3
  1. #1
    llvengancell's Avatar
    Join Date
    May 2007
    Posts
    390
    Reputation
    12
    Thanks
    5

    Lightbulb intro to c++

    utorial: A small introduction to C++
    Tutorial: A small introduction to C++

    This tutorial will only cover some main knowledge. After you have fully read it
    you should be able to create your own small programs, know the basics of C++ coding,
    and be able to use that base to continue and experimenting further into the language.
    So i will definitely not go into detail, like about how many bytes a certain
    data type uses.

    To compile C++ code you will need a debugger, the 2 most well known ones are
    Borland and Visual Studio C++.

    You can get Borland here:
    https://www.borland.com/downloads/download_cbuilder.html

    A trial version of Visual Studio C++ is available here:
    https://msdn.microsof*****m/vstudio/ex...ualc/download/

    Code:

    Content table:
    1. Data types
    2. Statements
    2.1. If, else
    2.2. For-loop
    3. Functions
    4. Code example

    1. Data types

    Like any other programming language, C++ uses data types to store values and information in.
    Here you can find a small list of the most used data types.

    Code:

    Int (integer value)
    Float (decimal value)
    Char (a character, contains text)
    Bool (boolean, true or false)

    I won't discuss Vector and String here since there are endless possibilities with them and
    it would take quite some time to write all that down .

    When you are coding and you want to store a value, you will have to know two things.
    First, what kind of data should the variable be able to handle? Second,
    what will the variable be called?

    This is how you declare those four data types.
    Code:

    int ThisIsAIntegerValue;
    float ThisIsADecimalValue;
    char ThisIsACharacterVariable;
    bool ThisIsABoolean;

    As you can see you first write the data type, after that, it's name, and then you
    have to finish the declaring with a ";".

    Now we have created a place we can put data in, but untill now we still haven't put any in.
    Code:

    int ThisIsAIntegerValue = 0;
    float ThisIsADecimalValue = 0.0;
    char ThisIsACharacterVariable = "test";
    bool ThisIsABoolean = false;

    2. Statements

    2.1 If, else

    In the next topic i will show you how to write your first program based on these two statements.

    Other then the else-statement, the if-statement can stand-alone and can only be used in one way.
    The else-statement can also be used in a combination of both statements. These are the two possibilities:

    Code:

    if ( ... )
    {
    }
    else
    {
    }

    Code:

    if ( ... )
    {
    }
    else if ( ... )
    {
    }
    else
    {
    }

    When you use the else-statement the two actions will never be executed at the same time.
    As you may have guessed, the code which should get executed when a certain action
    returns true has to be placed between the two brackets.

    So now we know where to put the action but not yet what we can do where the points are situated. This is an
    example of how you would use it with a boolean.

    Code:

    bool test=false;
    if ( test )
    {
    // test is true
    /* test is true */
    }
    else
    {
    // test is false
    /* test is false */
    }

    The "//" sign is used to place comments in your code, as you can see you can also use the "/ *" and "* /" sign.
    (Without the spaces) The above code is one way to check if a boolean is true or false. But to
    compare all data types there are built in signs you can use, here i give you a very smal list:

    Code:

    == equal to
    != not equal to
    > bigger
    < smaller
    >= bigger or equal
    <= smaller or equal

    2.2. For-loop

    You can use this loop when you want a certain action to get executed several times, or use it to loop
    trough several variables. This is an example of how you use it.

    Code:

    for (int i=0; i<=10; i++)
    {
    }

    As you can see, there are three main parts in the loop. The first one "int i=0" defines the variable
    that will change it's value. The second part "i<=10" is where you define how far it should loop, here it
    goes from 0 to 10 since we defined the variable as 0. The last one "i++" is the actual counting up, you
    can also use "i--" or any other action you would like.

    3. Functions

    Functions are very important for writing programs. My examplefunction will be called "main". I'm choosing
    this name because every program, whatever you write, needs a main function. Without it, you can not
    execute your program code. This is the example:

    Code:

    void main( )
    {
    }

    The first word written down is "void" it states that the function does not return any value.
    And as you may allready know, "main" is the name of the function. Now i'm going to show you an example
    which contains several new aspects.

    Code:

    int testFunction( int temp )
    {
    return temp;
    }

    Now the first word written down is "int", which refers to the integer value. It means that the function
    will retain an integer value. We do this by using the "return", and in this example we return "temp".
    "temp" is our input, which we get when the function is called. This is an example of a normal function
    call without a return value:

    Code:

    int test = 0;
    testXFunction( test );

    As you can see our input is now "test" which contains the value 0. Now when we would use a function
    with an integer return value and want to store the output of that function. Then our calling
    might look like this:

    Code:

    int test = 1;
    int output = testFunction( test );

    If testFunction is the function i posted above, then output will be set equal to test, which is 1.

    4. Code example

    Code:

    float sum( float input1, float input2 )
    {
    float temp = input1 + input2;
    return temp;
    }

    void main ( )
    {
    float var1, var2;
    float outputValue;

    cout << "Input float value 1:" << endl;
    cin >> var1;

    cout << "Input float value 2:" << endl;
    cin >> var2;

    outputValue = sum( var1, var2 );

    cout << "Sum: " << outputValue << endl;
    }

    You should be able to read and understand both functions. The only new things i haven't explained yet
    basically are "cout", "cin" and "endl". The cout stands for output, you can display text, variables
    and every other kind of data types with it. The second one (cin) is used to write input to variables.
    And the endl cmd just takes a new line after your text/variables have been displayed. You should
    mess around with some of those small codes to try understand the code better and learn from your
    own mistakes.

    I hope you have learned from this tutorial, if you did please +rep or let me know.
    If you are having any problems or questions on anything please don't pm me but ask them
    in this thread.

  2. #2
    dezer's Avatar
    Join Date
    Nov 2006
    Gender
    male
    Posts
    285
    Reputation
    12
    Thanks
    4
    My Mood
    Aggressive
    if you didnt notice, its warrock section
    Quote Originally Posted by killerofsake987 View Post
    wuts search button
    owned

  3. #3
    soad56's Avatar
    Join Date
    Jun 2007
    Gender
    male
    Posts
    416
    Reputation
    10
    Thanks
    10
    Post it to Tutorials or so!
    Excuse my english please, I'm from Germany





    blackdrag0n = hackingteam = spammer

Similar Threads

  1. N00B intro to overclocking...
    By ~Viper~ in forum Overclocking
    Replies: 16
    Last Post: 04-01-2009, 05:11 PM
  2. Rate my second JetaEngine intro
    By radnomguywfq3 in forum Art & Graphic Design
    Replies: 3
    Last Post: 12-03-2008, 03:48 PM
  3. Rate JetaEngine Intro
    By radnomguywfq3 in forum Art & Graphic Design
    Replies: 22
    Last Post: 12-01-2008, 10:36 PM
  4. My intro ^_^
    By -Mintek- in forum General
    Replies: 10
    Last Post: 08-12-2007, 07:06 PM
  5. After sometime of inactivity(my intro)
    By vega in forum General
    Replies: 13
    Last Post: 10-21-2006, 10:32 AM