Getting Set Up - C++ CompilersThe first thing you need to do, before starting on the C + +, is to ensure that you have a c...
The next important line is int main (). This line tells the compiler that a function called main, and thatfunction returns...
An Aside on Commenting Your ProgramsWhen you learn to program, you also have to start learning how to explain your program...
Declaring Variables in C++To declare a variable that you use the syntax "<name> type:". Here are some examples of variable...
Lets take a break and check this program line by line. Int declare thisisanumber keyword to an integer.Function cin >> to ...
Tutorial The basics of C++          Lesson 1           Special Thanx’s To :                God Allah               My Fami...
Tutorial basic of c ++lesson 1 eng ver
Upcoming SlideShare
Loading in …5
×

Tutorial basic of c ++lesson 1 eng ver

528 views
489 views

Published on

Just a simple Tutorial basic of c ++lesson 1 english version

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
528
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Tutorial basic of c ++lesson 1 eng ver

  1. 1. Getting Set Up - C++ CompilersThe first thing you need to do, before starting on the C + +, is to ensure that you have a compiler. Whatcompiler, you ask? A compiler converts a program you write to an executable that your computer iscancorrectly understand and execute. If you take the course, you may have one administered through yourschool. If you start out on your own, your best bet is to use Code :: Blocks with MinGW. If you are onLinux,You can use g + +, and if you are on Mac OS X, you can use XcodeIntro to the C++ LanguageA C + + program is a collection of commands that tell the computer to do "something". Collection oforders is usually called C + + source code, source code or just the code. A good command "function" or"keyword". Keyword is a block basic building blocks of language, while the function is, in fact, usuallywritten in the form of simple functions - youll see this in our first program, below. ? (Confused Think ofit less as a framework for a books; line may indicate each chapter in this book, each chapter may have itsown line, made up of sections each section may have its own line, or it may have all. written details)Happily., C + + provides the functionality of the general and the keywords you can use.But how does a program actually begin? Each program in C + + has a function, is always named main,which is always called when your program first starts up. Of the primary, you can also call the function-other functions if they were written by us or, as mentioned earlier, provided by the compiler.So how do you get access to prewritten functions? To access the functions that come standard withcompiler, you include a header with the directive # include. What this does is effectively take everythingin the header and paste it into your program. Lets look at the work program: #include <iostream> using namespace std; int main() { cout<<"Qrembiezs Intruder was here!n"; cin.get(); }Lets take a look at the elements of the program. The # include is a "preprocessor" directive that tells thecompiler to put the code in the header called iostream into our program before actually making theexecutable. by including header file, you get access to different functions. For example, the functionrequires iostream court. Follow include the statement, "using namespace std; . This line tells thecompiler to use the group functions is part of the standard library (std). By including this line at the topof the file, you allow the program to using functions like a court. The semicolon is part of the syntax of C+ +. This tells the compiler that you at the end of the command. You will see later that the semicolon isused to end most commands in C + +.
  2. 2. The next important line is int main (). This line tells the compiler that a function called main, and thatfunction returns an integer, hence int. The "curly braces" ({and}) signal the beginning and end of thefunction and other code blocks. You can think of them as the meaning of BEGIN and END.The next line of the program may seem strange. If you have programmed in other languages, you maywish to print will be a function used to display text. In C + +, however, the courts are used for objectdisplay text (pronounced "C out").It uses the << symbols, known as "insertion operator", to show what is the output. cout << result in thefunction call with the following text as an argument to the function. citing informed compiler that youwant to output a string literal is. The sequence n is actually treated as a single characterstands for a new line (well discuss this in more detail later). This moves the cursor on your screen to theline next. Again, notice the semicolon: is added to the last line, such as calling a function, in C + +.The next command is cin.get (). This is another function call: it reads the input and expect the user topress the button again. Many compiler environments will open a new console window, run the program,and then close the window. This command makes the window from closing because the program is notfinished because you are waiting for press enter. Including the line that gives you time to see therunning program.Having achieved the primary end, clamp shut, our program will return the value 0 (and integer, thenwhy we say the main to return int) for the operating system. The return value is important because itcan used to tell the OS whether our program succeeded or not. A return value of 0 means success andreturned automatically (but only for the main, other functions require you to manually return value), butif we want to return something else, such as 1, we have to do with return statement: #include <iostream> using namespace std; int main() { cout<<" Qrembiezs Intruder was here!n"; cin.get(); return 1; }Final closing brace of the function. You should try to compile and run this program. You can cut andpaste the code into the file, save it as a cpp file.
  3. 3. An Aside on Commenting Your ProgramsWhen you learn to program, you also have to start learning how to explain your programs (for yourself,if no one else). You do this by adding a comment to the code, I would use it frequently to help explainthe sample code. When you tell the compiler part of the text comments, he will ignore it when runningthe code,allows you to use the text you want to describe the real code. To make a comment make use ofthe sign / /, which tells the compiler that the rest of the line is commented out, or / * and then * / tomark the that all of the comments. Specific compiler environments will change the color of thecomment area, but some do not will. Be certain not accidentally comment out code (that is, to tell thecompiler part of your code is a comments) that you need for this program. When you learn to program,it is useful to be able to comment section of the code to see how the output is affected.User interaction and Saving Information with VariablesSo far you have learned how to write a simple program to display information typed by you,programmer, and how to describe your program with the comment. Thats fine, but how it interactswith your users? Fortunately, it is also possible for your program to accept input. You use the functionknown as cin, and followed by the insertion operator >>.Of course, before you attempt to receive input, you must have a place to store input. In programming,input and the data stored in the variable. There are several types of variable that stores various types ofinformation (eg numbers Versus letters), you tell the compiler when you declare a variable, you mustinclude the data type and its name variable. Several basic types include char, int, and float.A variable of type char stores a single character, variables of type int store integers (numbers withoutdecimal), and variable of type float store numbers with decimal places. Each type of variable - char, int,and float - is each keyword that you use when you declare a variable.Whats with all these variable types?Can sometimes be confusing to have some type of variable when it seems like some kind ofvariables are redundant (why when you have an integer number float). Using the right type of variablemay be important to make your code readable and for efficiency - some variables require memorymore than others. In addition, because of the way the numbers are actually stored in memory, the floatis "exact", and should not be used when you have to keep a "proper" value of an integer.
  4. 4. Declaring Variables in C++To declare a variable that you use the syntax "<name> type:". Here are some examples of variabledeclarations: int x; char letter; float the_float;It is permissible to declare multiple variables of the same type on the same line, each must be separatedby commas. int a, b, c, d;You may have seen that the variable declarations are followed by a semicolon (note that this is aprocedure that the same used when you call a function).Common Errors when Declaring Variables in C++If you try to use a variable that you have stated, your program will not compile or run, and you willreceive an error message informing you that you have made a mistake. Typically, this is called UndeclareVariable Case SensitivityNow is a good time to talk about an important concept that can easily throw you off: sensitivity of thecase. Basically, in C + +, if you use uppercase or lowercase letters p. Cat and kitten word meaningdifferent for the compiler. In C + +, all language keywords, all functions and all variables are casesensitive. Differences in variable declarations between you and the use of variables is one reason youmight get error variable Using VariablesOk, so you now know how to tell the computer about the variables, but how to use them?Here is a sample program that demonstrates the use of variable #include <iostream> using namespace std; int main() { int thisisanumber; cout<<"Please enter a number: "; cin>> thisisanumber; cin.ignore(); cout<<"You entered: "<< thisisanumber <<"n"; cin.get(); }
  5. 5. Lets take a break and check this program line by line. Int declare thisisanumber keyword to an integer.Function cin >> to read the value into thisisanumber, the user must press enter before the number isread by the program. cin.ignore () is a function Another read and discard characters. Remember thatwhen you type input into the program, it takes the enter as well. We do not need this, so we throw itaway. Note that the variable is declared integer, if the user tries to type a decimal number, it will betruncated (ie, components of decimal numbers will be ignored). Try typing in sequence of characters ora decimal number when you run the example program; response will vary from input to input, butin case it is not too pretty. Note that when printing out a variable quotation marks are not used. Is thereany sign of quotation, the output will be "You Entered:. Thisisanumber" The lack of quotation marks tellsthe compiler that there are variables, and because the program should check the value of a variable thatcan change the variable names with variables when running the output function. Do not be confusedwith the inclusion of two separate insertion operators on one line. Including the operator insertion inone lines perfectly acceptable and all output will go to the same place. In fact, you must separate stringliterals (strings enclosed in quotation marks) and variables by giving each its own insertion operators(<<). trying to put two variables together with only one << will give an error message, do not try it.Do not forget to end functions and declarations with a semicolon. If you forget the semicolon, thecompiler will give an error when You try to compile the program. Changing and Comparing VariablesOf course, no matter what type you use, the variable is not interesting without the ability to modifythem. Some operator used with variables are as follows: *, -, +, /, =, ==,>, <. * Multiply, which - reduced,and the + adds. This is of course important to realize that to change the value of the variable in theprogram was somewhat important to use the equal sign. In some languages, the equal sign comparesthe value of the values of the left and right, but in C + + == used for the task. The equal sign is still veryuseful. This sets the left input to the same sign, which should be one, and only one, variable equal to thevalue on the right side of the equal sign. Operators that perform mathematical functions should be usedin the right side of the equal sign in order to assign the result to a variable on the left side. a = 4 * 6; // (Note use of comments and of semicolon) a is 24 a = a + 5; // a equals the original value of a with five added to it a == 5 // Does NOT assign five to a. Rather, it checks to see if a equals 5.Other forms of the same, ==, not a way to assign values to variables. Instead, it checks to see whetherthe variables are the same. This is useful in other areas of the C + +, for example, you will often use == inconstructs such as conditional statements and loops. You can probably guess how <dan> function. Theyare larger than and less than operators. a < 5 // Checks to see if a is less than five a > 5 // Checks to see if a is greater than five a == 5 // Checks to see if a equals five, for good measureComparing the variables are not really useful until you have several ways to use it
  6. 6. Tutorial The basics of C++ Lesson 1 Special Thanx’s To : God Allah My Family Special Thanx’s to My Team : Prabujoyoboyo Loiz Xempaxping Thanx’s to Whitehat ./Blacknote Cancer Linuxer46 Shamus Cybermuttaqin See u in Lesson 2 Basic Of c++ (I Hope I can write again)

×