Copyright © 2000 SOLDIERX.COM and Freakout@soldierx.com *BTW if you have any questions or comments about anything within this phile, please contact me.* Index: X- introduction 2- Basic Programming, Using a. #include b. iostream.h c. cout, the power to write to the screen d. cin, the power to handle user-input ----- X- Introduction C++ is, as most of you might know, the update or "Better Version" of C. It was created by Bjarne Stroustrup. He took C, and extended it, to make it more powerful, flexible and to provide features needed to facilitate OOP(Object-Oriented-Programming). OOP mainly defines the three main added features: Encapsulation, Inheritance (and reuse), and Polymorphism. I will define and explain these terms later in the text. What you must remember is that, it is true that C++ is a superset of C and that all C programs are legal C++ programs, the leap between C and C++ is MAJOR. Many C++ programmers, including Strousup, say that it is not only unneccesary to know C before learning C++, but it might even be a disadvantage, because you will find that you need to unlearn alot of things you knew, and learn new ways of solving programming problems. To first start off i will shows you a graphique that you must always remember, and then we can start the thrill. Graphic 1.1 - The Steps In The Developpement Of A C++ Program. ----- Start | | ----> Edit Source Code | | | | | Compile | | | | ---Yes-Compile errors? | | | No | | | Link | | | | -----Yes-Link errors? | | | No | | | Run Program | | | | ---Yes-Run-Time error? | No | DONE! ----- ***** 2a) C++ is a compiled language, therefore a compiler is used. But when you push the compile button, something goes throughout the code before the actual compiler, the preprocessor, wich takes every statement starting with a pound(#) and includes the code from the files youve asked it to include. ie: In chapter 1, you saw this at the beggining of Listing 1.1, "#include ", this tells the preprocessor to include the code from the "iostream.h" file at the beggining(or where ever you put the include statement) of the code. ***** 2b) iostream.h could be defined as a basic, 16 bit, ms-dos window. As you can imagine, this as basic as C++ gets, eventually, if you use visual C++, you will be able to use the MFC wizard to create windows and interfaces, btu for now lets stick with this. iostream still permits some kind of "interaction" between the program and the user. In the next section, we will discuss a couple of them. ***** 2c) cout is a command that can only be used under iostream, and this is why it is not a keyword. What cout permits you to do is to write text to the screen, wich can be useful if you want to display information(about the computer for example Listing 1.1) or ask the user a question and expect an answer(2d).the syntax for this is to write cout followed by two 'less-than' operators(<<), folowed by a quote mark, then the text, and a closing quote mark and an ending semi-colon. ie: cout << "Hello World"; This is the most basic use of cout. cout can also be used to display the value of a variable, or constant. ie: 1: int myInt = 5; 2: cout << "myInt is equal to: " << myInt; These are the two most common uses of cout. ***** 2d) cin is a command wich enables the user to enter a value and store that value in a given variable. The syntaxe of cin is writing cin, folowed by two 'more-than' operators(>>), followed by the name of the variable in witch the input is going to be stored in, and ending with a semi-colon. ie: 1: int yourAge; //Definition of yourAge 2: cout << "How old are you? "; 3: cin >> yourAge; 4: cout << "Your are " << yourAge << " years old!"; ***** ***** 2a) C++ is a compiled language, therefore a compiler is used. But when you push the compile button, something goes throughout the code before the actual compiler, the preprocessor, wich takes every statement starting with a pound(#) and includes the code from the files youve asked it to include. ie: In chapter 1, you saw this at the beggining of Listing 1.1, "#include ", this tells the preprocessor to include the code from the "iostream.h" file at the beggining(or where ever you put the include statement) of the code. ***** 2b) iostream.h could be defined as a basic, 16 bit, ms-dos window. As you can imagine, this as basic as C++ gets, eventually, if you use visual C++, you will be able to use the MFC wizard to create windows and interfaces, btu for now lets stick with this. iostream still permits some kind of "interaction" between the program and the user. In the next section, we will discuss a couple of them. ***** 2c) cout is a command that can only be used under iostream, and this is why it is not a keyword. What cout permits you to do is to write text to the screen, wich can be useful if you want to display information(about the computer for example Listing 1.1) or ask the user a question and expect an answer(2d).the syntax for this is to write cout followed by two 'less-than' operators(<<), folowed by a quote mark, then the text, and a closing quote mark and an ending semi-colon. ie: cout << "Hello World"; This is the most basic use of cout. cout can also be used to display the value of a variable, or constant. ie: 1: int myInt = 5; 2: cout << "myInt is equal to: " << myInt; These are the two most common uses of cout. ***** 2d) cin is a command wich enables the user to enter a value and store that value in a given variable. The syntaxe of cin is writing cin, folowed by two 'more-than' operators(>>), followed by the name of the variable in witch the input is going to be stored in, and ending with a semi-colon. ie: 1: int yourAge; //Definition of yourAge 2: cout << "How old are you? "; 3: cin >> yourAge; 4: cout << "Your are " << yourAge << " years old!"; ***** *****