home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / info / c_tutorg / intro.txt < prev    next >
Encoding:
Text File  |  1992-05-22  |  11.0 KB  |  228 lines

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