ENGINEERING PROBLEM SOLVING WITH C++

Similar documents
CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England. and Associated Companies throughout the world

Computer Programming C++ (wg) CCOs

Part I Basic Concepts 1

ощ 'ршорвшэш! цвн-эориэу ощ 'sajbpossv # PIPG DUJ 'ssjmoossv ^ PIPG pipa w н OX ЛЮН VAV

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.

Absolute C++ Walter Savitch

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

B.Sc. Final B.SC. PART-III PAPER I COMPUTER ORGANIZATION II

Problem Solving with C++

Practical C++ Programming

PROGRAMMING IN C AND C++:

Programming Fundamentals - A Modular Structured Approach using C++ By: Kenneth Leroy Busbee

WITH C+ + William Ford University of the Pacific. William Topp University of the Pacific. Prentice Hall, Englewood Cliffs, New Jersey 07632

Preface to the Second Edition Preface to the First Edition Brief Contents Introduction to C++ p. 1 A Review of Structures p.


Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

C Programming for Electronic Engineers

CERTIFICATE IN WEB PROGRAMMING

C++ (Non for C Programmer) (BT307) 40 Hours

Spring 2018 Updates. Computing Technology for All. Data Structure Essentials. Digital Design

PROBLEM SOLVING WITH FORTRAN 90

Data Structures in C++ Using the Standard Template Library

Contents. Preface. Introduction. Introduction to C Programming

KLiC C Programming. (KLiC Certificate in C Programming)

Time: 3 HOURS Maximum Marks: 100

Welcome to Teach Yourself Acknowledgments Fundamental C++ Programming p. 2 An Introduction to C++ p. 4 A Brief History of C++ p.

Object Oriented Programming with c++ Question Bank

Contents. 2 Introduction to C++ Programming,

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

[CHAPTER] 1 INTRODUCTION 1

An Object Oriented Programming with C

Introduction p. 1 Pseudocode p. 2 Algorithm Header p. 2 Purpose, Conditions, and Return p. 3 Statement Numbers p. 4 Variables p. 4 Algorithm Analysis

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

Introduction to Programming Using Java (98-388)

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

Introduction... ix. Chapter 1: Exploring Fundamental Programming Concepts... 1

MATLAB is a multi-paradigm numerical computing environment fourth-generation programming language. A proprietary programming language developed by

Dietrich Paulus Joachim Hornegger. Pattern Recognition of Images and Speech in C++

Short Notes of CS201

CS201 Some Important Definitions

LOGIC AND DISCRETE MATHEMATICS

B.Sc II Year Computer Science (Optional)

CS201 - Introduction to Programming Glossary By

Contents. 1 Introduction to Computers, the Internet and the World Wide Web 1. 2 Introduction to C Programming 26

Contents. Illustrations. 1 Introduction to Computers, the Internet, the Web and C# 1

S Y B Voc Software Development Syllabus

Multiple Choice Questions. Chapter 5

This page intentionally left blank

VALLIAMMAI ENGINEERING COLLEGE

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

Introduction to Computational Mathematics

OUTCOMES BASED LEARNING MATRIX

STEPHEN WOLFRAM MATHEMATICADO. Fourth Edition WOLFRAM MEDIA CAMBRIDGE UNIVERSITY PRESS

Murach s Beginning Java with Eclipse

Question Paper Code : 97044

Babaria Institute of Technology Computer Science and Engineering Department Practical List of Object Oriented Programming with C

Final exam. Final exam will be 12 problems, drop any 2. Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers)

Deitel Series Page How To Program Series

CHOICE BASED CREDIT SYSTEM (With effect from )

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

F1 A Java program. Ch 1 in PPIJ. Introduction to the course. The computer and its workings The algorithm concept

C# Programming: From Problem Analysis to Program Design. Fourth Edition

Borland 105, 278, 361, 1135 Bounded array Branch instruction 7 break statement 170 BTree 873 Building a project 117 Built in data types 126

C-LANGUAGE CURRICULAM

Learning Objectives. C++ For Artists 2003 Rick Miller All Rights Reserved xli

B.C.A 2017 OBJECT ORIENTED PROGRAMMING USING C++ BCA303T MODULE SPECIFICATION SHEET

10CS36: Object Oriented Programming with C++

Object-Oriented Programming and Data Structures

Microsoft. Microsoft Visual C# Step by Step. John Sharp

About the Author. Dependency Chart. Chapter 1: Logic and Sets 1. Chapter 2: Relations and Functions, Boolean Algebra, and Circuit Design

MyProgram m i ng Lab. get with the programming. Through the power of practice and immediate personalized

Prelude to Programming

KLiC C++ Programming. (KLiC Certificate in C++ Programming)

Preface. Features of the Third Edition

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

Advanced C++ Programming Workshop (With C++11, C++14, C++17) & Design Patterns

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year

Big Java Late Objects

CSCI 171 Chapter Outlines

Ch02. True/False Indicate whether the statement is true or false.

Silver Oak Engineering College and technology Information Technology Department

HIGER SECONDARY FIRST YEAR COMPUTER SCIENCE

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE

Syllabus for Computer Applications


Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest. Introduction to Algorithms

COMPUTER PROGRAMMING LAB

CGS 2405 Advanced Programming with C++ Course Justification

M.C.A DEGREE EXAMINATION,NOVEMBER/DECEMBER 2010 Second Semester MC 9222-OBJECT ORIENTED PROGRAMMING (Regulation 2009)

Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team

ADMINISTRATIVE MANAGEMENT COLLEGE

Name :. Roll No. :... Invigilator s Signature :.. CS/B.TECH (NEW)/SEM-2/CS-201/ BASIC COMPUTATION & PRINCIPLES OF COMPUTER PROGRAMMING

"Charting the Course... MOC Programming in C# with Microsoft Visual Studio Course Summary

Overview : Table Of Content :

BACHELOR OF COMPUTER APPLICATIONS (BCA)

F. THOMSON LEIGHTON INTRODUCTION TO PARALLEL ALGORITHMS AND ARCHITECTURES: ARRAYS TREES HYPERCUBES

Fundamentals of the Java Programming Language

STATE COUNCIL OF EDUCATIONAL RESEARCH AND TRAINING TNCF DRAFT SYLLABUS.

Transcription:

ENGINEERING PROBLEM SOLVING WITH C++ Second Edition Delores M. Etter Electrical Engineering Department United States Naval Academy Jeanine A. Ingber Training Consultant Sandia National Laboratories Upper Saddle River, New Jersey 07458

Contents Preface xi Introduction to Computing and Engineering Problem Solving 2 1.1 Historical Perspective 3 1.2 Recent Engineering Achievements 7 Changing Engineering Environment 9 1.3 Computing Systems 11 Computer Hardware 11 Computer Software 12 1.4 Data Representation and Storage 16 Number Systems 17 Data Types and Storage 23 1.5 An Engineering Problem-Solving Methodology 26 Summary 29 Simple C++ Programs 34 ENGINEERING CHALLENGE: Global Change 2.1 Program Structure 35 2.2 Constants and Variables 39 Scientific Notation 41 Numeric Data Types 42 Boolean Data Type 44 Character Data Type 44 String Data 46 Symbolic Constants 47 2.3 C++ Operators 47 Assignment Operator 47 Arithmetic Operators 49 Precedence of Operators 51 Overflow and Underflow 54 Increment and Decrement Operators 55 Abbreviated Assignment Operators 55 2.4 Standard Input and Output 57 The с out Object 57 Stream Objects 58 Manipulators 60 The ein Object 63

vi Contents 2.5 Numerical Technique: Linear Interpolation 65 2.6 Problem Solving Applied: Freezing Temperature of Seawater 69 2.7 Basic Functions Included in the C++ Standard Library 73 Elementary Math Functions 74 Trigonometrie Functions 75 Hyperbolic Functions* 76 Character Functions 78 2.8 Problem Solving Applied: Velocity Computation 78 2.9 System Limitations 82 Summary 83 Control Structures 92 ENGINEERING CHALLENGE: Data Collection 3.1 Algorithm Development 93 Тор-Down Design 93 Structured Programming 94 Refinement in Pseudocode 95 Evaluation of Alternative Solutions 98 3.2 Conditional Expressions 98 Relational Operators 98 Logical Operators 99 Precedence and Associativity 101 3.3 Selection Statements 102 Simple if Statements 102 i f / e 1 s e Statement 104 switch Statement 108 3.4 Loop Structures 111 while Loop 111 do/while Loop 114 for Loop 116 break and continue Statements 120 Structuring Input Loops 121 3.5 Problem Solving Applied: Weather Balloons 125 Summary 130 Working with Data Files 138 ENGINEERING CHALLENGE: Weather Prediction 4.1 Defining File Streams 139 Stream Class Hierarchy 139 if stream Class 142 of stream Class 144 4.2 Reading Data Files 145 Specified Number of Records 146

Contents vii Trailer or Sentinel Signals 148 End-of-File 150 4.3 Generating a Data File 153 4.4 Problem Solving Applied: Data Filters Modifying an HTML File 156 4.5 Error Checking 159 The Stream State 161 4.6 Numerical Technique: Linear Modeling* 166 4.7 Problem Solving Applied: Ozone Measurements* 169 Summary 175 Modular Programming with Functions 182 ENGINEERING CHALLENGE: Enhanced Oil and Gas Recovery 5.1 Modularity 183 5.2 Programmer-Defined Functions 185 Function Definition 186 Solution 1 190 Solution 2 191 Function Prototype 194 5.3 Parameter Passing 195 Pass by Value 196 Pass by Reference 198 Storage Class and Scope 204 5.4 Problem Solving Applied: Calculating a Center of Gravity 206 5.5 Random Numbers 210 Integer Sequences 210 Floating-Point Sequences 214 5.6 Problem Solving Applied: Instrumentation Reliability 215 5.7 Numerical Technique: Roots of Polynomials* 222 Polynomial Roots 222 Incremental-Search Technique 224 5.8 Problem Solving Applied: System Stability* 226 Newton-Raphson Method* 232 5.9 Numerical Technique: Integration* 236 Integration Using the Trapezoidal Rule 236 Summary 240 One-Dimensional Arrays 250 ENGINEERING CHALLENGE: Hurricane Tracking 6.1 Arrays 251 Definition and Initialization 252 Computation and Output 256 Function Arguments 260

VIII Contents 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 Problem Solving Applied: Hurricane Categories Statistical Measurements Simple Analysis Variance and Standard Deviation Custom Header Files Problem Solving Applied: Speech Signal Analysis Sorting Algorithms Selection Sort Search Algorithms Unordered Lists Ordered Lists Character Strings С Style String Definition and I/O String Functions Problem Solving Applied: Palindromes The string Class Summary 263 269 269 271 274 274 280 281 282 283 283 285 285 288 289 293 295 Two-Dimensional Arrays and Matrices 300 ENGINEERING CHALLENGE: Terrain Navigation 7.1 Two-Dimensional Arrays 301 Declaration and Initialization 302 Computations and Output 306 Function Arguments 308 7.2 Problem Solving Applied: Terrain Navigation 311 7.3 Matrices* 316 Determinant 316 Transpose 317 Matrix Addition and Subtraction 318 Matrix Multiplication 318 7.4 Numerical Technique: Solution to Simultaneous Equations* 321 Graphical Interpretation 321 Gauss Elimination 323 7.5 Problem Solving Applied: Electrical Circuit Analysis* 327 7.6 Higher Dimensional Arrays* 333 Summary 335 An Introduction to Classes 342 ENGINEERING CHALLENGE: Simulation 8.1 Programmer Defined Types 343 8.2 Design and Implementation of Classes 345 Class Declaration 345 Class Implementation 347

Contents ix 8.3 Class Composition 353 8.4 Constructors 357 Initialization Lists 361 8.5 The vector class 364 Parameter Passing 366 8.6 Problem Solving Applied: Calculating probabilities 368 8.7 private Methods 381 Class Objects as Arguments to Member Functions 384 8.8 Problem Solving Applied: Design of Composite Materials 385 Summary 392 An Introduction to Pointers 396 ENGINEERING CHALLENGE: Weather Patterns 9.1 Addresses and Pointers 397 Address Operator 398 Pointer Assignment 400 Pointer Arithmetic 403 9.2 Pointers to Array Elements 406 One-Dimensional Arrays 407 Character Strings 409 Pointers as Function Arguments 410 9.3 Problem Solving Applied: El Nino-Southern Oscillation Data 415 9.4 Dynamic Memory Allocation 418 The new Operator 418 Dynamically Allocated Arrays 420 The delete Operator 420 9.5 Problem Solving Applied: Seismic Event Detection 422 9.6 Common Errors Using new and delete 428 9.7 Data Structures and the C++ Standard Template Library (STL) 430 The list class 430 The stack class 434 The queue class 436 9.8 Problem Solving Applied: Concordance of a Text File* 438 Summary 444 Additional Topics in Programming with Classes 450 ENGINEERING CHALLENGE: Artificial Intelligence 10.1 Introduction to Generic Programming 451 Function Templates 452 Overloading Operators 456 The pixel class 456 Arithmetic Operators 458 friend Functions 463

10.2 Problem Solving Applied: Color Image Processing 468 10.3 Recursion 475 Factorial Function 475 Fibonacci Sequence 477 Binary Trees 479 10.4 Class Templates 490 10.5 Inheritance 496 The Square class 497 The Cube class 502 10.6 virtual Methods 504 10.7 Problem Solving Applied: Iterated Prisoner's Dilemma 507 Summary 516 C++ Standard Library 521 ASCII Character Codes 529 Using MATLAB to Plot Data from ASCII Files 533 C++ Program to Generate a Data File 533 ASCII Data File Generated by the C++ Program 534 Generating a Plot with MATLAB 534 References 536 PRACTICE! Solutions 537 Index 552