A complete and authoritative introduction to computer programming in C,
with introductions to C++, Ch, and MATLAB

Title: "C for Engineers and Scientists: An Interpretive Approach"
Author: Harry H. Cheng
Publisher: McGraw-Hill, Inc.
Date: March, 2009
ISBN: 0073376051
ISBN-13: 978-0073376059.

After students learn the materials presented in this book, they shall have a solid foundation to tackle most difficult programming tasks in the real world.

Preface and a chapter on Introduction to Fortran in comparison studies with C in PDF files are freely available for anyone from the McGraw-Hill website for the book at http://www.mhhe.com/cheng

You can order the book from the publisher.

A translation edition in Chinese published by the Higher Education Press of China.

A white paper on Ten Reasons to Teach and Learn Computer Programming in C.

A white paper on C for the Course, ASME Mechanical Engineering Magazine, September, 2009, pp 50-52. on line

A white paper on why using Ch to learn C.

Ch Student Edition is free for regsitered students in educational institutions. The latest version of Ch Student Edition can be download here.

Summary of the Book

C for Engineers and Scientists: An Interpretive Approach is a complete and authoritative introduction to computer programming in C, with introductions to C++, Ch, MATLAB, and Fortran. This book is designed to teach students how to solve engineering and science problems using the C programming language. It teaches beginners with no previous programming experience the underlying working principles of scientific computing and a disciplined approach for software development. All the major features of C89 and C99 are presented with numerous engineering application examples derived from production code. The book reveals the coding techniques used by the best C programmers and shows how experts solve problems in C. It can be used as a textbook for students in computer science, engineering, science, and other disciplines. It is also an invaluable resource and reference book for seasoned programmers.

The book focuses on systematic software design approach in C for applications in engineering and science following the latest standard developed by the ANSI and ISO C Standard Committees called C99, which resolved many deficiencies of C89 for applications in engineering and science.

The book includes a companion CD which contains the cross-platform C/C++ interpreter Ch for use as an instructional tool to help teaching and learning C and C++. Ch is the most pedagogically effective interactive computing environment for instructors to make interactive presentations in a classroom to illustrate difficult concepts such as loops, functions, arrays, and pointers. Ch is also the most user-friendly for beginners to learn computer programming and problem solving in C/C++ so that they can focus on improving their program design and problem solving skills, in collaboration with fellow students in a class who very likely may use different platforms. The book also describes how to use Visual C++ and gcc/g++ compilers to compile and link C/C++ programs with special considerations to get the programs to work properly with these compilers in different platforms.

Highlights of Key Features

  • Clear explanation of working principles of scientific computing in C for solving engineering and science problems featuring the most complete coverage of new features in C99.
  • Over 350 well-documented complete sample programs and 500 carefully designed exercises are included. Many use simple graphical plotting functions for visualization in engineering and science.
  • Extensive coverage of cross-platform software development and 64-bit programming as well as introductions to object-based programming in C++, and numerical computing in Ch and MATLAB.
  • Comprehensive supplementary teaching resources including Solutions Manual for exercises in each chapter, Instructor's Guide, and 1,600 PowerPoints for lectures and discussions. These are included in the companion website for instructors.
  • The C/C++ interpreter Ch and Integrated Development Envrionment (IDE) is included on a companion CD with each copy of the text. The CD also includes references for all functions in the standard C libraries with a sample application program for each function.

Quotes from Expert Reviewers

"This book fills a void that is present in that C is finally presented in a way that makes it useful to engineers, and numeric and scientific programmers. This book covered C accurately and presented the information in a way that is aimed at the needs of engineers. I haven't seen many difficult topics in C89 and C99 covered so well before. The order of presentation flows nicely and aids understanding. I thoroughly enjoyed (finally) reading a book about C that covered the appropriate topics needed to solve numeric, scientific, and engineering problems. Excellent book!"
--- Tom MacDonald, Chair of the ANSI X3J11 C Standard Committee
"This is a very thorough book on C for engineers and scientists. All major topics of C for engineering applications are well presented with examples. It is an invaluable resource for beginners and seasoned programmers. This is a must-have book for engineers and scientists for solving problems in C."
--- Professor David Auslander, Department of Mechanical Engineering, University of California, Berkeley
"I have taught introductory computer programming in C to freshman electrical engineering students for five semesters. This is by far the best `engineering' C programming textbook I have seen. I like the order of topics presented in the book. It is great to include plotting for visualization. The engineering examples and engineering exercises at the end of chapter are outstanding!!!"
--- Professor Paul Furth, Klipsch School of Electrical and Computer Engineering, New Mexico State University

An Instructor's Experience Using This Book as a Textbook for a Course on Introductory Computer Programming

"Generally, textbooks on topics such as C programming are evolutionary, not revolutionary. In contrast, Harry Cheng's entry is an innovative textbook and programming environment that defines a new interactive paradigm for learning and using C and C++ that's particularly well suited for scientists and engineers.

In my January 2010 programming course, the students were almost equally split between Mac and PC users. Cheng's software and textbook package let us all focus on developing programs, without concerns about merging computer tools --- that is, compilers and plotting and analysis packages --- on multiple platforms.

...

The bottom line for a post-use review is one question: Would I use the text again? In the case of C for Engineers and Scientists. An Interpretive Approach, the answer is yes.

Students agreed with this assessment; in their post-use survey, when asked whether the book should be used in future course offerings, all students answered "yes."

After using this textbook and the Ch interpreter, I have a new respect for the role of interpreters as an alternative to traditional compilers for introducing computer programming."

--- Excerpts from the book review by Professor Thomas M. Huber, "An Introduction to C and Ch: Your One-Stop Shop for Scientific Computing", IEEE Computing in Science and Engineering, Vol. 12, No. 4, July/August 2010.

Table of Contents

Part I: Structured Programming in C (738 pages)
Chapter 1 Introduction
Chapter 2 Getting Started
Chapter 3 Number Systems, Scalar Types, and Input/Output
Chapter 4 Operators and Expressions
Chapter 5 Statements and Control Flow
Chapter 6 Functions
Chapter 7 Processing Directives
Chapter 8 Storage Classes and Program Structure
Chapter 9 Formatted Input and Output
Chapter 10 Arrays
Chapter 11 Pointers
Chapter 12 Characters and Strings
Chapter 13 Structures, Enumerations, Unions, and Bit Fields
Chapter 14 File Processing
Chapter 15 Dynamic Data Structures and Cross-Platform Software Development
Chapter 16 Scientific Computing in the Entire Real Domain in C99
Chapter 17 Programming with Complex Numbers in C99 and C++

Part II: Object-Based Programming in C++ (55 pages)
Chapter 18 Introduction to C++
Chapter 19 Classes and Object-Based Programming in C++
Chapter 20 Two-and Three-Dimensional Plotting in C++

Part III: Numerical Computing in Ch (52 pages)
Chapter 21 Computational Arrays and Matrix Computations in Ch
Chapter 22 Advanced Numerical Analysis in Ch

Part IV: Numerical Computing in MATLAB (44 pages)
Chapter 23 Introduction to MATLAB and Comparison Study with C/Ch

Appendices
A Keywords
B C99 Features Supported in Ch
C C++ Features Supported in Ch
D The ASCII Character Set

Special Features of the Book

Complete C coverage. This book completely covers the C language in Part I with more 700 pages, which is organized cumulatively so that each chapter builds information presented in the earlier chapters. Each chapter itself is organized cumulatively so that each section uses information provided in the previous sections. A single topic is presented in a section first, and then reinforced and cross-referenced in other sections and chapters. Beginners can skip sections and chapters marked with the double dag symbol in the title without hindering the learning of the later chapters. These materials, however, are very useful for those who plan on serious software development in C or intend to take other advanced courses. The text is logically organized, and heavily cross-referenced and indexed to serve as a reference for serious programmers.

Only two programs in Part I used extended features in Ch over C for simplicity of programming. Program 4.6 uses the format specifier "%b" in Ch to print out data in binary number. Program 4.7 is a much compplicated equivalent C program. Program 10.30 uses the function linsolve() in Ch to solve a system of linear equations. Program 10.31 is an equivalent version in C.

Extensive coverage of major C99 features. C99 features of variable length arrays (VLA), type generic functions, IEEE 754 floating-point arithmetic, complex numbers, and new data types bool and long long are used for numerical computing. They overcome the shortcomings of C89 for solving problems in engineering and science.
Plotting for visualization. A picture is worth a thousand words. Graphical plotting is essential for applications in engineering and science. A plotting C++ library is used for visualization for solving many problems in engineering and science in both the text and exercises. All plots including those in exercises were generated using simple functions or member functions in this plotting library.
Multiple forms of presentation. Many illustrations are used to clarify difficult concepts and programming features such as expression evaluation order, pointers, arrays, structures, byte order, and dynamic data structures (singly linked list, doubly linked list, circularly linked lists, stacks, queues, and binary trees). Flowcharts, pseudocode, and procedures are used to describe complicated algorithms.
Multiple versions for example programs. Earlier example programs are gradually rewritten to make them more concise, efficient, powerful, useful, or user friendly. This way, students do not struggle with trying to understand new features and new programs at the same time.
Teaching and learning by examples with over 350 well-documented complete sample programs of more than 14,000 lines of code. These programs show various features of C and a disciplined approach including how to document source code on-line, programming style, modular programming, code reuse, how to overcome the numerical inaccuracy of floating-point numbers, and algorithm development for solving problems in engineering and science. Many of these programs are derived from the real-world production code. In addition, many succinct C code and statements are executed interactively with output in Ch to illustrate numerous programming features and concepts.
Over 500 carefully designed exercises as homework problems. These exercises for solving many problems in engineering and science reinforce concepts presented in the text. Each chapter contains exercises asking students to find potential trouble spots and likely errors. Abundant exercises are designed for teaching multiple sessions without repeating problems.
Cross-platform software development. All code examples in Parts I and II have been tested in Windows, Linux, Mac OS X, Solaris, HP-UX, FreeBSD, and QNX in both the C/C++ interpreter Ch and C/C++ compilers. The implementation and platform-specific issues are presented with examples throughout the book in sections titled "Making It Work" at the end of each chapter in Parts I and II. These sections illustrate how to use C/C++ interpreter Ch and ChIDE to execute C and C++ programs. They describe the processes and options on how to compile and link C/C++ programs using Visual C++ in Windows, gcc and g++ in Linux, and cc and CC in Solaris through ChIDE, command shell and make files. Building and distributing static and dynamic libraries using make files on these different platforms is also demonstrated.
64-bit programming. 64-bit machines are becoming increasingly popular. This book addresses how to write portable C code for machines with a different number of bits. Whenever the code produces different results for 32-bit and 64-bit machines, it is pointed out in the text.
Extensive coverage and unique presentation of difficult concepts. Difficult topics such as arrays, pointers (pointers to pointers, pointers to functions, pointers to arrays, arrays of pointers, dynamical allocation of multi-dimensional ararys, passing arrays of variable length using poiners to pointers, generic pointers, how to find if a program has a memory leak in different platforms), binary and text mode for accessing files, byte order (endianness), structure alignment, dynamic data structures (singly linked list, doubly linked list, circularly linked lists, stacks, queues, and binary trees), developing and distributing static and dynamic libraries in Windows and Unix, and hardware interfaces are thoroughly covered using multiple forms of presentation with many sample application programs.
Top-down and bottom-up software development is presented with real-world application examples. The book is culminated by three interactive menu-driven GPA programs gradually rewritten with structures, arrays, dynamic data structures of singly linked lists, and data files using static and dynamic GPA libraries. Old application programs would still work without any modification whereas the underlying GPA library is gradually rewritten with new features for new applications. The modular programming and code reuse are clearly illustrated by these application programs.
LAPACK (Linear Algebra PACKage) written in Fortran and its C version, CLAPACK, are introduced. How to use this most commonly used numerical library for linear systems is presented with examples. Mixed-language programming with both row-wise and column-wise arrays is addressed.
Commonly used Unix commands are used for cross-platform software development. Commonly used Unix commands such as cc, gcc, g++, c++, CC, ld, make, ls, cd, mkdir, pwd, cp, rm, chmod, man, more, diff, wc, hexdump, ps, grep, xhost, ar, ranlib, ln, zip, unzip, gzip, and tar are introduced in the book for cross-platform software development. In addition, the input/output redirection and pipeline are introduced at the beginning for using data files in programs.
Object-based programming in C++ is introduced in Part II. Essential features of C++ for applications in engineering and science are covered. A C++ class for graphical plotting is introduced as an example of application of C++.
Numerical computing in Ch using computational arrays as first-class objects and advanced numerical functions are introduced in Part III. They can be used conveniently to solve ODE, non-linear equations, linear algebra, etc. for complicated problems in engineering and science.
MATLAB is introduced in Part IV as a second programming language in comparison with C and Ch. Part IV contains a thorough introduction to MATLAB and comparison study with C and Ch for numerical computing. With a solid foundation in computer programming in C, students can pick up any other languages and mathematical packages such as MATLAB or Mathematica quickly. Part IV can also serve as a quick reference for programming in MATLAB for C programmers.
Fortran is introduced as a second programming language in comparison with C. The chapter is available in a PDF file from the website for the book. Once you have learned C, you will be able to quickly learn Fortran by reading this chapter. The comparison study presented in this chapter will also be very useful for those who have the prior programming experience in Fortran to learn C.
Companion CD contains C/C++ interpreter Ch Student Edition including the user-friendly ChIDE. A C/C++ interpreter Ch can be used for interactive execution of C expressions, statements, functions, and programs. It can be used by students or instructors in classrooms for quick testing and trying difficult C features such as pointers and arrays. It is especially suitable for beginners to learn internal representation of integral and floating-point numbers, programming concepts of selection statements, loops, functions, arrays, and pointers. Ch environment for Windows also contains nearly 250 commonly used Unix commands such as vi, ls, rm, make, awk, sed, zip, unzip, gzip, and tar. It can also be used by students to learn Unix in a familiar Windows environment for a smooth transition from Windows to Unix. ChIDE is especially developed for beginners without any previous programming experience to learn how to design and debug C/C++ programs. It allows the user to edit and interpretively execute C/C++ programs in a user-friendly integrated development environment. It can execute functions and programs with detailed line-by-line and step-by-step traces. It can also invoke C and C++ compilers to compile and link C/C++ programs, then run the created binary executable programs. The CD also contains a complete reference manual in a PDF file and sample demo C source programs for all functions in the C standard libraries.
Using multiple colors in the book. For clarity of the presentation, multiple colors are used in the book. Programs are displayed with the light blue background. Interactive executions of programs, functions, statements, and expressions are displayed with the dark blue background. The output from programs are displayed with the grey background. Practical application examples are separated from the main text by two thick horizontal blue lines, one at the beginning and the other at the end.

Prerequisites

The mathematical prerequisite for the book is trigonometry, except for Chapter 22 and Chapter 23 (section 23.11), which require a calculus background. No prior computer or programming experience is required. Because it is assumed that readers, such as freshman students, have limited mathematical background, extra effort has been made to carefully select and explain many practical applications in engineering and science, as well as numerical methods to teach beginners the underlying working principles of scientific computing and a disciplined software design in C/C++/Ch/MATLAB.

Using this Book as a Textbook

This is a comprehensive book on software development for solving problems in engineering and science with complete coverage of the C language and other programming languages. The materials are more than enough for a one-semester course. Below are some possible ways to use the book as a textbook.

Computer Programming for Engineering Applications or Engineering Problem Solving. In this freshman introductory course, it is assumed that students have no prior computer and programming experience. Computer programming in C is introduced to solve problems in engineering and science. At the end, MATLAB is introduced as a second programming language to solve the same problems previously solved in C. With a solid foundation in C, students can learn MATLAB quickly.
Introduction to Computer Programming in C. The book can be used as a gentle slow-paced introduction to computer programming using the C language. It is assumed that students do not have any prior computer or programming experience. Example programs can be presented using ChIDE with detailed line-by-line traces.
Introduction to C Programming or Advanced C Programming. For this upper-division undergraduate course, it is assumed that students have prior programming experience in other programming languages or software packages. Some difficult topics related to C and its applications can be covered.
Using this book as a supplementary textbook. The text can also be used as a supplement for some upper-division or graduate courses in engineering and science, in which C programming is needed.

Instructor's Teaching Resources

This book grew out of the author's over 18 years of teaching introductory computer programming in C for engineering applications and engineering software design at the University of California, Davis since 1992. It also reflects author's unique experience in the design and implementation of an ISO C standard compliant cross-platform C/C++ interpreter Ch (developed in C/C++) as well as his extensive industrial and research work on solving engineering problems in C and C++.

If the book is adopted for teaching, instructors can obtain about 1,400 PowerPoint slides complementary to this book with many different example programs ready for classroom presentation, 200 companion PowerPoint slides for discussion sessions, Instructor's Guide (with sample syllabus, homework assignments, quizzes, and midterm and final examinations), and Solutions Manual and the source code for solutions for exercises in each chapter from the McGraw-Hill website for the book at http://www.mhhe.com/cheng

Requesting a Complimentary Copy and Instructor's Teaching Resources for Teaching Using This Book by Instructors

To adopt this book for teaching a course, as an instructor, you may request a complimentary copy of the textbook and Instructor's Teaching Resources listed above from your local McGraw-Hill sale representative at http://catalogs.mhhe.com/mhhe/findRep.do.