Programming in C++ Getting Started

Everything related to programming.
Post Reply
Fonzeh
Ranger
Posts: 1894
Joined: Tue Oct 16, 2007 3:57 am
Location: "I didn't just take your mom out to dinner. I ate your mom for dinner."
Contact:

Programming in C++ Getting Started

Post by Fonzeh » Sat Nov 12, 2011 9:23 pm

A little C++ Sex... These are highly detailed and explain every single bit of code written, anyone can understand the code written below. It's like a halo tutorial it's done so well. I may be new to C++ but these references are dead accurate and are 100% guaranteed to launch if put in a compiler.

Enjoy and Learn as I did my friends.

Code and Tutorial written by Fonzie, instruction by Bucky @ thenewboston.com

LET IT BEGIN!

*/ are markers for my inserts, explanations, paragraphs, etc. If you have a compiler pop this in and it should light up (more colorful makes it easier / funner to read)


Hello C++! I'm Fonzie!

Code: Select all

#include <iostream>

/*pre processor directive.
includes a file.
*/

using namespace std;

/*'std' means standard library.

includes a library.

the above are includers, including directives
we are using in this test program.

int is an integer, necessary for calculations.

main always works with integers.

the code below is called a function,

Ex. things you want the computer to do.
*/
int main()

/*
main tells the computer where to start.
*/

{
    cout << "Hello world!" << endl;

/*endl; = end line, go to the next line.

cout= output stream object, used to write
characters on screen.

'<<' is a stream insertion operator, takes stuff
to the right of it and prints it out on the
screen.
*/
    return 0;
}

/*main functions should always have a return.

also when the app runs and gets to return 0
it shows that the app made it all the way
to the end with no errors.

all functions are made up of statements
statements are your instructions
each instruction has to end with a
semi-colon to show it has ended its line.

the brackets show the opening and closing
of your statements.
*/


___________________________________________________

Making C++ Show Text Back

Code: Select all

#include <iostream>

using namespace std;

int main()
{
    cout << "MAN I LOVE BACON \n";
    cout << "AND HAM" << endl;

/*
'\n' is a different way to make a new
line other than 'endl'.

doubling it like \n \n, will make a
space between the two lines of text.
*/
    return 0;
}



_________________________________________


Making Variables in C++

Code: Select all

/*
I did what I was told in this example
but this time used what i learned to
make it look and run better.
*/
#include <iostream>

using namespace std;

int main()
{
    int tuna = 6;

/*
int = integers are whole numbers
(6, 83, 540) no decimal places.

remember to end your lines with ;.
*/

    cout << "Tuna (for some reason) equals = "
    << tuna << "\n" << endl;


/*
once ran will show the number 6, not tuna.
tuna is your variable (placeholder) and
since tuna = 6, when it hits tuna, 6 is shown.
*/

    int a = 4;

    int b = 21;

    int sum = a + b;

    cout << "4 + 21= " << sum << "\n \n" << endl;

    cout << "VARIABLE WIN! \n\n" << endl;

    cout << "Made by AnonDavis who is about to be a fucking beast at C++" << endl;

/*
the following code will make the sum 25
appear, just writing the function doesn't
make it show, you HAVE to tell it to print
out the answer (cout).

a and b are variables, you get to type them
instead of the numbers, and the compiler
will substitute the letter for the designated
number, as long as you set it as an integer
first. IE, int a = 4, etc.
*/
    return 0;
}


___________________________________________




A Basic Calculator in C++

Code: Select all

/*
I will be using variables in this app
but this time it will be different.
This time the user will be able to type
in the numbers, instead of pre designated
terms.
*/

#include <iostream>

using namespace std;

int main()
{
    int a;
    int b;
    int sum;
/*
Empty Variables created son! The Program will now
recognize a, b and sum as placeholders.

You don't have to declare the variable
right off the bat, adding a ';' after
your variable will allow the numbers
to be added later.

Also for fucks sake remember the ';'
youll syntax error the shit out of yourself
if you forget.
*/
    cout << "This is a 2 whole number addition application.";
    cout << "\n If you type a letter instead of a number, this will not work... \n\n";
    cout << "Enter a Number Bawss: ";

/*'cout' takes information from your computer
and puts it on your screen.

  'cin' takes information from the user, and
puts it in the computer.. fuckin smart.

~to clarify~

cout= OUTPUT stream object
<< = stream INSERTION operator.

cin = INPUT steam object.
>> = stream EXTRACTION operator.

    Fuckin Smart.
*/

    cin >> a;

/*
smart.
*/

    cout << "Enter another Number Wise Guy: ";
    cin >> b;

    cout << "\n\n";

    sum = a + b;
    cout << "The sum of " << a << " and " << b << " ends up being= " << sum << "\n\n\n\n";

    cout << "Created by AnonDavis, LadyKiller.\n\n\n\n\n";
    return 0;
}


/*You don't have to declare the variable
right off the bat, adding a ';' after
will allow you to state the number
at a later time.

EXAMPLE: int a;
         a = 54

I am sure this can also be used
so the user can put his own choice
of number in later.
*/


_______________________________________________________




Getting away with Mathematical Murder (Arithmetic and Variable Manipulation in C++)

Code: Select all

/*
You can also use Arithmetic when setting variables.

Heres a little lesson in Arithmetic Operators...

EXAMPLE:
    int x = 4 + 6;
    cout << x;
The following will return x as the number 10.
    Fuckin Smart.

    ~uneeded clarifying~

    * = Multiplcation
    + = Addition
    - = Subtraction
    / = Division

But uhh.. wait, what if what were dividing has a remaining number?
By Default the usual line of code 'int x = 81 / 2' will indeed give you
the answer, but leave out the remaining numbers left over entirely.

This is where the % comes in.

% = The Modulous Operator

Simply replace / with %.

But so you know, this is only going to give you the remaining number, not the
answer. What needs to be done should be obvious... look below... dumbass...
*/

#include <iostream>

using namespace std;

int main()
{
    int a = 81 * 2;
    int b = 81 % 2;
    int c = (4+3)* 7;

    cout << a << " Remainder " << b;
    cout << "\n\n\n\n";
    cout << "Let's try something a little more crazy... \n\n\n";

/*
This is one way to make it work, there are others, just use your head.
*/
/*
    ~Order of Precedents~
    Multiple numbers getting butcrunched my the OS
If you use multiplication in the equation you have to use the associative
property technique, or the equation will be summed incorrectly.

Associative Property?! wtf?

() - Parenthesis you dumbass, put them around the Multiplied numbers.

Parenthesis first
then your multiplication and divison
then your addition and subtraction.

EXAMPLE:
            int c = (4+3)* 7;

If you did it without the Parenthesis, it would've done 3x7 first, then added
4, which would've given you 25, instead of 49, which is the correct answer.
*/


    cout << c;

    cout << "\n\n\nCreated by AnonDavis who is way more epic than Slappey.\n\n\n";


    return 0;
}


/*
    I should be getting paid to be this smart.
*/

I'd clap right now but i can barely type due to my fingers hurting FROM ALL THIS CODWEALNFASFN

Main code was from a tutorial from thenewboston.com

http://www.thenewboston.com/?cat=66&pOpen=tutorial

^^ All his Video C++ videos, what I shown above is covered, I just added notes between the code for usefullness, and modified the code to make the ending application look better / more organized.

Hope this helps you guys!
G[v]N wrote:HUGE NOTIFICATION
THIS GRAVY HAS BRAINS
Mota-Lev was here 30/4/2010@2:18pm
Image

tokage
Ranger
Posts: 1459
Joined: Sat Dec 06, 2008 4:28 pm
Location: Between the 'y' and 'i' keys.
Contact:

Re: Programming in C++ Getting Started

Post by tokage » Sat Nov 12, 2011 11:30 pm

I need to read these tomorrow!

In the mean time... I need a way to show how neat this is...


NEATOMETER!
_____
10| X - Pretty fucking neato!
9 | X
8 | X
7 | X
6 | X
5 | X
4 | X
3 | X
2 | X
1 | X
Image

Fonzeh
Ranger
Posts: 1894
Joined: Tue Oct 16, 2007 3:57 am
Location: "I didn't just take your mom out to dinner. I ate your mom for dinner."
Contact:

Re: Programming in C++ Getting Started

Post by Fonzeh » Sun Nov 13, 2011 10:28 pm

I would suggest watching the videos linked, because that's where i got the tutorial from, what's cool about mine though is the fact that i added comments that explain every bit of code typed. I thought this would be necessary for those who didn't know wtf was going on.
G[v]N wrote:HUGE NOTIFICATION
THIS GRAVY HAS BRAINS
Mota-Lev was here 30/4/2010@2:18pm
Image

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest