Charas-Project

  • Home
  • Help
  • Search
  • Calendar
  • Login
  • Register
*
Please login or register.

Login with username, password and session length
 

News:

New forum theme up and running!



  • Charas-Project »
  • Off-Topic »
  • Archive »
  • Really Old Stuff »
  • General programming »
  • Pyros C++ Tutorials
« previous next »
  • Print
Pages: [1]

Author Topic: Pyros C++ Tutorials  (Read 3520 times)

Offline PyroAlchemist

  • STOP IT NOW!
  • Agent
  • *
  • Posts: 932
Pyros C++ Tutorials
« on: April 20, 2006, 12:09:18 AM »
Alrighty. I would like to go ahead and say. All lessons will be in this post. I will have them labeled so check back every now and again to see. I already have the first 3. Any questions or suggestions then PM me =) Hope this helps.


LESSON 1 Compiler and some basics.

Alright. If you're completely new to C++ then welcome. We hope you learn and enjoy yourself here. First off. You need to get a compiler. If you don't already have one then go here.

Compiler

Download the compiler and install it. They have 5 under beta but I never trust a beta. But thats just me. Once you have it installed then you can get started.

BASICS:

Here are the basics of the basics for you.

#include
using namespace std;
int main()
{
cout << "Hello Programmers World" << endl;
}

____________________________________________________________________

Do you understand that? No well alright. I'll explain.

#include
This says to include the functions of C++. It is needed just so you know.

using namespace std;
This lets us use the cout (pernounced "see out") and cin (pernounced "see in") functions.

int main()
int stands for integer. In C++ a programmer must specify the type of information (data) that is to be placed within the variable. C++ has 16 designated data types which I will cover in a later lesson.

{ }
All your code must be placed within these two brackets.

cout << "Hello Programmers World" << endl;
This simply prints (shows) the text Hello Programmers World. The text between "" is what is shown.

Well I hope this helped you out. I will have the next lesson up A.S.A.P. =D happy programming.

~Gary Robinson


LESSON 1.5 numbers and characters

This one isn't really big enough to have anything past a .5 so here we go.  :D As I statted in the last lesson In C++ a programmer must specify the type of information (data) that is to be placed within the variable. C++ has 16 designated types.

Declaration Name : DATA TYPE DESCRIPTION

char : character
unsigned char : unsigned character
signed char : signed character (same as char)
int : integer
unsigned int : unsigned integer
signed int : signed integer (same as int)
unsigned short int : unsigned short integer

long : long integer (same as int)
long int : long integer (same as long)
signed long int : signed long integer (same as long int)

unsigned long int : unsigned long integer
float : floating-point (Real)
double : double floating-point (Real)
long double : long double floating-point (Real)

Data type example: char initial;
Each data type has a specific range of characters which it can occupy. Below shows each data types range.

Data Type : Range

char : -128 to 127
unsigned char : 0 to 255
signed char : -128 to 127
int : -2147483648 to 2147483647
unsigned int : 0 to 65535
signed int : -2147483648 to 2147483647
unsigned short int : 0 to 65535

long int : -2147483648 to 2147483647
signed long int : -2147483648 to 2147483647

unsigned long int : 0 to 4294967296
float : -3.4E38 to 3.4E+38
double : -1.7E+308 to 1.7E+308
long double :-1.7E+308 to 1.7E+308


And there you have it. Hope this helps you more than confuses you =D
~ Gary Robinson


LESSON 2 if/else

 Hello and welcome to Lesson 2 of my C++ tutorials. If you haven't
already then check out lesson 1 and 1.5 first. They'll be needed to
try and understand this lesson. Well this lesson is on If/Else and is
very useful. A sample program is below.




#include
using namespace std;

//If/Else Tutorial

int main()
{
int answer;
cout << "you like C++? 1=yes and 2=no " << endl;
cin >> answer;
if(answer == 1){
cout << "Great. C++ is very fun." << endl;
}
else if(answer == 2){
cout << "Then why are you looking at this lesson?" << endl;
}
else if(answer >2){
cout << "Um. Can you even read numbers? 0_o" << endl;
}
cin.ignore(1000,'n');
getchar();
return 0;
}


____________________________________________________


Alrighty then. Time to break down the new stuff.

int answer; says that answer will be an integer and therefore is a
number. Find ints range in lesson 1.5.


cin >> answer; cin (pernounced "see in") is an input function. This lets
you input the int answer value. for this to work "int answer;" must be
declared.


if(answer ==1) This says if answer is equal to 1 then to do the code
that is under this.


else if(answer ==2); Is to say if it isn't 1 but is this other number then
to do what is placed under here. You can use these more than once.


else if(answer >2); Says that if the answer is greater than 2 then to do
the code under this line.


cin.ignore(1000,'n');
getchar();
return 0;

All this must be used to get the If/Else functions to work. Without these
the program will just close.

Go ahead and try a couple of programs. Have fun =)

~Gary Robinson
Logged
<img src="http://img20.imageshack.us/img20/4995/pyrotu5.png">

Offline Mr. AJ

  • Member
  • Initiate
  • *
  • Posts: 28
(No subject)
« Reply #1 on: April 20, 2006, 10:01:56 PM »
Decent. You had some of these on RPGA. Keep it up.
Logged
Im such a Megaman nerd. I know everything there is to know. Now if thats not nerdy. Someone tell me what is. And if your describing yourself. Man you need help.

Offline DragonBlaze

  • A Wild DB Appeared!
  • Royal
  • *
  • Posts: 3,329
(No subject)
« Reply #2 on: April 21, 2006, 02:27:47 AM »
That took me 2 months to learn in my compy programming class...
Logged
Hell Yeah! Just recovered all my old rm2k/3 games from my 10 year old, broken laptop hard drive that had been formatted and had a new OS installed on it. Oh, and I did all of this from my phone. WIN

Offline PyroAlchemist

  • STOP IT NOW!
  • Agent
  • *
  • Posts: 932
(No subject)
« Reply #3 on: April 21, 2006, 02:28:36 AM »
lol. really? so was mine clear for you? or would it take to months? XD
Logged
<img src="http://img20.imageshack.us/img20/4995/pyrotu5.png">

Offline DragonBlaze

  • A Wild DB Appeared!
  • Royal
  • *
  • Posts: 3,329
(No subject)
« Reply #4 on: April 21, 2006, 03:09:09 AM »
Yeah, i understand it, I think I could learn it in a day rather than two months :)

Its a bit differant than what I'm used to though, so i got a little confused on some stuff.

For example, I use the iostream.h, but I never have to use that other command before main(). For main, instead of using int main, I've always used void main(), and I never had to use
cin.ignore(1000,'n');
getchar();
return 0;
The only time I have to use the cin.ignore command was when I use strings and had some sort of input before the sting.

I'm guessing these differances are just because our compilers are a bit differant.
Logged
Hell Yeah! Just recovered all my old rm2k/3 games from my 10 year old, broken laptop hard drive that had been formatted and had a new OS installed on it. Oh, and I did all of this from my phone. WIN

Offline PyroAlchemist

  • STOP IT NOW!
  • Agent
  • *
  • Posts: 932
(No subject)
« Reply #5 on: April 21, 2006, 03:32:04 AM »
it could be. what compiler you use? borland, bloodshed dev, VC++?
Logged
<img src="http://img20.imageshack.us/img20/4995/pyrotu5.png">

Offline DragonBlaze

  • A Wild DB Appeared!
  • Royal
  • *
  • Posts: 3,329
(No subject)
« Reply #6 on: April 22, 2006, 03:07:17 AM »
I use microsoft visual C++.
Logged
Hell Yeah! Just recovered all my old rm2k/3 games from my 10 year old, broken laptop hard drive that had been formatted and had a new OS installed on it. Oh, and I did all of this from my phone. WIN

Offline PyroAlchemist

  • STOP IT NOW!
  • Agent
  • *
  • Posts: 932
(No subject)
« Reply #7 on: April 22, 2006, 02:11:47 PM »
Ah see I use Bloodshed Dev C++. That could be it. But I think that either way it'll work on them. Haven't used another compiler to see. In these tutorials I'll be usin Bloodshed Dev C++ though. It's free =)
Logged
<img src="http://img20.imageshack.us/img20/4995/pyrotu5.png">

  • Print
Pages: [1]
« previous next »
  • Charas-Project »
  • Off-Topic »
  • Archive »
  • Really Old Stuff »
  • General programming »
  • Pyros C++ Tutorials
 

  • SMF 2.0.10 | SMF © 2015, Simple Machines
  • XHTML
  • 2O11
  • RSS
  • WAP2
  • Simple Machines Forum