C - Program - 2e - Chapter01.pdf
(
436 KB
)
Pobierz
C++ Overview and
Software Development
1
CHAPTER OBJECTIVES
Introduce this text to the reader.
KEY TERMS AND CONCEPTS
ANSI/ISO standard
C++ class
compiler
cross-platform code libraries
functions
linker
object
object-oriented program
open source software
operators
pointers
portable language
references
software development steps
software development skill set
source code
standardized libraries
structured programming
top-down
Visual C++ 2005
Present the history and an overview of the C and C++
languages.
Illustrate the concept of object-oriented programming.
Compare structured program design and object-oriented pro-
gram design.
Help the programmer begin thinking about all aspects of build-
ing software.
Welcome!
Y
ou are about to embark on a wonderful journey. Learning to write computer
programs with the C++ programming language will bring you a wonderful
sense of accomplishment. When you become an efficient C++ developer,
technical career doors will open for you and many programming paths will be-
come available. C++ is a cornerstone in today’s programming environment.
Whether you are writing controllers for robots, implementing elegant user inter-
faces, building high-speed graphics for games, web services, interfacing into
databases, or learning the C++, C, or Java programming language for Internet
and Web application, C++ is where it all starts.
But beware! Programming—in any language—is not for everyone. In the
journey there are often speed bumps, potholes, clear-air turbulence, and fog. A
successful programmer uses many skills, including logical thinking and trou-
bleshooting. At times, success seems to depend on just plain luck. If you are al-
ready familiar with another programming language and are now learning C++,
you are aware of all these factors. If C++ is your first programming language, you
will find these pearls of wisdom to be true soon enough.
Software Developer Skill Set
Aside from learning C++, there are several other skills a student must learn to be
a successful software developer and to contribute fully to a development or
maintenance job. A few of these skills are listed in Table 1-1.
A software developer must also be a student of other fields. For any software
job, the developer must understand the underlying concepts of the software while
also working closely with non-software experts on a project. For example, to write
an inventory control and tracking system for an international company, the soft-
ware team must have a good idea of all aspects of the business. If you are writing a
program to handle bad debt for a company, you will need to know the laws and
company policies concerning debt. Software developers are not expected to be
experts in everything, but they should expect to keep learning new things long
after school is out.
3
4
Chapter 1
❚
C++ Overview and Software Development
❚
TABLE 1-1
Software Developer’s Skill Set
Skill
Where It Is Used
Documentation
All software needs to be documented well and should be easy to read. Docu-
mentation is written into the source code as comments and describes what the
program is doing, the logic that is used, how the user interacts with the program,
and any special methods used. You should write your software assuming that it will
be used for years to come. Can someone read your software and know what you
were doing?
Communication
Software developers must be able to communicate with team members, cus-
tomers, and end users. Software projects often go through several design stages.
Formal design and requirements documents are written before any code is built.
Quick learners
Software developers often work with experts in other fields who need to have soft-
ware written. The software developer must gain some level of understanding of
the new concepts before he or she is able to build the software. Often program-
ming requires the use of mathematics. The programmer should be familiar with
mathematical concepts.
Debugging
It is vitally important to learn debugging skills when developing software. Debug-
gers aid in finding problems in software.
Troubleshooting
Debugging “broken” code is common. Good analysis/troubleshooting skills are in-
valuable.
Testing
Always think about how to test your software. Are you covering all the cases? Test-
ing is one of the most important aspects of software development, but it is the
most often neglected.
A Few Details Concerning This Text
Concepts, Order of Presentation
Chapters 2 through 6 present the nuts
and bolts of the C/C++ language including an introduction to object-oriented
concepts in Chapter 1. In Chapter 2, we begin using classes provided in the C++
standard libraries and learn how to get data in and out of a program. We write
short programs that use different types of data, practice writing math statements.
In Chapter 3 we need to be able to have our code perform logical and condition-
al statements and loops. Chapter 4 teaches us how to separate our code into indi-
vidual modules known as functions. We explore the various ways C++ lets us
write functions, including overloading, and default parameter lists. In Chapter 5,
we expand our discussion of functions by presenting an introduction to refer-
ences and pointers. Pointers and references are handy little devices found every-
where in C++ code. Chapter 6 introduces the concept of an array—a list or
grouping of data variables and, finally, Chapters 7 and 8 provide the tools for you
to write your own classes.
Although we begin writing our own classes and using our objects in Chapter 7,
we begin using several C++ classes right from the start! Chapter 1 introduces an
easy way to understand classes and objects, and then we use the C++ string class in
Chapter 2. In Chapter 3, we begin using the C++ vector class. These classes give us
5
Johnston’s Rules for Programmers
the ability to build interesting C++ programs right away. By the time we reach
Chapter 7, we are familiar with classes. The mechanics of writing object-oriented
software are based on the concepts we’ve been studying in the first several chap-
ters. In the latter chapters, we write several programs using many of the classes we
write as well as the classes C++ gives us.
Accompanying CD with This Book
One compact disc is included with this
book. On it is a copy of the
Microsoft Visual C++ 2005 Express Edition
, which
may be installed on a personal computer and used to build and run C++ pro-
grams. This software includes the Visual Studio C++ development tools as well as
an excellent C++ Language Reference. Appendix A, “Getting Started with Visual
C++ 2005 Express Edition,” covers the system requirements, software installation,
all of the necessary steps to create and run a simple project, and how to access the
help feature. (The debugger tool is described in Appendix I, “Microsoft Visual
C++ 2005 Express Ediiton Debugger.”)
Microsoft Visual C++
2005
Microsoft’s C++ de-
velopment environ-
ment
Program Source Code
The source code for all the program examples in this
text are available on the text's website. These examples are organized into
Microsoft Visual C++ 2005 project folders, and each is located in its respective
chapter folder. The project folders should be copied onto the reader’s hard drive.
The projects may be opened using Visual C++ 2005, or the source files can be
copied and compiled in other C++ environments.
ISO C++, Not Visual C++
The programs included in this text are written
according to the International Standards Organization (ISO) C++ standards.
You may run (or modify and run) these programs on any computer system that
has ISO standard C++ software. The Microsoft Visual C++ 2005 software is
included so that you may load it on your personal computer at home and prac-
tice writing C++ programs. One appendix covers how to install and get started
with this software. Another appendix covers how to use the debugger in Visual
C++ 2005. We will be creating and running our programs by using the Console
Application.
Program Examples, Output, Errors, and Warnings
This book also includes
a wide variety of program examples—short five-liners to multifile, multi-object,
medium-size programs. Some are complete programs, and the reader is welcome to
use them as starting points for further expansion, such as accessing the computer sys-
tem time as a seed for the random number generator. You will find many examples of
code that are written incorrectly and hence do not build and execute. (Sometimes
seeing the wrong way is more informative than seeing the right way.) We illustrate the
wrong code along with the software error and/or warning messages.
Johnston’s Rules for Programmers
As a team member of a commercial firm engaged in building and developing
software, I am acquainted with technology skills needed in the marketplace. And
as a member of the faculty of a community college, I have learned ways to help
students master these skills. Teaching beginning C and C++ students for many
6
Chapter 1
❚
C++ Overview and Software Development
years has brought an understanding of the trials and tribulations that the new
C++ student encounters.
Drafts of the first edition of this text were used for four semesters by beginning
and advanced C++ programming students. This second edition revision also used C++
programming students as test-drivers, who worked through new ideas, concepts, and
programs. Past students also volunteered to help with this second edition. My begin-
ning C++ students are excellent test subjects and proved to be adept at using C++
classes in their second program. They followed the introductory examples and discus-
sions here, and were soon showing that they were apt object users.
While test-driving the material in this book, these first semester program-
ming students were quite open about what they needed in the text to aid them in
learning to program in C++. They told me what they liked and did not like, and
what was helpful and what was confusing. Past students who are now working as
C/C++ programmers or are continuing their education have provided even more
suggestions and advice.
A common theme for all these students is their belief in the set of rules we
develop at the beginning of each programming course. We refer to them as either
the “Nine Rules for Programmers” or the “Johnston Rules for Programmers.”
They are:
Keep your cool (don’t get mad).
Work when you are rested (don’t program when you are tired).
KISS your software (keep it simple, sweetie).
Give help/get help.
Study and know the rules for the language (syntax).
Learn the development environment and tools (we’ll concentrate on
Visual C++).
Understand the problem you are trying to solve.
Build and test your software in steps.
Save early/save often (back up your computer programming files often).
One more rule might emphasize, “Patience, patience, patience.” You can apply
this maxim immediately, as several topics need to be covered before we reach the
core of the C++ language. Two of my students like to say that there is no crying in
baseball, but they’re not so sure about programming! It is important to follow the
above rules for programming so you’re not crying at your computer. Read on,
have fun! Principles that now seem disjointed will come together as you practice,
practice, practice your programming.
1.1
What Is C and What Is C++?
The C language was developed originally by Bell Laboratories and was stan-
dardized by the
American National Standards Institute (ANSI)
in 1989. In
1990, the
International Standards Organization (ISO)
adopted the ANSI stan-
dard. You can think of the ISO Standard as the governing laws for C/C++. These
ISO Standards dictate the correct form of C/C++ statements, and how aspects of
the language must work.
ANSI
American National
Standards Institute
ISO
International Stan-
dards Organization
Plik z chomika:
Januszek66
Inne pliki z tego folderu:
Back Seat_ A Mumbai Tale - Aditya Kripalani.mobi
(755 KB)
Brief Wondrous Life of Oscar Wao, The - Junot Diaz.opf
(3 KB)
Don't Make Me Think, Revisited_ - Steve Krug.mobi
(9256 KB)
M. T. Anderson - Norumbegan 03 - The Empire of Gut and Bone # (v5.0).epub
(2209 KB)
M. T. Anderson - Norumbegan 02 - The Suburb Beyond the Stars # (v5.0).epub
(2105 KB)
Inne foldery tego chomika:
Dokumenty
Galeria
LUDLUM ROBERT
Midi - Kar
Mszał Rzymski PL
Zgłoś jeśli
naruszono regulamin