Charas-Project
Off-Topic => Really Old Stuff => Archive => General programming => Topic started by: PyroAlchemist 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 (http://www.bloodshed.net/devcpp.html)
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
-
Decent. You had some of these on RPGA. Keep it up.
-
That took me 2 months to learn in my compy programming class...
-
lol. really? so was mine clear for you? or would it take to months? XD
-
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.
-
it could be. what compiler you use? borland, bloodshed dev, VC++?
-
I use microsoft visual C++.
-
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 =)