Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    cpp
  » Borland C++ free Compiler #2
      by revolution
 Page 1 of 1 
   

(Login to remove green text ads)
Here is the second of 2 articles i got from Samc. Hope it helps get you on your way.

Borland C++ Free compiler: Tutorial #2 - Doing some interaction

Required Tools:

Borland C++ command line tools
NotePad (Text Editor)

Required Platform:

* Windows 9x
* Windows XP
* Windows 2000


Tested Platforms:

* Windows 2000
* Windows XP

The first tutorial covered the installation and limited use of the Borland C++ compiler. The first program you ever wrote for the compiler looks like this:

Code:
#include <iostream.h> int main() { cout<<"Hello World! I am learning to code with the help of Borland"; }
Let us take this example just one step further and this time let us include some way of asking the user for input, and then *echoing* this input back to the user in some sort of tangible expression. For the sake of simplicity, let us take the statement from the previous piece of code and change it so that it now reads "Hello World! *Some Name* is learning to code with the help of Borland". In order to do this I am going to introduce one more command from the iostream library and it is called "cin".
Now the introduction of "cout" in the last lesson might be too overwhelming but try and stick with me as I explain the use and definition of "cin". Here is a definiton of cin and cout.

* The streams are declared in the header file iostream.h.


* The streams cout, cin and cerr are in fact `objects' of a given class (more on classes later) which processes the input and output of a program. Note that the terminology `object' means here: the set of data and functions which define the item in question.


* The stream cin reads data and copies the information to variables (e.g., ival in the above example) using the right-shift operator >>. We will describe later how operators in C++ can perform quite other actions than what they are defined to do by the language grammar, such as is the case here.


* The operators which manipulate cin, cout and cerr (which are >> and <<) also manipulate variables of different types. In the above example cout << ival stands for the printing of an integer value. The actions of the operators therefore depend on the type of supplied variables.

For now, ignore the cerr statement, we'll go into that later. For now let us go into the use of "cin". Take the next code segment and see how the use of "cin" and "cout" helps add some interactivity to your applications.

Code:
#include <iostream> using namespace std; int main() { char* FirstName; cout<<"Please enter your first name: "; cin>>FirstName; cout<<"Hello World! "
Go ahead and save this as second.cpp and then compile and link the program as you did in the previous tutorial, but this time sub in the file name second.cpp. After it compiles go ahead and run the program by typing in the command line second {enter} . The first thing that will come up is a prompt asking you to enter your first name. Enter your first name and hit {Enter}. After doing that a second statement that will come up this time with your first name. Congratulations you have now added some interactivity to your applications.

You may have noticed something that wasn't in the last code release and that is the char* designation. What does it mean you ask? Well sit back grasshopper and I'll explain, or if you don't want to hear about, get the heck out of my temple. Ah, but master, you say I am not here to learn Kung Fu, we'll shut the hell up because you are, this is the style called Compressing bits. Coding just like any physical art is also a state of mind. To become a coder you have to have a single yet deterministic state of mind. You must be focused in your endeavors. But enough side tracking let us continue with the lesson.
Oh yeah I left off on the explanation of char*, for now I'm going to ask you to go on a little faith and just believe that it is a designation, for now, that signifies a link of characters. The char designation in C++ signifies 1 byte. What is one byte you ask? One byte is equal to 8 bits. A bit is the atomic structure of a computer it can have only 2 values 0 or 1, or on and off. The only way a computer runs, everything you see is only a visible reputation of on and off, of 0 and 1. Have I drilled it in your head yet? The computer is just a bunch of 1's and 0's, nothing more nothing less. It can't be. So how does it do all this math and hold characters you ask? By representing everything with 1's and 0's. The letter 'A' is represented in the ASCII table by the decimal number 65, again, a number. This simple data conversion can be abstracted to anything you see represented on your computer. So what is the total number of numbers that one byte can represent? Well, that number would be 2^8 = 256. Only 256? How can the computer handle higher numbers? By increasing the number of bytes it handles by doubling the number of bytes you increase the number that can be handled exponentially. That is why the jump from 16 to 32 in computer parlance was so dramatic and beneficial. You go from only being able to access 64K of memory to now being able to access 4GB of memory. I know I'm probably going a little ahead of myself for the novice, but I find computer's so interesting and you'll start to discover these facts on your own.




 
 Page 1 of 1 
   

Rate This Article
1 2 3 4 5 6 7 8 9 10





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle