Programming in C++ for Engineering and Science
eBook - ePub

Programming in C++ for Engineering and Science

  1. 744 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Programming in C++ for Engineering and Science

Book details
Book preview
Table of contents
Citations

About This Book

Developed from the author's many years of teaching computing courses, Programming in C++ for Engineering and Science guides students in designing programs to solve real problems encountered in engineering and scientific applications. These problems include radioactive decay, pollution indexes, digital circuits, differential equations, Internet addr

Frequently asked questions

Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes, you can access Programming in C++ for Engineering and Science by Larry Nyhoff in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming Games. We have over one million books available in our catalogue for you to explore.

Information

Publisher
CRC Press
Year
2012
ISBN
9781439884546
Edition
1

CHAPTER 1

Introduction to Computing

CONTENTS

1.1 Computing Systems
1.2 Computer Organization
Exercises
I wish these calculations had been executed by steam.
CHARLES BABBAGE
One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man.
ELBERT HUBBARD
Where a computer like the ENIAC is equipped with 18,000 vacuum tubes and weighs 30 tons, computers in the future may have only 1000 vacuum tubes and weigh only 1-1/2 tons.
POPULAR MECHANICS (MARCH 1949)
640K ought to be enough for anyone.
BILL GATES (1981)
So IBM has equipped all XTs with what it considers to be the minimum gear for a serious personal computer. Now the 10-megabyte disk and the 128K of memory are naturals for a serious machine.
PETER NORTON (1983)
THE MODERN ELECTRONIC COMPUTER is one of the most important products of the twentieth century. It is an essential tool in many areas, including business, industry, government, science, and education; indeed, it has touched nearly every aspect of our lives. The impact of the twentieth-century information revolution brought about by the development of high-speed computing systems has been nearly as widespread as the impact of the nineteenth-century industrial revolution. In this chapter we begin with some background by describing computing systems, their main components, and how information is stored in them.
Early computers were very difficult to program. In fact, programming some of the earliest computers consisted of designing and building circuits to carry out the computations required to solve each new problem. Later, computer instructions could be coded in a language that the machine could understand. But these codes were very cryptic, and programming was therefore very tedious and error prone. Computers would not have gained widespread use if it had not been for the development of high-level programming languages that made it possible to enter instructions using an English-like syntax.
Fortran, C, C++, Java, and Python are some of the languages that are used extensively in engineering and scientific applications. This text will focus on C++ but will also describe some properties of its parent language, C, noting features that these two languages have in common, as well as their differences.

1.1 COMPUTING SYSTEMS

Four important concepts have shaped the history of computing:
1. The mechanization of arithmetic
2. The stored program
3. The graphical user interface
4. The computer network
This section briefly describes a few of the important events and devices that have implemented these concepts. Additional information can be found on the website for this book described in the preface.

1.1.1 Machines to Do Arithmetic

One of the earliest “personal calculators” was the abacus (Figure 1.1a), with movable beads strung on rods to count and to do calculations. Although its exact origin is unknown, the abacus was used by the Chinese perhaps 3000 to 4000 years ago and is still used today throughout Asia. Early merchants used the abacus in trading transactions. The ancient British stone monument Stonehenge (Figure 1.1b), located near Salisbury, England, was built between 1900 and 1600 BC and, evidently, was used to predict the changes of the seasons. In the twelfth century, a Persian teacher of mathematics in Baghdad, Muhammad ibn-Musa al-Khowarizm, developed some of the first step-by-step procedures for doing computations. The word algorithm, used for such procedures, is derived from his name. The English mathematician William Oughtred invented a circular slide rule in the early 1600s, and more modern ones (Figure 1.1c) were used by engineers and scientists through the 1950s and into the 1960s to do rapid approximate computations.
FIGURE 1.1 (a) Abacus. (Image courtesy of the Computer History Museum.) (b) Stonehenge. (c) Slide rule.
In 1642, the young French mathematician Blaise Pascal invented one of the first mechanical adding machines to help his father with calculating taxes. This Pascaline (Figure 1.2a) was a digital calculator because it represented numerical information as discrete digits, as opposed to a graduated scale like that used in analog instruments of measurement such as slide rules and nondigital thermometers. Each digit was represented by a gear that had 10 different positions (a ten-state device) so that it could “count” from 0 through 9 and, upon reaching 10, would reset to 0 and advance the gear in the next column so as to represent the action of “carrying” to the next digit. In 1673, the German mathematician Gottfried Wilhelm von Leibniz invented an improved mechanical calculator (Figure 1.2b) that also used a system of gears and dials to do calculations. However, it was more reliable and accurate than the Pascaline and could perform all four of the basic arithmetic operations of addition, subtraction, multiplication, and division. A number of other mechanical calculators followed that further refined Pascal’s and Leibniz’s designs, and by the end of the nineteenth century, these calculators had become important tools in science, business, and commerce.

1.1.2 The Stored Program Concept

The fundamental idea that distinguishes computers from calculators is the concept of a stored program that controls the computation. A program is a sequence of instructions that the computer follows to solve some problem. An income tax form is a good analogy. Although a calculator can be a useful tool in the process, computing taxes involves much more than arithmetic. To produce the correct result, one must execute the form’s precise sequence of steps of writing numbers down (storage), looking numbers up (retrieval), and computation to produce the correct result.
The stored program concept also gives the computer its amazing versatility. Unlike most other machines, which are engineered to mechanize a single task, a computer can be programmed to perform many different tasks. Although its hardware is designed for a very specific task—the mechanization of arithmetic—computer software programs enable the computer to perform a wide variety of tasks, from navigational control of the space shuttle to word processing to musical composition.
FIGURE 1.2 (a) Pascaline. (b) Leibnitz’s calculator. (Images courtesy of the Computer History Museum.)
The Jacquard loom (Figure 1.3a), invented in 1801 by the Frenchman Joseph Marie Jacquard, is an early example of a stored program automatically controlling a hardware device. Holes punched in metal cards directed the action of this loom: a hole punched in one of the cards would enable its corresponding thread to come through and be incorporated into the weave at a given point in the process; the absence of a hole would exclude an undesired thread. To change to a different weaving pattern, the operator of this loom would simply switch to another set of cards. Jacquard’s loom is thus one of the first examples of a programmable machine, and many later computers would make similar use of punched cards.
FIGURE 1.3 (a) Jacquard Loom. (Image courtesy of the Computer History Museum.) (b) Charles Babbage. (c) Difference Engine.
The English mathematician Charles Babbage (1792–1871) (Figure 1.3b) combined the two fundamental concepts of mechanized calculation and stored program control. In 1822, supported by the British government, he began work on a machine that he called the Difference Engine (Figure 1.3c). Comprised of a system of gears, the Difference Engine was designed to compute polynomials for preparing mathematical tables.
Babbage abandoned this effort and began the design of a much more sophisticated machine that he called his Analytical Engine (Figure 1.4a). It was to have over 50,000 components, and its operation was to be far more versatile and fully automatic, controlled by programs stored on punched cards, an idea based on Jacquard’s earlier work. Although this machine was not built during his lifetime, it is an important part of the history of computing because many of the concepts of its design are used in modern computers. For this reason, Babbage is sometimes called the “Father of Computing.” Ada Augusta (Figure 1.4b), Lord Byron’s daughter, was one of the few people other than Babbage who understood the Analytical Engine’s design. This enabled her to develop “programs” for the machine, and for this reason she is sometimes called “the first programmer.” In the 1980s, the programming language Ada was named in her honor.
FIGURE 1.4 (a) Analytical Engine. (b) Ada Augusta.
During the next 100 years, the major significant event was the invention by Herman Hollerith of an electric tabulating machine (Figure 1.5a) that could tally census statistics stored on punched cards. This was noteworthy because the U.S. Census Bureau feared it would not be possible to complete the 1890 census before the next one was to be taken, but Hollerith’s machine enabled it to be completed in 2-1/2 years. The Hollerith Tabulating Company later merged with other companies to form the International Business Machines (IBM) Corporation in 1924.
The development of electromechanical computing devices continued at a rapid pace for the next few decades. These included the “Z” machines, developed by the German engineer Konrad Zuse in the 1930s, which used binary arithmetic instead of decimal so that two-state devices could be used instead of ten-state devices. Some of his later machines replaced mechanical relays with vacuum tubes. Zuse also designed a high-level programming language called Plankalkül. World War II also spurred the development of computing devices, including the Collosus computers developed by Alan Turing and a British team to break codes generated by Germany’s Enigma machine. The best-known computer built before 1945 was probably the Harvard Mark I (Figure 1.5b). Like Zuse’s “Z” machines, it was driven by electromechanical relay technology. Repeating much of the work of Babbage, Howard Aiken and others at IBM constructed this large, automatic, general-purpose, electromechanical calculator, sponsored by the U.S. Navy and intended to compute mathematical and navigational tables.
FIGURE 1.5 (a) Hollerith’s tabulating machine. (b) Harvard Mark I. (Images courtesy of the Computer History Museum.)
In 1944, Grace Murray Hopper (1907–1992) began work as a coder—what we today would call a programmer—for the Mark I. Later, while working on its successor, the Mark II, she found one of the first computer “bugs”—an actual bug stuck in one of the thousands of relays.1 To this day, efforts to find the cause of errors in programs are still referred to as “debugging.” In the late 1950s, “Grandma COBOL,” as she has affectionately been called, developed the FLOW-MATIC language, which was the basis for COBOL (COmmon Business-Oriented Language), a widely-used programming language for business applications.
John Atanasoff and Clifford Berry developed the first fully electronic binary computer (Figure 1.6a), the ABC (Atanasoff-Berry Computer), at Iowa State University during 1937–1942. It introduced the ideas of binary arithmetic, regenerative memory, and logic circuits. Unfortunately, because the ABC was never patented and others failed at the time to see its utility, it took three decades before Atanasoff and Berry received recognition for this remarkable ...

Table of contents

  1. Cover
  2. Title Page
  3. Copyright
  4. Contents
  5. Preface
  6. Acknowledgments
  7. About the Author
  8. CHAPTER 1: Introduction to Computing
  9. CHAPTER 2: Programming and Problem Solving—Software Engineering
  10. CHAPTER 3: Types in C++
  11. CHAPTER 4: Getting Started with Expressions
  12. CHAPTER 5: Control Structures
  13. CHAPTER 6: Functions and Libraries
  14. CHAPTER 7: Using Classes
  15. CHAPTER 8: More Selection Control Structures
  16. CHAPTER 9: More Repetition Control Structures
  17. CHAPTER 10: Functions in Depth
  18. CHAPTER 11: Files and Streams
  19. CHAPTER 12: Arrays and the vector Class Template
  20. CHAPTER 13: Multidimensional Arrays and Vectors
  21. CHAPTER 14: Building Classes
  22. CHAPTER 15: Pointers and Linked Structures
  23. CHAPTER 16: Data Structures
  24. ANSWERS TO TEST YOURSELF QUESTIONS
  25. APPENDIX A: ASCII CHARACTER CODES
  26. APPENDIX B: C++ KEYWORDS
  27. APPENDIX C: C++ OPERATORS
  28. APPENDIX D: OTHER C++ FEATURES
  29. INDEX