home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / tutorial / cpptutor / text / intro.txt < prev    next >
Encoding:
Text File  |  1994-05-15  |  10.9 KB  |  232 lines

  1.  
  2.  
  3.  
  4.                                                      Introduction
  5.                                                       WHAT IS C++
  6.  
  7. THE ORIGIN OF C++
  8. -----------------------------------------------------------------
  9. The C programming language was developed at AT&T for the purpose 
  10. of writing the operating system for the PDP-11 series of 
  11. computers which ultimately became the unix operating system.  
  12. C was developed with the primary goal of operating efficiency.  
  13. Bjarne Stroustrup, also of AT&T, developed C++ in order to add 
  14. object oriented constructs to the C language.  Because object 
  15. oriented technology was new at the time and all existing 
  16. implementations of object oriented languages were very slow and 
  17. inefficient, the primary goal of C++ was to maintain the 
  18. efficiency of C.
  19.  
  20. C++ can be viewed as a traditional procedural language with some 
  21. additional constructs.  Beginning with C, some constructs are 
  22. added for object oriented programming and some for improved 
  23. procedural syntax.  A well written C++ program will reflect 
  24. elements of both object oriented programming style and classic 
  25. procedural programming.  C++ is actually an extendible language 
  26. since we can define new types in such a way that they act just 
  27. like the predefined types which are part of the standard 
  28. language.  C++ is designed for large scale software development.
  29.  
  30.  
  31. HOW TO GET STARTED IN C++
  32. -----------------------------------------------------------------
  33. The C programming language was originally defined by the classic 
  34. text authored by Kernigan and Ritchie, "The C Programming 
  35. language", and was the standard used by all C programmers until a 
  36. few years ago.  The ANSI standard for C was finally approved in 
  37. December of 1989 and has become the official standard for 
  38. programming in C.  The ANSI standard adds many things to the 
  39. language which were not a part of the Kernigan and Ritchie 
  40. definition, and changes a few.  The two definitions are not 
  41. absolutely compatible and some experienced C programmers may not 
  42. have studied the newer constructs added to the language by the 
  43. ANSI-C standard.
  44.  
  45. This tutorial will assume a thorough knowledge of the C 
  46. programming language and little time will be spent on the 
  47. fundamental aspects of the language.  However, as a aid to those 
  48. programmers that have learned the dialect of C as defined by 
  49. Kernigan & Ritchie, some sections will be devoted to explaining 
  50. the newer additions included in the ANSI-C standard.  As the 
  51. ANSI-C standard was in development, many of the newer constructs 
  52. from C++ were included as parts of C itself, so even though C++ 
  53. is a derivation and extension of C, it would be fair to say that 
  54. ANSI-C has some of its roots in C++.  An example is prototyping 
  55. which was developed for C++ and later added to C.
  56.  
  57.                                                          Page I-1
  58.  
  59.                                        Introduction - What is C++
  60.  
  61. The best way to learn C++ is by using it.  Almost any valid C 
  62. program is also a valid C++ program and, in fact, the addition 
  63. of about 12 keywords is the only reason that some C programs will 
  64. not compile and execute as a C++ program.  There are a few other 
  65. subtle differences, but we will save the discussion of them until 
  66. later.  Since this is true, the best way to learn C++ is to 
  67. simply add to your present knowledge and use a few new constructs 
  68. as you need them for each new project.  It would be a tremendous 
  69. mistake to try to use all of the new constructs in your first C++ 
  70. program.  You would probably end up with an incomprehensive 
  71. mixture of code that would be more inefficient than the same 
  72. program written purely in C.  It would be far better to add a few 
  73. new constructs to your toolkit occasionally, and use them as 
  74. needed while you gain experience with their use.
  75.  
  76. As an illustration of the portability of C to C++, all of the 
  77. example programs included in the Coronado Enterprises C tutorial 
  78. compile and execute correctly when compiled as C++ programs with 
  79. no changes.  None of the C++ programs will compile and execute 
  80. correctly with any C compiler however, if for no other reason 
  81. than the use of the new style of C++ comments.
  82.  
  83.  
  84. HOW TO USE THIS TUTORIAL
  85. -----------------------------------------------------------------
  86. This tutorial is best used while sitting in front of your 
  87. computer.  It is designed to help you gain experience with your 
  88. own C++ compiler in addition to teaching you the proper use of 
  89. C++.  Display an example program on the monitor, using whatever 
  90. text editor you usually use, and read the accompanying text 
  91. which will describe each new construct introduced in the example 
  92. program.  After you study the program, and understand the new 
  93. constructs, compile and execute the program with your C++ 
  94. compiler.
  95.  
  96. After you successfully compile and execute the example program, 
  97. introduce a few errors into the program to see what kind of error 
  98. messages are issued.  If you have done much programming, you will 
  99. not be surprised if your compiler gives you an error message that 
  100. seems to have nothing to do with the error introduced.  This is 
  101. because error message analysis is a very difficult problem with 
  102. any modern programming language.  The most important result of 
  103. these error introduction exercises is the experience you will 
  104. gain using your compiler and understanding its nuances.  You 
  105. should then attempt to extend the program using the techniques 
  106. introduced with the program to gain experience.
  107.  
  108. The way this tutorial is written, you will not find it necessary 
  109. to compile and execute every program.  At the end of each 
  110. example program, listed in comments, you will find the result of 
  111. execution of that program.  Some of the constructs are simple 
  112. and easy for you to understand, so you may choose to ignore 
  113. compilation and execution of that example program, depending 
  114.  
  115.                                                          Page I-2
  116.  
  117.                                        Introduction - What is C++
  118.  
  119. upon the result of execution to give you the output.  Some 
  120. students have used these results of execution to study several 
  121. chapters of this tutorial on an airplane by referring to a 
  122. hardcopy of the example programs.
  123.  
  124. In the text of this tutorial, keywords, variable names, and 
  125. function names will be written in bold type as an aid when you 
  126. are studying the example programs.
  127.  
  128.  
  129. DIFFERENT C++ IMPLEMENTATIONS
  130. -----------------------------------------------------------------
  131. There are primarily two standards for naming C++ files, one using 
  132. the extension CPP and the other using the extension CXX.  All 
  133. files in this tutorial use the CPP extension for naming files.  
  134. If your compiler requires the CXX extension it will be up to you 
  135. to rename the files.  When C++ was in its infancy, header files 
  136. generally used the extension .HPP, but there is a definite trend 
  137. to use .H for all header files.  For that reason all header files 
  138. in this tutorial will use that convention.
  139.  
  140. Even though we have tried to use the most generic form of all 
  141. constructs, it is possible that some constructs will not actually 
  142. compile and run with some C++ compilers.  As we find new 
  143. implementations of C++, and acquire copies of them, we will 
  144. compile and execute all files in an attempt to make all example 
  145. programs as universal as possible.
  146.  
  147. The C++ language is very new and is changing rapidly.  The 
  148. developer of the language, AT&T, has changed the formal 
  149. definition several times in the last few years and the compiler 
  150. writers are staying busy trying to keep up with them.  It would 
  151. be best for you to search the more popular programming magazines 
  152. for evaluations and comparisons of compilers.  New C++ 
  153. implementations are being introduced at such a rapid rate, that 
  154. we cannot make a compiler recommendation here.
  155.  
  156. A committee is currently meeting to produce an ANSI-C++ standard, 
  157. but the standard is not expected to be available for general use 
  158. until sometime in 1996.  Until then we must expect a few changes 
  159. to the language.
  160.  
  161.  
  162. PRINTING THE EXAMPLE PROGRAMS
  163. -----------------------------------------------------------------
  164. Some students prefer to work from a hardcopy of the example 
  165. programs.  If you desire to print out the example programs, there 
  166. is a batch file on the distribution disk to help you do this.  
  167. Make the distribution disk the default drive and type PRINTALL at 
  168. the user prompt.  The system will print out about 140 pages of 
  169. C++ programs, all of the example programs in this tutorial.
  170.  
  171.  
  172.  
  173.                                                          Page I-3
  174.  
  175.                                        Introduction - What is C++
  176.  
  177. The PRINTALL batch file calls the program named LIST.EXE once 
  178. for each example program on the distribution disk.
  179.  
  180.  
  181. PROGRAMMING EXERCISES
  182. -----------------------------------------------------------------
  183. There are programming exercises given at the end of each chapter 
  184. to enable you to try a few of the constructs given in the 
  185. chapter.  These are for your benefit and you will benefit greatly 
  186. if you attempt to solve each programming problem.  If you merely 
  187. read this entire tutorial, you will have a good working knowledge 
  188. of C++, but you will only become a C++ programmer if you write 
  189. C++ programs.  The programming exercises are given as suggestions 
  190. to get you started programming.
  191.  
  192. An answer for each programming exercise is given in the ANSWERS 
  193. directory on the distribution disk.  The answers are all given 
  194. in compilable C++ source files named in the format CHnn_m.CPP, 
  195. where nn is the chapter number and m is the exercise number.  If 
  196. more than one answer is required, an A, B, or C, is included 
  197. following the exercise number.
  198.  
  199.  
  200. RECOMMENDED ADDITIONAL READING
  201. -----------------------------------------------------------------
  202.  
  203. Brad Cox.  "Object Oriented Programming, An Evolutionary 
  204.      Approach".  Addison-Wesley, 1986.  This book is excellent 
  205.      for a study of object oriented programming and what it is, 
  206.      but since it is based on Objective-C, it covers nothing of 
  207.      the C++ language or how to use it.
  208.  
  209. Margaret Ellis & Bjarne Stroustrup. "The Annotated C++ Reference 
  210.      Manual".  Addison-Wesley, 1990.  This is the base document 
  211.      for the ANSI-C++ standard.  Even though it is the definitive 
  212.      book on C++, it would be difficult for a beginner to learn 
  213.      the language from this book alone.
  214.  
  215. Scott Meyers.  "Effective C++, 50 Specific Ways to Improve Your 
  216.      Programs and Designs".  Addison-Wesley, 1992.  This book 
  217.      is excellent for the advanced C++ programmer, but it is 
  218.      definitely not for the beginner.
  219.  
  220. Note that the C++ culture is in rapid change and by the time you 
  221. read this, there will be additional well written texts available 
  222. as aids to your learning the syntax and proper use of the C++ 
  223. programming language.
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.                                                          Page I-4
  232.