Post: [Guide/Basics]The Language of C++ [In Progress]
10-24-2010, 10:46 PM #1
(adsbygoogle = window.adsbygoogle || []).push({});
Drackos's Guide to C++ Scripting

This guide is still under construction! It is about 15% complete!


Please go to the other pages for information about the basics of C++. C++ has many uses, such as programming. It is also most famous on NGU for GSC (the language of Call of Duty), being derived from C++. I will not explain how to create a patch here though.




[multipage=The Basics of a Program]

The first Example:

    
// Program 1

#include <iostream>
using namespace std;

int main ()
{
cout << "Testing: First Program!";
return 0;
}


Elements Found in the example above:

    
//


The // indicate a comment line. Comment lines do not effect the scripting for the program itself and will not cause a syntax error as long as you have the //.

Comment blocks can also be created. They are opened by doing /*. You can write whatever you like in a comment block. You MUST close the comment block with */ though, if you do not, the ENTIRE page is considered a comment block.

    #include <iostream>


THe #include indicates a directing path. It tells the program that it will be using resources from another location. <iostream> is the file where all basic declarations of C++ are.

    using namespace std;


All elements of standard C++ are declared in a namespace.

    int main()


This is the declaration of a main function. The name of the main function cane be located at the top or the bottom of the function itself. The () indicate the actaull declaration of the function. Other parameters can be put in the () if needed.

    {}


Within a main function immediately you will see a {. This indicates the start of the instructions for that function. At the end of the main function it is closed by a }. Once closed, the function's instructions are completed.

    cout << "Testing: First Program!";


This represents a statement in C++. The "cout" indicates that there are a sequence of characters that will follow it. In this case the sequence of characters are "Testing: First Program".

The characters are opened by " and closed with a ". At the end of each statement in C++ you MUST close it with ;. It is the most common syntax error if you do not.

Another good feature about C++ is that you do not need to have spaces between each line. The entire program ideally could be scripted in one line. For example:

    int main () { cout << "Testing: First Program!"; return 0; }


This script would perform exactly the same as the first example written above. As long as the { and } are placed correctly and each statement ends with a semicolon, the program will work.

You can also make multiple lines in the same line with \n.

This allows you to do this:

    
cout << "Testing" \ n"Lol";

Next Page: Basics of Variables and Data.
[multipage=Variables and Data]

NOTE: There is a space between " \ n because if I don't have the spaces there the \ does not appear.

One may think that writing that script for one line to be displayed is a waste of time. While this is true, as it is faster to type it out then script for it. C++ truly becomes useful when variables are introduced.

For example, if I asked you to memorize the number 5 in your memory, and then also memorize the number 2, but then after ask you to add 1 to the first number, you would have to search your mind for the correct numbers. C++ allows you to set variables. For example:

    a = 5;
b = 2;
a = a + 1;
result = a - b


This is extremely simple, but imagine a program running thousands of these variables. Doesn't seem so simple now does it :p?

Each variable listed requires an identifier. In the example above the identifiers were a, b, and result.

Identifiers

Originally posted by another user
A valid identifier is a sequence of one or more letters, digits or underscore characters (_). Neither spaces nor punctuation marks or symbols can be part of an identifier. Only letters, digits and single underscore characters are valid. In addition, variable identifiers always have to begin with a letter. They can also begin with an underline character (_ ), but in some cases these may be reserved for compiler specific keywords or external identifiers, as well as identifiers containing two successive underscore characters anywhere. In no case they can begin with a digit.

Another rule that you have to consider when inventing your own identifiers is that they cannot match any keyword of the C++ language nor your compiler's specific ones, which are reserved keywords. The standard reserved keywords are:


These are the list of reserved C++ keywords:

    
asm, auto, bool, break, case, catch, char, class, const, const_cast, continue, default, delete, do, double, dynamic_cast, else, enum, explicit, export, extern, false, float, for, friend, goto, if, inline, int, long, mutable, namespace, new, operator, private, protected, public, register, reinterpret_cast, return, short, signed, sizeof, static, static_cast, struct, switch, template, this, throw, true, try, typedef, typeid, typename, union, unsigned, using, virtual, void, volatile, wchar_t, while


Some alternative representations for some operators cannot be used as identifiers since they are reserved keywrods in SPECIAL circumstances.

The list:
    
and, and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor, xor_eq


It is extremely important to know that C++ is case sensitive. If the keyword "while" was written as "While" they would no longer be identical.

Another example.

If "result" was written as "RESULT" it would not have the same meaning in C++.

Lets put all of our variable knowledge together now Winky Winky.

    
//Variable main example

#include <iostream>
using namespace std;

int main()
{
//declaring variables
int a, b;
int result;

//process:
a = 5;
b = 2;
a = a + 1
result = a - b;

//print out the result:
cout << result;

//Terminate the program with:
return 0;
}


[multipage=Constants]

Definition: Constants are expressions that have fixed values.

Literals


Definition: the most obvious form of constant. They are used to express particular values within the source code of a program. The previous variables stated in the last page are considered literals. One example:

    a = 5;


the 5 in this piece of code was a literal constant.

There are five types of literal subcategories.

  1. Integer Numbers
  2. Floating-Point Numerals
  3. Characters
  4. Strings
  5. Boolean Values


Integer Numerals


    1776
401
-1231


These are numerical constants that identify decimal values. Notice that to express a numberical constant, no quotes are used or any other special character. There is absolutely no doubt that it is a constant. 1776 in a program is referring to the value 1776.

C++ also allows us to write numbers in octal and hexadecimal. Here is an example:

    75 // decimal notation
0113 // octal notation
0x4b // hexadecimal notation


All of these represent the number 75 expressed as a base-10 numeral, octal numeral and hexadecimal numeral.

Floating Point Numbers


These express numbers with decimals or exponents. Think of it like scientific notation from chemistry class Winky Winky.

Examples:

    3.14159 
6.02e23 //6.02 x 10^23
1.6e-19 // 1.6 x 10^-19


Character and string literals


You can also have characters that are not numbers but still be classified as constants. For example:

    
'a'
'q'
"C++"
"Scripting"


The first two represent "single character constants". Single character constants are enclosed with a ('Winky Winky and string constants are enclosed with (").

[multipage=Operators]

Operator 1: The Equality Symbol (=) (Assignment Operator)


    
a = 137;
Last edited by Drackos ; 11-02-2010 at 12:53 AM.

The following 16 users say thank you to Drackos for this useful post:

One, Actual C++, al9522, Baby-panama, boyyo11, Cody_h4x, dunczzzz, Epic?, Helios, karalex, KingcreekS, Rath, sAmIzErE, skitterz, Stugger, Tupac17
10-24-2010, 10:51 PM #2
Superahm
< ^ > < ^ >
first thread, and post :y:

The following user thanked Superahm for this useful post:

Drackos
10-24-2010, 11:10 PM #3
Helios
Coolest Kid Around.
Nice thread drackos. Should help people understand the basics if they want to begin programming. Stickied.
Last edited by Helios ; 10-24-2010 at 11:27 PM.
10-24-2010, 11:11 PM #4
Originally posted by Helios View Post
Nice thread drackos. Should help people understand the basics that want to begin programming. Stickied.


Why thank you good sir Winky Winky.

Its going to take a while to finish this because I'm juggling classes but I'm working on it as we speak Happy.
03-31-2011, 07:06 PM #5
Cody_h4x
Nobody is like me
Originally posted by Dr.
Drackos's Guide to C++ Scripting

This guide is still under construction! It is about 15% complete!


Please go to the other pages for information about the basics of C++. C++ has many uses, such as programming. It is also most famous on NGU for GSC (the language of Call of Duty), being derived from C++. I will not explain how to create a patch here though.




[multipage=The Basics of a Program]



The first Example:

    
// Program 1

#include <iostream>
using namespace std;

int main ()
{
cout << "Testing: First Program!";
return 0;
}


Elements Found in the example above:

    
//


The // indicate a comment line. Comment lines do not effect the scripting for the program itself and will not cause a syntax error as long as you have the //.

Comment blocks can also be created. They are opened by doing /*. You can write whatever you like in a comment block. You MUST close the comment block with */ though, if you do not, the ENTIRE page is considered a comment block.

    #include <iostream>


THe #include indicates a directing path. It tells the program that it will be using resources from another location. <iostream> is the file where all basic declarations of C++ are.

    using namespace std;


All elements of standard C++ are declared in a namespace.

    int main()


This is the declaration of a main function. The name of the main function cane be located at the top or the bottom of the function itself. The () indicate the actaull declaration of the function. Other parameters can be put in the () if needed.

    {}


Within a main function immediately you will see a {. This indicates the start of the instructions for that function. At the end of the main function it is closed by a }. Once closed, the function's instructions are completed.

    cout << "Testing: First Program!";


This represents a statement in C++. The "cout" indicates that there are a sequence of characters that will follow it. In this case the sequence of characters are "Testing: First Program".

The characters are opened by " and closed with a ". At the end of each statement in C++ you MUST close it with ;. It is the most common syntax error if you do not.

Another good feature about C++ is that you do not need to have spaces between each line. The entire program ideally could be scripted in one line. For example:

    int main () { cout << "Testing: First Program!"; return 0; }


This script would perform exactly the same as the first example written above. As long as the { and } are placed correctly and each statement ends with a semicolon, the program will work.

You can also make multiple lines in the same line with \n.

This allows you to do this:

    
cout << "Testing" \ n"Lol";

Next Page: Basics of Variables and Data.
[multipage=Variables and Data]

NOTE: There is a space between " \ n because if I don't have the spaces there the \ does not appear.

One may think that writing that script for one line to be displayed is a waste of time. While this is true, as it is faster to type it out then script for it. C++ truly becomes useful when variables are introduced.

For example, if I asked you to memorize the number 5 in your memory, and then also memorize the number 2, but then after ask you to add 1 to the first number, you would have to search your mind for the correct numbers. C++ allows you to set variables. For example:

    a = 5;
b = 2;
a = a + 1;
result = a - b


This is extremely simple, but imagine a program running thousands of these variables. Doesn't seem so simple now does it :p?

Each variable listed requires an identifier. In the example above the identifiers were a, b, and result.

Identifiers



These are the list of reserved C++ keywords:

    
asm, auto, bool, break, case, catch, char, class, const, const_cast, continue, default, delete, do, double, dynamic_cast, else, enum, explicit, export, extern, false, float, for, friend, goto, if, inline, int, long, mutable, namespace, new, operator, private, protected, public, register, reinterpret_cast, return, short, signed, sizeof, static, static_cast, struct, switch, template, this, throw, true, try, typedef, typeid, typename, union, unsigned, using, virtual, void, volatile, wchar_t, while


Some alternative representations for some operators cannot be used as identifiers since they are reserved keywrods in SPECIAL circumstances.

The list:
    
and, and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor, xor_eq


It is extremely important to know that C++ is case sensitive. If the keyword "while" was written as "While" they would no longer be identical.

Another example.

If "result" was written as "RESULT" it would not have the same meaning in C++.

Lets put all of our variable knowledge together now Winky Winky.

    
//Variable main example

#include <iostream>
using namespace std;

int main()
{
//declaring variables
int a, b;
int result;

//process:
a = 5;
b = 2;
a = a + 1
result = a - b;

//print out the result:
cout << result;

//Terminate the program with:
return 0;
}


[multipage=Constants]

Definition: Constants are expressions that have fixed values.

Literals


Definition: the most obvious form of constant. They are used to express particular values within the source code of a program. The previous variables stated in the last page are considered literals. One example:

    a = 5;


the 5 in this piece of code was a literal constant.

There are five types of literal subcategories.

  1. Integer Numbers
  2. Floating-Point Numerals
  3. Characters
  4. Strings
  5. Boolean Values


Integer Numerals


    1776
401
-1231


These are numerical constants that identify decimal values. Notice that to express a numberical constant, no quotes are used or any other special character. There is absolutely no doubt that it is a constant. 1776 in a program is referring to the value 1776.

C++ also allows us to write numbers in octal and hexadecimal. Here is an example:

    75 // decimal notation
0113 // octal notation
0x4b // hexadecimal notation


All of these represent the number 75 expressed as a base-10 numeral, octal numeral and hexadecimal numeral.

Floating Point Numbers


These express numbers with decimals or exponents. Think of it like scientific notation from chemistry class Winky Winky.

Examples:

    3.14159 
6.02e23 //6.02 x 10^23
1.6e-19 // 1.6 x 10^-19


Character and string literals


You can also have characters that are not numbers but still be classified as constants. For example:

    
'a'
'q'
"C++"
"Scripting"


The first two represent "single character constants". Single character constants are enclosed with a ('Winky Winky and string constants are enclosed with (").

[multipage=Operators]

Operator 1: The Equality Symbol (=) (Assignment Operator)


    
a = 137;


Nice man great tutorial, Can't wait to see the finished version of it :y:
Very detailed and well explained, good job Claps
04-24-2011, 07:39 PM #6
Merkii
Former Staff
Drackos sorry for the bump but will you be ever updating this?
04-30-2011, 05:27 PM #7
ShinigamiUzi
Proud to be a Player
Great SuperModerator :y:

Thanks for the useful thread.
06-02-2011, 01:57 AM #8
LOl really great thread especially for begenniers :P
06-15-2011, 05:15 PM #9
nice thread drackos
07-25-2011, 12:12 PM #10
Woof
...hmm
Wow, nice thread! :y:
I'm sure this will help allot of people understand the language Smile

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo