C++ Tutorial in depth

Discussion in 'Programming General' started by spots13, Sep 14, 2011.

C++ Tutorial in depth
  1. Unread #1 - Sep 14, 2011 at 8:51 PM
  2. spots13
    Joined:
    Feb 29, 2008
    Posts:
    213
    Referrals:
    0
    Sythe Gold:
    0

    spots13 Active Member
    $5 USD Donor New

    C++ Tutorial in depth


    WELCOME TO SPOTS13 C++ TUTORIAL

    SECTION 1.1
    Well guys, I've decided to start this thread with the intention of making a tutorial guideline for everyone, in which we are going to review C++ from the basis and going over and over, I'm gonna be explaining in detail every step we are doing right here, so everyone is able to understand it in a very easy way, also I'm gonna give some common mistakes and some useful tips for programming in C++ and basically in any other language.

    So lets Get Started

    OUR FIRST PROGRAM

    print a code line

    well in this first exercise the idea is to get familiarized with the C++ code and show some important features within the language.


    this will show


    IMPORTANT:
    please note that every instruction ends with a semicolon ;.

    "//" are used to mark comments and everything inside them will not affect the program the only purpose of them is the clarify some points of our program for other users who might read it .

    every code line which starts with a # state ans the "#include<iostream>" is because that lines are processed before the program is compiled, as it is a raw program you must show the processor which headlines it uses, in this case the library "<iostream>" allows the processor to use the file of the headline that includes the input/output stream, this file must be included for every program which receives data imputed by keyboard or that shows data on screen.

    "\n" is a escape sequence that place the mouse in a new line in the screen, just a like the "ENTER" key does. (I might make a char including every escape sequence available).

    the parenthesis just after the "main" function indicates that it is a construction space which is called function. C++ programs are usually made of
    one or more functions or classes (which I'm showing you later) there must be just one "main" function because the program is being executed when the main function appears even doe if main is not the first function declared.

    the reason the the "main" function is being declared as an "int" is because it allow us to return a integer value in this case it allows the program to return the value 0 when it is executed properly.

    the blue words on the code are called as keyword, they are reserved words for C++ and they are used for an specific task.

    the open key parenthesis "{" must begin the body of every function and the close key "}" ends the body of it.

    the cout is used to print a characters on screen, the notation std:: before it specifies that we are using a name that we have taken from #include<iostrem> and that belongs to the "name sapace" the "name spaces" are a more advanced characteristic of C++ and I'll be explaining it later on

    Section 1.2

    well assuming you have read the last section and that you have done your first program already we are to introduce the input stream operator which is std::cin, it uses the operator >> for the extraction; we are going to make a program that receives two integer numbers by keyboard (which are inputted by the user) it calculates the addition between both numbers and prints the result using the std::cout that we have already seen before

    Note* I leave spaces in between lines for better readability of the source code and the comments if you find it annoying please let me know.

    THIS WILL SHOW
    IMPORTANT:

    int a; , int b; , int add; they all are declaration, the identifiers "a","b","add" are variable names, a variable is a store place within the memory of you pc, in which you can store a value for using it while the program is running. These declarations determine that variables a,b,add are data categorized as int type, that means these variables contain integer values (every number between (-infinity & infinity with out using decimals). Every variable must be declared with a name and a type before using it on the program, you can declare in the same line every single variable that shares the same type, just as shown

    int a, b, add;


    this reduce legibility to our program and prevents you from commenting on each single variable, REMEMBER if you are to declare variables this way you must separate them by colons (,), I recommend using a space after the colon is set but that is not necessary is just for it to look nicer

    you can declare or assign value to your variables whenever you like in your program, just remember to declare them before using them


    the assignation done in the program "add = a+b;" is an assignation that you do as a programmer and is not shown on screen after the compile is done, while you are programming you have to take care of which type of assignation do you need for the variables you use, user made (asking for an input value entered by keyboard)or programmer made just like the one before


    Section 1.3


    Now that we have learned how to show data in screen using std::cout and asking for data with std::cin we can’t go further without checking the charts of operators relation and equality, this is because we are introducing in this section to the instruction if, if’s are made of relations between data, just like in real life, if you eat you meal then you are going to have dessert this is the basic idea of the if instruction
    Its structure is:

    This is basic if construction later on, we might see some more complex instructions, like nested if’s with “else” instruction and so on.
    In the next example we are moving on the “using” declarations this safes the need of using “std::” before each instruction like we did in the programs before, once we use “using” deckarations instead of use “std::cin” you simply use the cin or cout, endl or w/e instruction you have declared ; from now on we are going to use “using declarations” for each program.

    In the next program we are going to use if’s to compare 2 numbers inputted by keyboard and show in screen which of them is greater, smaller, equal, not equal…. and so on.


    on the following we have the charts that are needed for this program and the ones we are going to be creating in the future.

    [​IMG]


    and

    [​IMG]

    so let's start
    This Will Show


    OR

    OR

    IMPORTANT:


    We are using open key and close key on the if’s that we are using, if we use a basic if is not necessary to use them, but is preferable, but later on maybe on the chapter 3 we’re going to see compound if’s with more than one instruction and with those it is a must to use the key’s operators

    the operations hierarchy is just as in normal math including parenthesis and everything ​

    END OF SECTION 1



    SECTION 2

    SECTION 2.1

    well as many of you might know while checking these c++ is an OOP which means object oriented programming language and in this section we are introducing you guys for the real stuff, and I mean classes, objects, functions and more after this section I'm willing to give you guys some terminology some exercises and some auto-evaluation exercises with their answers so have fun a let's begin

    first I'm going to explain what classes are with a simple analogy let's suppose that you drive a car and for it to accelerate you got to press the accelerator
    but before you could do that there must be an engineering who designed the accelerating system which the accelerator hides, this allows the non-experienced users to be able to drive just by knowing the function of the pedal and not the process involved.

    well now let's take our car example to the c++, for doing a task in an application there is required a function (just like the "main" we use in the last chapter) the function describes the mechanisms that are in charge of doing his tasks , the function hides the user the complex tasks that it does, just as the accelerator pedal, in C++ we create a unit application called class to store a function just as the car design stores the pedal's engineering we are going to see more about this topic in the future so don't worry.

    let's begin with a short example of what a class is, let's GradingSheet is a class that represents a grading sheet that a random teacher uses to maintain his students grades, and the function main creates an object , GradingSheet. The function main uses the object and it's function to welcome the teacher to his grading sheet program, this is a simple explanation of the topic later on we are going to see more sophisticated ways for improving and to achieve a better software if you like prefer to say it that way.


    this will show


    IMPORTANT:


    before the function main is able to create an object of the class GradingSheet, we must show to the compiler which are member functions and which data members belongs to that class, this is known as "class definition" . the "class definition" GradingSheet contains a function called showmessage which shows a message on screen. Remeber that a class is like the construction plans; that is why we need to create an object of the class GradingSheet and recall it's fucntion showmessage for allowing the program to execute that line ans show the welcome message on screen.

    the class definition starts with the keyword "class" and next goes the name of the class in this case "GradingSheet" a user defined class goes with the first letter in caps

    the Body of the class is in between of to open and close keys "{" "}" and the definition of the Body ends with a semicolon ";"

    Remember the function "main" is always auto recalled by the program major functions are not recalled automatically, as we are going to see he have to explicit call the function "showmessage" in an explicit way to indicate it to do his task

    the keyword public is an access identifier, in the program we define the function "showmessage" as "public" to indicate the obvious, it has public access, this means any other function in the program (just as main) can recall it, and also the member function of other classes (if there are any), later on we are going to see the "private" identifier




    Coming soon:

    In the mean time I'm going to post a compiler and an IDE for you guys to use while practicing



    Good luck play safe

    Have fun and practice a lot,
    for you
    ---
    Spots13.
     
  3. Unread #2 - Sep 14, 2011 at 9:42 PM
  4. Terrankiller
    Joined:
    May 7, 2005
    Posts:
    1,286
    Referrals:
    1
    Sythe Gold:
    1

    Terrankiller Ex-Administrator
    Retired Administrator Visual Basic Programmers

    C++ Tutorial in depth

    Right on. Better than most of the starter guides I have read as you actually explain every line.
     
  5. Unread #3 - Sep 14, 2011 at 10:31 PM
  6. spots13
    Joined:
    Feb 29, 2008
    Posts:
    213
    Referrals:
    0
    Sythe Gold:
    0

    spots13 Active Member
    $5 USD Donor New

    C++ Tutorial in depth

    thanks I appreciate this coming from you,
    Sure I'll keep it and well if there is anything you wanna add please tell me or even if someone needs help I''m always available if you need me
    thanks again @Terra
     
  7. Unread #4 - Sep 14, 2011 at 10:42 PM
  8. The Black Tux 2
    Joined:
    Aug 27, 2011
    Posts:
    123
    Referrals:
    0
    Sythe Gold:
    0

    The Black Tux 2 Active Member

    C++ Tutorial in depth

    Nice guide. I really like how you take everything slowly.
     
  9. Unread #5 - Sep 15, 2011 at 9:10 PM
  10. spots13
    Joined:
    Feb 29, 2008
    Posts:
    213
    Referrals:
    0
    Sythe Gold:
    0

    spots13 Active Member
    $5 USD Donor New

    C++ Tutorial in depth

    edit to main post, added section 1.2
     
  11. Unread #6 - Sep 15, 2011 at 9:39 PM
  12. The Black Tux 2
    Joined:
    Aug 27, 2011
    Posts:
    123
    Referrals:
    0
    Sythe Gold:
    0

    The Black Tux 2 Active Member

    C++ Tutorial in depth

    To which depth will this guide go?

    Looking nice 1.2
     
  13. Unread #7 - Sep 15, 2011 at 9:46 PM
  14. spots13
    Joined:
    Feb 29, 2008
    Posts:
    213
    Referrals:
    0
    Sythe Gold:
    0

    spots13 Active Member
    $5 USD Donor New

    C++ Tutorial in depth

    if I got the time maybe I could reach to game programming with OGRE and boost libraries c++ox well at least that's my plan
     
  15. Unread #8 - Sep 16, 2011 at 6:18 PM
  16. spots13
    Joined:
    Feb 29, 2008
    Posts:
    213
    Referrals:
    0
    Sythe Gold:
    0

    spots13 Active Member
    $5 USD Donor New

    C++ Tutorial in depth

    edit main post added section 1.3 and planning already 2.1
     
  17. Unread #9 - Sep 17, 2011 at 4:42 AM
  18. Terrankiller
    Joined:
    May 7, 2005
    Posts:
    1,286
    Referrals:
    1
    Sythe Gold:
    1

    Terrankiller Ex-Administrator
    Retired Administrator Visual Basic Programmers

    C++ Tutorial in depth

    Which IDE and compiler do you use?
     
  19. Unread #10 - Sep 17, 2011 at 8:57 AM
  20. spots13
    Joined:
    Feb 29, 2008
    Posts:
    213
    Referrals:
    0
    Sythe Gold:
    0

    spots13 Active Member
    $5 USD Donor New

    C++ Tutorial in depth

    At the moment I'm working with the 2005 ,and the 2011 studio express but I might also post the code for the DevC++ which is not so different from the actual code of the studio versions
     
  21. Unread #11 - Sep 17, 2011 at 9:06 AM
  22. SuF
    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary

    SuF Legend
    Pirate Retired Global Moderator

    C++ Tutorial in depth

    I didn't read it, but I glanced through it and it is actually fairly good. I like that you explain what you are doing instead of just throwing a ton of code out in front of people.
     
  23. Unread #12 - Sep 17, 2011 at 3:19 PM
  24. spots13
    Joined:
    Feb 29, 2008
    Posts:
    213
    Referrals:
    0
    Sythe Gold:
    0

    spots13 Active Member
    $5 USD Donor New

    C++ Tutorial in depth

    thanks, hope you got the time to read it someday, and well I'll keep updating it in the meanwhile

    Updated main post, just added the section 2 and 2.1 which introduces to objects and classes in c++ :) yay! well have fun and practice
     
  25. Unread #13 - Sep 18, 2011 at 3:16 PM
  26. The Black Tux
    Joined:
    Apr 19, 2009
    Posts:
    10,306
    Referrals:
    30
    Sythe Gold:
    55
    Vouch Thread:
    Click Here
    Two Factor Authentication User Cool Kid Former OMM Cook RsProd Sythe Awards 2012 Winner Village Drunk

    The Black Tux Veteran
    The Black Tux Donor Java Programmers PHP Programmers

    C++ Tutorial in depth

    Shouldn't it go up to 1.9 :p

    Oh well, it's basic programming stuff up to 2.1, let see how you continue.
     
  27. Unread #14 - Sep 19, 2011 at 1:27 AM
  28. Romperin
    Joined:
    Apr 15, 2011
    Posts:
    487
    Referrals:
    2
    Sythe Gold:
    0

    Romperin Forum Addict
    Banned

    C++ Tutorial in depth

    v'nice.
    I'm beginning so this will be useful. ;)
     
  29. Unread #15 - Sep 19, 2011 at 9:32 AM
  30. spots13
    Joined:
    Feb 29, 2008
    Posts:
    213
    Referrals:
    0
    Sythe Gold:
    0

    spots13 Active Member
    $5 USD Donor New

    C++ Tutorial in depth

    Glad you like it, with a little of time today I'll be updating it to the 2.2 section with more about classes and objects so keep tune up :D
     
  31. Unread #16 - Sep 20, 2011 at 6:50 PM
  32. spots13
    Joined:
    Feb 29, 2008
    Posts:
    213
    Referrals:
    0
    Sythe Gold:
    0

    spots13 Active Member
    $5 USD Donor New

    C++ Tutorial in depth

    bump.
     
  33. Unread #17 - Sep 29, 2011 at 8:37 PM
  34. spots13
    Joined:
    Feb 29, 2008
    Posts:
    213
    Referrals:
    0
    Sythe Gold:
    0

    spots13 Active Member
    $5 USD Donor New

    C++ Tutorial in depth

    bump.
     
  35. Unread #18 - Oct 3, 2011 at 8:22 AM
  36. Leaderjack
    Joined:
    Jan 24, 2011
    Posts:
    225
    Referrals:
    0
    Sythe Gold:
    0

    Leaderjack Active Member
    Banned

    C++ Tutorial in depth

    It might be a bit better if you told us what programs to use? Provided us with links to download? told us what program type we do? stuff like that
     
  37. Unread #19 - Oct 4, 2011 at 10:56 PM
  38. FreakNasty188
    Joined:
    Jul 15, 2011
    Posts:
    174
    Referrals:
    0
    Sythe Gold:
    0

    FreakNasty188 Active Member

    C++ Tutorial in depth

    Hey I'm pretty new to C++ programming, but why don't you just type "using namespace std;"? Instead of using std::cout each time? Just curious. Please don't flame me if this is a stupid question, like I said I'm new to C++.
     
  39. Unread #20 - Oct 4, 2011 at 11:06 PM
  40. spots13
    Joined:
    Feb 29, 2008
    Posts:
    213
    Referrals:
    0
    Sythe Gold:
    0

    spots13 Active Member
    $5 USD Donor New

    C++ Tutorial in depth

    it´s true and the answer is for you to know from where it comes from nothing more
     
< Help with a program | » Pelican - [Mass Mailer - AIO phisher - Detailed logs - CHEAP] >

Users viewing this thread
1 guest


 
 
Adblock breaks this site