?? c++ tutorial by clayman.html
字號:
<html>
<head>
<title>C++ Tutorial I By ClayMan</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
<style type="text/css">
<!--
a:active { text-decoration: none}
a:hover { text-decoration: underline; color: #999999}
a:link { text-decoration: none}
a:visited { text-decoration: none}
-->
</style>
</head>
<body bgcolor="#000000" text="#CCCCCC" link="#99CCFF" vlink="#CCCCFF" alink="#CCFF99" leftmargin="20" topmargin="10" marginwidth="0" marginheight="0">
<center>
<p align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b><br>
</b><font face="Book Antiqua" color="#FFFFFF" size="5">C++ Tutorial | By Clayman</font></font></p>
<p align="left"><font color="#FFFFFF" size="2"><br>
<br>
</font></p>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="1" color="#999999">-----------------------------------------<br>
</font><font face="Georgia, Times New Roman, Times, serif" size="2" color="#FFFFFF"><font face="Arial, Helvetica, sans-serif"><b>TABLE
OF CONTENTS<br>
</b></font><font size="2" face="Arial, Helvetica, sans-serif"><b> </b></font><font size="4"><font color="#999999" size="1" face="Arial, Helvetica, sans-serif">-----------------------------------------<br>
</font> </font></font></p>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="2">1. <a href="#introduction">Introduction</a>
</font></p>
<div align="left">
<ul>
<li><font face="Arial, Helvetica, sans-serif" size="2">1.1. Why do people
program? </font>
<li><font face="Arial, Helvetica, sans-serif" size="2">1.2. What is C++
& OOP? </font>
<li><font face="Arial, Helvetica, sans-serif" size="2">1.3. What do I need
to program?<br>
</font></li>
</ul>
</div>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="2">2. <a href="#yourfirstprogram">Your
first program</a> </font>
<div align="left">
<ul>
<li><font face="Arial, Helvetica, sans-serif" size="2">2.1. Running a C++
program </font>
<li><font face="Arial, Helvetica, sans-serif" size="2">2.2. C++ program
structure </font>
<li><font face="Arial, Helvetica, sans-serif" size="2">2.3. Comments </font>
<li><font face="Arial, Helvetica, sans-serif" size="2">2.4. Libraries </font>
<li><font face="Arial, Helvetica, sans-serif" size="2">2.5. Functions </font>
<li><font face="Arial, Helvetica, sans-serif" size="2">2.6. Streams </font>
<li><font face="Arial, Helvetica, sans-serif" size="2">2.7. Return </font></li>
</ul>
</div>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="2"><br>
3. <a href="#datandnumsystems">Number Systems</a> </font>
<div align="left">
<ul>
<li><font face="Arial, Helvetica, sans-serif" size="2">3.1. Decimals </font>
<li><font face="Arial, Helvetica, sans-serif" size="2">3.2. Binaries </font>
<li><font face="Arial, Helvetica, sans-serif" size="2">3.3. Hexadecimals
</font></li>
</ul>
</div>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="2"><br>
4. <a href="#exercises">Exercises</a> </font>
<div align="left">
<ul>
<li><font face="Arial, Helvetica, sans-serif" size="2">4.1. EX 1 : Running
</font>
<li><font face="Arial, Helvetica, sans-serif" size="2">4.2. EX 2 : Typing
</font>
<li><font face="Arial, Helvetica, sans-serif" size="2">4.3. EX 3 : Converting
</font></li>
</ul>
</div>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="2"><br>
5. <a href="#whatnow">What now?</a> </font>
<div align="left">
<ul>
<li><font face="Arial, Helvetica, sans-serif" size="2">5.1. Good programming
sites </font>
<li><font face="Arial, Helvetica, sans-serif" size="2">5.2. Good books on
C++<br>
</font></li>
</ul>
</div>
<hr noshade size="1" align="left">
<p align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="-0"><br>
<font color="#FFFFFF" size="2"><a
name=introduction><strong>1.INTRODUCTION</strong></a><br>
<br>
<strong>1.1. Why do People Program?</strong><br>
</font> <br>
<font face="Arial, Helvetica, sans-serif" size="2"> Each
person can have his own reason for programming but I can tell you that programming
is one of the best ways to gain a deep understanding of computers and computer
technology. Learning to program makes you understand why computers and computer
programs work the way they do. It also puts some sense into you about how
hard it is to create software.<br>
</font> <br>
<strong><font color="#FFFFFF" size="2">1.2. What is C++ & OOP?</font></strong><font color="#FFFFFF" size="2"><br>
</font> <font size="2"> <br>
<font face="Arial, Helvetica, sans-serif"> C++ is an extended
version C. C was developed at Bell Labs, in 1978. The purpose was to create
a simple language (simpler than assembly & machine code...) which can
be used on a variety of platforms. Later in the early 1980's C was extended
to C++ to create an object-oriented language. O(bject) O(riented) P(rogramming)
is a style of programming in which programs are made using Classes. A class
id code in a file separate from the main program - more on classes later.
OOP in general & C++ in particular made it possible to handle the complexity
of graphical environments. (like windows, macintosh..)<br>
</font> <br>
<strong><font color="#FFFFFF">1.3. What do I need to program?</font></strong><font color="#FFFFFF"><br>
</font></font> <font size="2"><br>
<font face="Arial, Helvetica, sans-serif"> Well, you need
a computer and a compiler to start with but you also need some curiosity and
a lot of time. I guess(!?) you have a computer. You can find different compilers
for free from <a href="http://www.borland.com/">borlands</a> website (Check
5.1). If you have the curiosity but lack in time read stuff at lessons and
detention hours. Read whenever you find time. Having a good C++ book (check
5.2) also helps a lot. (and is much better for your eyes) One thing not to
forget: No tutorial, book, program or course makes you a programmer in 5 days.
YOU make yourself a programmer. NO compiler writes an entire program for you,
YOU write the program.<br>
</font> <br>
</font><font color="#FFFFFF" size="2"><a name=yourfirstprogram><strong>2.
YOUR FIRST PROGRAM</strong></a><br>
<br>
<strong>2.1. Running a C++ Program</strong><br>
</font><font size="2"> <br>
<font face="Arial, Helvetica, sans-serif"> Read this part
carefully: A C++ program must be compiled and linked before it can be executed,
or run, on the computer. A great lot of compilers do this automatically. So
what is a compiler? A compiler is a program that translates C++ code into
machine language. Machine language is the language consisting of 1s and 0s,
and is the native language of a computer. A typed C++ program is called the
source-code, and the compiled code is called the object code.<br>
<br>
Before the object code can be executed, it must be linked
to other pieces of code (e.g. included libraries) used by the program. The
compiled & linked program is called an executable file. Finally, the program
is executed by the system. It's output is displayed in a window.<br>
</font> <br>
<strong><font color="#FFFFFF">2.2. C++ Program Structure</font></strong><font color="#FFFFFF"><br>
<br>
</font> <font face="Arial, Helvetica, sans-serif"> All C++
progs contain statements (commands) that tell the computer what to do. Here
is an example of a simple C++ program:<br>
</font></font></font></p>
<div align="left">
<table border=0 cellpadding=3 cellspacing=3 width="56%" bgcolor="#26343E">
<tbody>
<tr>
<td width="100%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">/*
Downloaded from code.box.sk<br>
We own you program */<br>
<br>
#include <iostream.h><br>
<br>
int main()<br>
{<br>
cout<<"We own you";
// the first statement<br>
return(0); //
the second statement<br>
}</font></td>
</tr>
</tbody>
</table>
</div>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="2"><br>
Run the program. It should display :<br>
<br>
<font color="#FFFFFF"> We own you<br>
</font> <br>
The structure of a simple C++ program is:<br>
</font></p>
<div align="left">
<table border=0 cellpadding=3 cellspacing=3 width="57%" bgcolor="#26343E">
<tbody>
<tr>
<td width="100%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">/*
Comments : Name, purpose of the program <br>
your name, date, etc. */<br>
<br>
#include <librarynames.h><br>
<br>
int main()<br>
{<br>
statements; // comments<br>
return(0);<br>
}</font></td>
</tr>
</tbody>
</table>
<font face="Arial, Helvetica, sans-serif" size="2"><br>
</font> </div>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="2">Now we will
have a closer look on the structure:<br>
</font><font face="Verdana, Arial, Helvetica, sans-serif" size="2"> <br>
<strong><font color="#FFFFFF">2.3. Comments<br>
</font></strong></font><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<font face="Arial, Helvetica, sans-serif"> Comments are
used to explain the contents of a program for a human reader. The computer
ignores them. The symbols /* and */ are used for the beginning and end of
a comment for multi-line comments. // symbols are also used for commenting.
All characters on a line after the // symbol are considered to be comments
and are ignored. Most newbies think that commenting a program is a waste of
time. They are wrong. Commenting is very important because it makes the code
understandable by other programmers and makes it easier to improve a program
or fix the bugs in it. You'll understand better after trying to decipher a
hundred pages of code you wrote a few months later.<br>
</font> <br>
<strong><font color="#FFFFFF">2.4. Libraries</font></strong><font color="#FFFFFF"><br>
</font> <br>
<font face="Arial, Helvetica, sans-serif">Look at the program above. Following
the opening comment was the line:<br>
</font> <br>
<font color="#FFFFFF"> #include <iostream.h><br>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -