Introduction - About C++
C++ is a low-level programming language that is flexible and has a very specific syntax. You can do anything from displaying a simple piece of text in a console to coding high graphical games that provides entertainment for the user. Whatever the purpose may be you have to start somewhere. When I got my first C++ book I picked it up for the first time, read the first few pages and in my hopes to succeed I failed numerous time as I would put the book down and never pick it up again.
Well now I have picked the book up and put the book down finally finishing all 361 pages. Throughout my coding experience I have come to realize that one of the things that makes it hard to learn the language is the fact that the person teaching you is a professional. This means the professional may not always explain things at your level. So, my goal today is to try and reach that level just like a friend did for me when I started C++. Although, many claim to be C++ professionals or the so called "Uber Coder Geeks" nobody can ever know all of C++. It's just too big of a program and it would take literally decades.
But, do not let this affect you even some of the best programmers in the world don't know the whole language inside and out. They may have a very complex understanding within the language but nobody can know all of it. It pretty much depends on how much time you devote on learning the language and how far you can go before you just do not want to continue or until you just don't understand anymore.
In a way it is like math, you can probably learn each and every math equation and know every answer to every math problem by spending years even decades on it devoting your life to math. But, the person down the street is a gifted 12 yo who is going to college and getting a computer science degree. So, it also depends on the person.
So, let me begin by saying I am not a C++ professional. If I state anything that may be incorrect please address it properly without making a big issue about it. I have noticed that a lot of arguments go on within the C++ section about who is right and who is wrong.
Lesson 1 - Understanding C++
Syntax
A syntax is nothing other then a the rules of a language. A language can not operator if it has no guidelines thus there is a syntax. So, a syntax acts like your TV remote for example. If you want a specific channel you can't just start punching in random numbers and expect it to go the channel you want. So, Each channel has its own number and depending on the service you have the number for that channel would be different. So for Direct TV the channel for cartoons might be 225 but for AT&T it would be 315. You still use a remote but you have to use a different syntax or "Channel Number" in this case.
So, here are to examples.
Python 3.0 - "Hello World"
Dev C++ - "Hello World"Code:print ("Hello World")
A perfect example on why C++ is a low-level language and Python would be a high-level language.Code:// Hello World Program // Demonstrates displaying text #include <iostream> using namespace std; int main() { cout << "Hello World"; system("PAUSE"); return 0; }
Here is something that also confuses people. What is cout? and what is cin? Well even though some of the other programmers might have a very complex explanation for them. All I need to tell you is think of them as this. Console Output and Console Input. The easiest way to remember how to display output is thinking of cout as c - out and cin as c - in. Meaning console output and console input. You will learn more about this later on in the book that I provided at the end of this book.
A Comment
A comment is nothing more then putting a little message inside the code for fellow programmers to read or explaining a piece of code that is not very clear. To make a comment all you have to do is place two forward slashes or // marks. Please keep in mind that a comment does not display text to a user. It only provides little pieces of information to another coder on the team or to help remind yourself of something you are going to do with the code in the future. Here are some examples of comments.
Now, normally you would not place that many comments in a section like that but this is an example. You can place a comment after a piece of code, you can place a comment on the same line of a piece of code, and you can also place a comment in between pieces of code. It common to place comments right after or before pieces of code to avoid confusion. You also want to avoid commenting on the obvious.Code:// Name of project // About my project #include <iostream> using namespace std; int main() { cout << "This is a Test Project"; // This displays text. Which is obvious. // I will eventually work on something here... return 0; }
Another way to make a comment is by using /* This is a comment */ the reason this is a good thing to use is because if you are commenting on a piece of code it can be hard to find out where the comment ends or not unless you have a color coded compiler like me. For user friendly purposes I color coded every piece of code provided in this code so it is easier to read.
The Pre-processor
The pre-processor is a operator that tells the compiler to locate a library file within the compiler and insert the contents of that library file. Although it is not visually inserted just the fact that it is told to insert it means it is there. Here is some example code.
Here you will seeCode:// Project Name // Demonstrates the Pre-processor #include <iostream> using namespace std;
the #include <iostream> tells C++ to locate library "iostream> and the greater than ">" and less then "<" sign tell the compiler to locate the file wherever the compiler holds its libraries. This way you do not have to find out what the location is for each C++ compiler you are using. Weather its C++ Borland or Dev C++. Just below that you will seeCode:#include <iostream>
Code:using namespace std;
the using namespace std; tells the compiler to use namespace standard. A namespace is a namespace scope which is used to avoid name collisions with variables, types, classes, or functions. Defining a namespace is much like defining a class. First you put in the namespace keyword then the identifier (the name of the namespace) followed by member declarations. You may also create your own namespaces but this is a more advanced feature that you will learn later on in your programming experience.
(Some of this is quoted from Tomas Restrepo)
For more information on namespaces please refer to Tomas Restrepo's guide on namespaces provided in the following link. Tomas Restrepo's Guide - Namspaces
Variables
Variables are simply expressions that are assigned values.So if you say a = 1 a would be a variable. Here are some examples on how you can use variables.
As you can see you define a variable then use the variable to store information. In the book I provide at the end of this tutorial it tells you that you may use a batch file to view a your code. This is because when you enter your code to display text or do whatever it is you are doing. It reads the code so fast then closes the program. To stop this you can either use the getchar() which I do not recommend or you can use the system("PAUSE"); which I do recommend. You can also use a system("CLS"); to clear everything on the screen before the system("CLS"); code is displayed. Everything after that will be displayed at the top again until you use another system("CLS"); or until the program ends.Code:// Address Book 1.0 // Recieves and stores data #include <iostream> using namespace std; int main() { string name; string address; int age; cout << "Please enter the follow information.\n"; cout << "Name: "; cin >> name; cout << "\n"; cout << "Age: "; cin >> age; cout << "\n"; cout << "Address: "; cin >> address; cout << name << "\n" << age << address << endl; system("PAUSE"); return 0; }
Next, I use the string, and int to define my variables. I use string to define my first variable "name" and my second variable "address" because I know that there will be an array of characters in a name and I also know in an address there is usually an array of characters and numbers. Then I use cout to display text "Console Output" and then I use cin to receive data "Console Input".
Alright, so if you made it this far and read this whole guide. CONGRATS! if not well I recommend starting from the top and getting it over with while you can. Below are some definitions, source files from the projects in the book, the book, and the setup.exe to Dev C++ Bloodshed. Thank you for reading my tutorial until next time I am Donovan Simon with the awesome forum of CodeCall
Definitions
These are a few important things you should remember before moving on.
&& - Logical And
!= - Logical NOT
== - Equal to
bool = Bool or Boolean as its normally called is a variable that stores either a True or False value. A number like 1 being true and a number like 0 being false.
string = A string is an array of characters. "This text would be a string" strings are used to assign characters or letters to a variable.
int = Int or integer as its normally called is a variable that stores a number. In this case it is a short integer so it would store a whole number integer. Meaning 1, 2, 3 but not 1.1, 2.2, or 3.3
double = This is a double integer meaning it allows you or the user to store either 1, 2, 3, 1.1, 2.2, and 3.3.
- Dev C++ Bundle
Includes -
The Dev C++ Book
The Program "Bloodshed Dev C++"
All project files from Chapter 1 - Chapter 10.
Last edited by WingedPanther; 03-07-2009 at 04:24 AM.
Quite a detailed guide mateDidn't learn much, yet it is the basics. But still helpful to those new to C++
I would +rep but I can't at the moment![]()
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation
Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!
Alrighty thenlol maybe if I add reputation avatars and am a +rep eater I will have billions of rep like Xav haha.
Nicely done, lots of information here. I hate the blue font though but I'll still +rep you.![]()
I did that for a reason to point out bits of code that are in black
Thanks for the rep![]()
A good read but before someone flames you - you called python low-level and c++ high level. Its the other way around Posted via CodeCall Mobile
Termana's right, C++ is mid- to low-level. Also, since system() calls commands in the OS, the commands you can call depend on the target OS. That said, it's an excellent introduction. Well done and +rep!
Thank you both for pointing out the high - level and low - level situationI always get those to mixed up. Also the system() function I know depends the operating system the problem was remembering to add that part to the end while adding all the forum coding lawls. Since I color coded all my code it got really confusing. Anyway thanks for the +rep and the pointers. For any questions please add my msn.
Donovan.Simon@hotmail.com
Last edited by Donovan; 12-16-2008 at 08:38 PM.
+ rep.
Great job!
Interested in participating in community events?
Want to harness your programming skill and turn it into absolute prowess?
Come join our programming events!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks