1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. We have recently started the 16th edition of the Mini Mapping Contest. The theme is mini RPG. Do check it out and have fun.
    Dismiss Notice
  4. Choose your ride to damnation in the 5th Special Effect Contest Poll.
    Dismiss Notice
  5. The winners of the 13th Techtree Contest have been announced!
    Dismiss Notice
  6. The 13th Music Contest Poll is up! Vote for the best tracks in this symphony of frost and flame.
    Dismiss Notice
  7. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  8. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Tutorial: C++ for beginners

Discussion in 'Off-Topic' started by orcfan32, Oct 26, 2004.

Thread Status:
Not open for further replies.
  1. orcfan32

    orcfan32

    Joined:
    Jul 3, 2004
    Messages:
    337
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    First, you will need a good compiler to start programming.

    Get this, DEV-CPP.
    http://ftp1.sourceforge.net/dev-cpp/devcpp4.zip



    Sections:
    Tutorials (Lessons)
    FAQ (NEW!)
    Other, Untested Compilers (NEW!)
    Extra (NEW!)



    ---LESSON 1---
    This is the best compiler that I have found. Install it and exit the program. Start up notepad.exe in the accessories, or create a new one on your hard drive. Open it up now. Copy and paste the following text to your notepad file.

    Code (Text):
    #include <iostream>

    using namespace std;

    int main()
    {
        cout<<"Hello World!\n";
        cin.get();

    }
    Rename the text file as "hello.cpp". Double click on your new file. You should now be in "DEV-CPP". Hit "F9" on your keyboard. This will compile and run it. You should have a window that will pop up and say "Hello World!". Let's disassemble the coding now. The { and } mean beginning and end. You will use this for ALL separate functions. #include <iostream> is the function that it uses to call strings and stuff like that. The using namespace std; means..well..I don't know YET. The int main means that this is the "main function". Int declares the variable "main". cout<<"Hello World!\n"; makes the string appear. \n means to start a new line in the program. cin.get(); is a VERY important function. This keeps the window open. Try running it without this command. I haven't explained the ; yet. This is required for many lines in the C++ language. I don't know why, but it seems a little stupid to me. That is it about this program.
    ---END LESSON 1---



    ---LESSON 2---
    Declaring variables is easy. Go into your compiler\text editor and write:
    Code (Text):
    #include <iostream>

    using namespace std;

    int main()
     
    Now, get ready for your next program: returning an integer variable that has been entered in line 1. (An integer is a number) Copy and paste this code over your existing code, or type it all out on your own:
    Code (Text):
    #include <iostream>

    using namespace std;

    int main()
    {
        int Number;
        cout<<"Enter a number: ";
        cin>> Number;
        cin.ignore();
        cout<<"You entered: "<< Number <<"\n";
        cin.get();
    }
    Compile and run the program. After that, let me explain the new lines of the program. Go back to lesson one if you don't know about "#include <iostream>", "using namespace std;", "int main()", and ";". "Int Number" declares your new integer integer "int". Remember the { and } means beginning and end. " Cout<<"Enter a number: "; " makes the text.
    "Cin>> Number;" is puting your entered number after the prompt.(Enter a number: ) "Cin.ignore();" makes the program so that it doesn't exit after you hit enter like the "Hello World" program did.
    " Cout<<"You entered: "<< Number <<"\n"; " makes your program so that it displays the text and your integer variable. "Cin.get()" makes the window stay until you hit enter. That's it to this lesson. Keep up to date on these tutorials!
    ---END LESSON 2---



    ---LESSON 3---
    This is a very short lesson, so please bear with me.
    You will need the code from last lesson, because this code comes from that lesson. Actually, I will just provide the code:
    Code (Text):
    #include <iostream>

    using namespace std;

    int main()
    {
        int Number;
        int Number2;
        cout<<"Enter a number: ";
        cin>> Number;
        cin.ignore();
        cout<<"Enter another number: ";
        cin>> Number2;
        cin.ignore();
        cout<<"You entered: "<< Number <<" "<< "and "<< Number2 <<"\n";
        cin.get();
    }
     
    F9 to compile and run. Do it. This is derived from the first integer returner. I want you to study this code. I did this extra part from scratch, and I'm sure that by using code already used, you can decode the function of this.
    Like I said, short.
    ---END LESSON 3---



    ---LESSON 4---
    This lesson is pretty short to. This is a very important thing to know as we progress to further lessons: comments. you can outline comments by using:
    Code (Text):
    //Your comment text here
    or
    /*Your comment text here
     
    if you are using DEV-CPP, these comments will be in a light gray and italicized
    Comments are important for making definitions of functions.
    ---END LESSON 4---



    ---LESSON 5---
    Now that we have covered a few more areas, let's move on: next, we are going to create a calculator that can do all four functions: addition, subtraction, division, and multiplication. Use this code:
    Code (Text):
    #include <iostream>

    using namespace std;

    int main()
    {
        float num1;
        float num2;
        float add;
        float sub;
        float div;
        float mul;
    /* --- Actions --- */  
        cout<<"Enter Number 1: ";
        cin>> num1;
            cout<<"Enter Number 2: ";
            cin>> num2;
            cin.ignore();
            add = num1 + num2;
            sub = num1 - num2;
            div = num1 / num2;
            mul = num1 * num2;
            cout<<"Your sum is: "<< add<< "\n";
            cout<<"Your difference is: "<< sub<< "\n";
            cout<<"Your quotient is: "<< div<< "\n";
            cout<<"Your product is: "<< mul<< "\n";
            cin.get();
    }
    Run this in whatever your compiler is. After that, lets disect the coding.
    1. A float is an integer that has the ability to contain decimal points(.). This is useful, and should always be used in calculator programs for the integers.
    2.Next is the comment to separate the variable declarations from the actions.
    3.The string for prompting to enter the number.
    4.The action for making the last entered text to be the value of the float variable.
    5.The next two lines are repeats of the last two numbers. (3., 4.)
    6.These four lines tell what the variables should contain next
    7.The next four lines tell you the answers to the problem, it says the text then tells you the value of the variables.

    That was a longer lesson, but it wasn't so bad, now was it?
    ---END LESSON 5---



    ---FAQ---

    Q:Why do we need #include <whatever it is> ?
    A:This is including the directive used for functions to work, for example:
    #include <windows.h> is needed for the function "Sleep", which can be a VERY important function in some cases.

    Q:Why bother with C++ now..?
    A:If your going to school, you will probably eventually go to college. There, C++ is required to learn, unless you are too deeply interested in something else.

    Q:I can't understand C++, help!
    A:C++ is not in plain English, if you are having trouble understanding it, go get Visual Basic, and start from there.

    Q:C++ is too boring, why does it have to be in a DOS type window?
    A:If you go through all the necessary coding, you can change that.

    ---END FAQ---



    ---OTHER, UNTESTED COMPILERS---

    Digital Mars C++ Compiler
    ftp://ftp.digitalmars.com/Digital_Mars_C++/Patch/dm841c.zip
    Also Requires: STL Port
    ftp://ftp.digitalmars.com/Digital_Mars_C++/STL/stlport.zip


    Intel C++ for Linux
    http://www.intel.com/software/products/compilers/clin/noncom.htm

    ---END OTHER, UNTESTED COMPILERS---



    ---EXTRA---

    I have things here that don't exactly fit in any other section.

    DEV-CPP is now in Beta.Version 5!

    ---END EXTRA---


    ---TO BE CONTINUED---
     
  2. Lord Finarfin

    Lord Finarfin

    Joined:
    Aug 4, 2004
    Messages:
    982
    Resources:
    0
    Resources:
    0
    And this is for...?
     
  3. orcfan32

    orcfan32

    Joined:
    Jul 3, 2004
    Messages:
    337
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
  4. Eusira

    Eusira

    Joined:
    Sep 3, 2004
    Messages:
    2,101
    Resources:
    4
    Models:
    3
    Skins:
    1
    Resources:
    4
    C++ is the text scripting for programmers. Simple C++ is also used to make certain JASS scripts as well. There are 2 things you can do:
    1: go take computer lessons or go to computer camp
    2: learn by making GUI triggers and converting them
    3: Print it out and ask some "nerd" at your school to teach you how to do this, and apologize for laughing and mocking him
     
  5. Lord Finarfin

    Lord Finarfin

    Joined:
    Aug 4, 2004
    Messages:
    982
    Resources:
    0
    Resources:
    0
    Gotcha....but I'm afraid I'm not interested.

    *walks off*
     
  6. GreyArchon

    GreyArchon

    Joined:
    Jul 18, 2004
    Messages:
    1,868
    Resources:
    44
    Models:
    25
    Icons:
    14
    Skins:
    3
    Maps:
    2
    Resources:
    44
    Aisde from the explanation what it -IS-, there's still a question remaining as to why this tutorial would be posted here? :roll: Did someone request a C++ tutorial? Because in the end, most people here would prefer a JASS tutorial instead. You know, being a Warcraft community after all.
     
  7. Saikann

    Saikann

    Joined:
    May 10, 2004
    Messages:
    670
    Resources:
    3
    Skins:
    3
    Resources:
    3
    would be nice if you explained the meaning of every line as well :)
     
  8. orcfan32

    orcfan32

    Joined:
    Jul 3, 2004
    Messages:
    337
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    This is in the "Off Topic" section if you would have noticed. Any JASS tutorial would be in the JASS section or the tutorial section. No one requested this tutorial, it is here for the purpose of learning C++. If someone would learn this, then they could become a good tool writer for Warcraft 3. :wink:
     
  9. Eusira

    Eusira

    Joined:
    Sep 3, 2004
    Messages:
    2,101
    Resources:
    4
    Models:
    3
    Skins:
    1
    Resources:
    4
    This is a two-pronged idea. People learn how to program, while the EXACT same concept is used for JASS. So learning a little more is going to kill you?
     
  10. oz02

    oz02

    Joined:
    Jan 9, 2004
    Messages:
    1,205
    Resources:
    2
    Tutorials:
    2
    Resources:
    2
    Err... this tutorial isn't very detailed. It seems you don't have too much experience yourself in c++ to be writing tutorials. If someone wanted to learn the language they would probably get a book or find some sort of tutorial site on it. A Warcraft III site will probably not get too many people interested in c++.
     
  11. GreyArchon

    GreyArchon

    Joined:
    Jul 18, 2004
    Messages:
    1,868
    Resources:
    44
    Models:
    25
    Icons:
    14
    Skins:
    3
    Maps:
    2
    Resources:
    44
    My thoughts exactly. Listen to this guy, Eusira and orcfan. He explains my opnion better than I do.
     
  12. orcfan32

    orcfan32

    Joined:
    Jul 3, 2004
    Messages:
    337
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    How can this tutorial be "sharpened" if you will.

    Oh, yeah, I updated it with three new sections.
     
  13. lorothrigs

    lorothrigs

    Joined:
    Aug 2, 2004
    Messages:
    716
    Resources:
    0
    Resources:
    0
    basic programming language is much easier....
     
  14. harper

    harper

    Joined:
    Jan 13, 2005
    Messages:
    559
    Resources:
    0
    Resources:
    0
    Wow, I really dont understand c++ but I like html.
     
  15. DeadDogNoGoWoof

    DeadDogNoGoWoof

    Joined:
    Nov 22, 2004
    Messages:
    1,104
    Resources:
    1
    Icons:
    1
    Resources:
    1
    Ok. MAJOR thread rez here.
     
  16. aarkshark

    aarkshark

    Joined:
    Oct 28, 2004
    Messages:
    521
    Resources:
    0
    Resources:
    0
    thanks for the obvious DDNGW.....
    another thread rez, its like a WC3S version of the scourge.....
     
  17. Dark Destroyer

    Dark Destroyer

    Joined:
    Nov 27, 2004
    Messages:
    158
    Resources:
    0
    Resources:
    0
    >.< lorthrigs just revived an old topic...-_-
     
Thread Status:
Not open for further replies.