P. 1
C++Programming

C++Programming

Ratings: (0)|Views: 198 |Likes:
Published by kouabri

More info:

Published by: kouabri on Jan 17, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

01/11/2013

pdf

text

original

 
C++ Programming/Print version
From Wikibooks, the open-content textbooks collection
About the book
Foreword
Guide to Readers
The book is organized into different parts, but as this is a work that is always evolving, things may be missing or ust not where they should be, you are free to become a writer and contribute to fix things up...If you are already familiar with programming in other languages you can skip most of the
Getting StartedChapter
(it deals with basic and general programming concepts). You should not skip the
ProgrammingParadigms
introduction, since C++ does have some particulars on that topic that should be useful even if youalready know an OOP language. The
Language Comparisons Section
, providing comparisons for thelanguage(s) you already know, is important for veterans. However if this is your first contact with programmingthen continue on reading, and take in consideration that the
Programming Paradigms
section can be hard todigest if you lack some bases, don't despair, the relevant points will be extended when other concepts areintroduced, that section is provided to give you a mental framework to help you not only to understand C++, butto let you easily adapt to (and from) other languages that share those concepts.
Authors
The following people are authors to this book PanicThere are many other contributors/editors to the book; a verifiable list of all contributions exist as History Logsat Wikibooks (http://en.wikibooks.org/).Acknowledgment is given for using some contents from other works like Programming C
-/- -/-
, Wikipedia, theWikibooks Java Programming and C Programming, C++ Exercises for beginners, C/C++ Reference Web Site(http://www.cppreference.com) , and from Wikisource as from authors such as Scott Wheeler (http://ktown.kde.org/~wheeler/bio.html) , Stephen Ferg (http://www.ferg.org/index.html) and Ivor Horton.Permission is granted to copy, distribute and/or modify this documentunder the terms of the
GNU Free Documentation License
, Version 1.2 or any later version published by the Free Software Foundation; with noInvariant Sections, no Front-Cover Texts, and no Back-Cover Texts. Acopy of the license is included in the section entitled "GNU Free
1 of 330
 
Documentation License."
Getting Started
Introducing C++
C++
(pronounced "see plus plus") is a general-purpose, object-oriented, statically typed, free-form, multi- paradigm programming language supporting procedural programming, data abstraction, and generic programming. During the 1990s, C++ became one of the most popular computer programming languages.
History
Bjarne Stroustrup from Bell Labs was the designer and original implementer of C++ (originally named "C withClasses") during the 1980s as an enhancement to the C programming language. Enhancements started with theaddition of classes, followed by, among many features, virtual functions, operator overloading, multipleinheritance, templates, and exception handling, these and other features are covered in detail along this book.The C++ programming language is a standard recognized by the the ANSI (The American National StandardsInstitute), BSI (The British Standards Institute), DIN (The German national standards organization), several other national standards bodies, and was ratified in 1998 by the ISO (The International Standards Organization) as
 ISO/IEC 14882:1998
, the current version of which is the 2003 version,
 ISO/IEC 14882:2003
.The 1998 C++ Standard consists of two parts: the Core Language and the Standard Library; the latter includesthe Standard Template Library and the Standard C Library (ANSI C 89). Many C++ libraries exist which are not part of the Standard, such as Boost. Also, non-Standard libraries written in C can generally be used by C++ programs.Features introduced in C++ include declarations as statements, function-like casts,
new
/
delete
,
bool
, referencetypes,
const
,
inline
functions, default arguments, function overloading, namespaces, classes (including allclass-related features such as inheritance, member functions, virtual functions, abstract classes, andconstructors), operator overloading, templates, the
::
operator, exception handling, run-time type identification,and more type checking in several cases. Comments starting with two slashes ("
//
") were originally part of BCPL, and was reintroduced in C++. Several features of C++ were later adopted by C, including
const
,
inline
, declarations in
for
loops, and C++-style comments (using the
//
symbol).
C++ source code example
// 'Hello World!' program#include <iostream> intmain(){std::cout<<"Hello World!"<< std::endl;  return 0; }
Traditionally the first program people write in a new language is called "Hello, World." because all it does is printthe words
Hello World
. Hello World Explained offers a detailed explanation of this code; the included sourcecode is to give you an idea of a simple C++ program.
2 of 330
 
Overview
Before you begin your journey to understand how to write programs using C++, it is important to understand afew key concepts that you may encounter. These concepts, while not unique to C++, help in understanding programming in general. Readers who have experience in another programming language may wish to skimthrough or skip this section entirely.There are many different kinds of programs in use today. From the operating system you use that makes sureeverything works as it should, to the video games and music applications you use for fun, programs can fulfillmany different purposes. What all
programs
(also called
software
or 
applications
) have in common is that theyall are made up of a sequence of instructions written in some form of programming language. These instructionstell a computer what to do, and generally how to do it. Programs can contain anything from instructions to solvemath problems or send emails, to how to behave when a video game character is shot in a game. The computer will follow the instructions of a program one instruction at a time from start to finish.
Why learn C++?
Why not? This is the most clarifying approach to the decission to learn anything, learning is always good,selecting what to learn is more important as is how to prioritize tasks. Another side of this problem is that youwill be investing some time in getting a new skill set, you have to consider in what ways will this benefit you.Check your objectives and compare similar projects or see what the programming market is in need. In any casethe more programming languages you know, the better.If you are approaching the learning process only to add another notch under your belt, that is, willing only todedicate enough effort to understand its major quirks and learn something about its dark corners then you should be best served in learning first two other languages, this will clarify what makes C++ special in its approach to programming problems. You should select one imperative language and in this C will probably have a better market value and will have a direct relation to C++ (a good substitute would be ASM) and the second languageshould be an Object Oriented language like Java for the same reasons, as there is a close relation between thetree languages.If you are willing to dedicate a more than passing interest in C++ then you can even learn C++ as your firstlanguage but dedicate some time understanding the different paradigms and why C++ is a multi-paradigmlanguage or how some like to call it a hybrid language.Learning C is not a requirement for understanding C++, but knowing how to use an imperative language is, C++will not make it easy for you to understand and distinguish some of this deeper concepts, since in C++ you arefree to implement solutions with a great range of freedom. Understanding what options to make will become thecornerstone of mastering the language.You should not learn C++ if you are only interested in applying or learning about Object Oriented Programingsince the nomenclature used and some of the approaches C++ takes to the problem will probably increase thedifficulty level in learning and mastering those concepts, if you are truly interested in Object Oriented programming, the best language for that is Smalltalk.As with all languages C++ has a specific scope of application, where it can truly shine, and if we take a quick comparison with the previous mentioned languages, C++ is harder to learn than C and Java but more powerfulthan both. C++ enables you to abstract from the little things you have to deal with in C or other lower levellanguages but will grant you a bigger control and responsibility than Java, but it will not provide the defaultfeatures you can obtain in similar higher level languages. You will have to search and examine several externalimplementations of these features and freely select those that best serve your purposes or you may even have to
3 of 330

Activity (6)

You've already reviewed this. Edit your review.
1 hundred reads
minamjah liked this
BGSorin liked this
BGSorin liked this
Acharya liked this
chandra-calgary liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->