ENERGY 211 / CME 211
Computer Programming in
C++ for Earth Scientists and
Engineers
Lecture 1
September 22, 2008
2
Why This Course?
• To help students improve or acquire the
programming skills they need for
research in earth sciences or
engineering
• Alternative to CS106X, with more
relevant examples and exercises
3
What is Covered?
• Learning C++
– Basics
– Classes
– Standard C++ library, including STL
• Software Engineering Practices
– Computer architecture essentials
– Design, testing, debugging
– Efficient memory usage
• Special Topics
4
Course Staff
• Instructor: Prof. Jim Lambers
– Acting assistant professor, ERE/ICME
– Former software engineer
– Email: lambers@stanford.edu
• TA: Alejandro David Leiva
– MS student, ERE
– Email: aleiva@stanford.edu
• TA: Yifan Zhou
– MS student, ERE
– Email: yifanz@stanford.edu
5
Course Web Sites
• http://energy211.stanford.edu
– Primary site, for easier access to course
materials and information
• http://coursework.stanford.edu
– For viewing grades, receiving email
announcements
• Lecture notes, assignments available at
either site
6
Your Grade
• No midterm or final exam
• 6 programming projects, 10-15% each
• Final project, 30%
• Bonus: 1% added to overall grade if at
least 5 coding-related questions asked
by e-mail to instructor
• Letter grades: straight scale (or nicer)
7
Programming Projects
• 6 projects, one week each
• Can (and should!) work with a partner
– Can be different partner for each project
– No changing partners in the middle of a
project
• Must be submitted electronically (details
to come)
• First project to be distributed on Friday,
October 3
8
Late Days
• Programming projects must be
submitted electronically by 11:59pm on
the due date
• You have five late days for the entire
quarter that may be used at any time,
no questions asked
• Use them wisely, they might be all you
get!
9
Why C++?
• To maximize computational efficiency,
best to use low-level programming
languages (easy to translate into
efficient machine code)
• To efficiently build large applications,
best to use high-level languages that
support modularity, abstraction and
encapsulation
• C++ combines aspects of both
10
Low-level C/C++
#include <stdlib.h>
extern ssize_t write(int, const void *, size_t);
int main()
{
write(1, "Hello world!n", 13);
}
0: 1b 00 00 00 sethi %hi(0x0), %o5
4: 82 10 00 0f mov %o7, %g1
8: 92 03 60 00 add %o5, 0, %o1
c: 90 10 20 01 mov 1, %o0
10: 94 10 20 0d mov 13, %o2
14: 40 00 00 00 call 0x14
18: 9e 10 00 01 mov %g1, %o7
C code
Assembly
code
11
High-level C++
#include <iostream>
int main()
{
std::cout << "Hello world!" << std::endl;
}
• Easier to understand this program’s purpose:
to send text and end-of-line to output device
• No need for device descriptors, computing text
length, or escape sequences
• Being programmer-friendlier carries a cost:
assembly code is nearly 4 times as long!
12
A Few Buzzwords
• Modularity: the extent to which a
program is decomposed into separate
modules, thus simplifying design
• Abstraction: the practice of reducing or
factoring out details so that one can
focus on only a few concepts at a time
• Encapsulation: hiding the design of a
task from the rest of the application,
thus protecting it from changes
13
What C++ Offers
• All of the power and efficiency of C
(which is a subset)
• Object-oriented programming (though
not truly an object-oriented language)
• Generic programming, through
templates
• Definition and extension of operators
• Freedom to use paradigm of choice
14
Why Not Just Use MATLAB?
• MATLAB is useful for proof-of-concept,
but not for release-grade software
• Its language is interpreted, not compiled
into machine code
• Only offers a subset of the functionality
of a compiled language such as C++
• This lack of flexibility significantly, and
adversely, impacts usability and
performance
15
Examples of Drawbacks
• MATLAB uses LAPACK and BLAS for
its low-level linear algebra operations
• Use of other libraries is much more
difficult and less efficient
• Forced to use MATLAB’s data
structures for dense and sparse
matrices, or other data
• Lack of control over how data is
accessed results in needless copying
16
Effective Software
Engineering
• Involves much more than just designing
and implementing algorithms
• Criteria for a program’s usefulness:
– Does it accomplish its intended task, and if
so, with what limitations?
– How efficient is it, in the given computing
environment?
– How robust is it? Does it handle adverse
conditions gracefully?
17
Hard Lessons
• The sooner you start writing code, the
longer it takes you to finish
• Untested code will almost always fail
• What works today can be broken
tomorrow
• The first person to use your code will
input the one case that it doesn’t handle
• Document code well, because your
code can be unintelligible, even to you
18
Sound Programming Practices
are Essential!
• In 1991 Gulf War, US Patriot missiles
intercepted Iraqi SCUD missiles by
estimating velocity = distance / time
• Time interval obtained by subtracting
times at which position was determined
• Times measured as seconds since
tracking devices first activated in the
field
19
Tracking SCUD Missiles
Correct Incorrect
Source: U.S. GAO Report
20
Little Details Aren’t Really
Little
• Time values large, but close together,
so subtraction inaccurate, due to
catastrophic cancellation
• Velocity estimates useless, so missile’s
position could not be determined
• Interception failed, led to 28 deaths
• What is a simple remedy?
21
Next Time
• Overview of C++:
– History
– Design
• How to write and run C++ programs
– Windows
– UNIX/LINUX
• Understanding simple C++ programs

More Related Content

PPTX
Intro to Python (High School) Unit #1
PPT
01 introduction to cpp
PPT
Software engineering
PPT
Software engineering
PPT
Software engineering
PDF
02 c++g3 d
DOCX
Comso c++
PDF
C programming from problem analysis to program design 4th ed Edition D S Malik
Intro to Python (High School) Unit #1
01 introduction to cpp
Software engineering
Software engineering
Software engineering
02 c++g3 d
Comso c++
C programming from problem analysis to program design 4th ed Edition D S Malik

Similar to Lecture1.ppt (20)

DOCX
Ece 1322 programming_for_engineers_s1_201213(1)
PPSX
Programming Languages Intriduction to C++ programming
PDF
C programming from problem analysis to program design 4th ed Edition D S Malik
PDF
Starting Out With C Early Objects 7th Edition 7th Edition Tony Gaddis
PDF
Programmingwithc 131017034813-phpapp01
PPTX
lecture Slides - Week 1.programming fundamentals
PDF
Computer Programming With C Kunal Pimparkhede
PDF
Programming c++
PDF
Fundamentals of programming with C++
PPT
1 2 programming
PDF
C programming from problem analysis to program design 4th ed Edition D S Malik
PDF
Modern C For Software Developers Serious C Development 13 Karen Singh Garewal
PDF
Modern C For Software Developers Serious C Development 13 Karen Singh Garewal
PDF
C and c++ in 5 days
PDF
Programming c and c++ in five days
PDF
A Complete Guide to Programming in C 1st Edition Ulla Kirch-Prinz
PPTX
C++ l 1
PPTX
Expection Setting - 1st ppt. pptx
PPT
C++ - A powerful and system level language
PPTX
Programming using C++ - slides.pptx
Ece 1322 programming_for_engineers_s1_201213(1)
Programming Languages Intriduction to C++ programming
C programming from problem analysis to program design 4th ed Edition D S Malik
Starting Out With C Early Objects 7th Edition 7th Edition Tony Gaddis
Programmingwithc 131017034813-phpapp01
lecture Slides - Week 1.programming fundamentals
Computer Programming With C Kunal Pimparkhede
Programming c++
Fundamentals of programming with C++
1 2 programming
C programming from problem analysis to program design 4th ed Edition D S Malik
Modern C For Software Developers Serious C Development 13 Karen Singh Garewal
Modern C For Software Developers Serious C Development 13 Karen Singh Garewal
C and c++ in 5 days
Programming c and c++ in five days
A Complete Guide to Programming in C 1st Edition Ulla Kirch-Prinz
C++ l 1
Expection Setting - 1st ppt. pptx
C++ - A powerful and system level language
Programming using C++ - slides.pptx
Ad

More from AqeelAbbas94 (20)

PPT
trees_introduction.ppt ug yg i gg yg gj
PPT
ch6_2_v1.ppt yh jkkj jhjh h jhyj hg hghh
PPT
lecture_5 (2).ppt hjhrrgjbgrmgrhbgrgghjd
PPT
1-Lec - Introduction vhvv,vbvv,v (2).ppt
PPT
2-Lec - History of OOP and Java (1) .ppt
PPTX
Lecture-32-33.pptx
PPTX
10-Lec - Nested IF Statement.pptx
PPTX
blue.pptx
PPTX
use_case+use_case description.pptx
PPT
555e81217b39f1c1262b33d0.ppt
PPTX
12-Lec - Repetition For Loop.pptx
PPTX
hexagon.pptx
PDF
wepik-exploring-the-robust-features-of-samsung-health-app-enhancing-well-bein...
PPT
lecture56.ppt
PPT
04.ppt
PPT
19-Lec - Multidimensional Arrays.ppt
PPT
SelectionSort.ppt
PPT
Lecture2 (1).ppt
PPT
ch06.ppt
PPTX
Your Title goes Here.pptx
trees_introduction.ppt ug yg i gg yg gj
ch6_2_v1.ppt yh jkkj jhjh h jhyj hg hghh
lecture_5 (2).ppt hjhrrgjbgrmgrhbgrgghjd
1-Lec - Introduction vhvv,vbvv,v (2).ppt
2-Lec - History of OOP and Java (1) .ppt
Lecture-32-33.pptx
10-Lec - Nested IF Statement.pptx
blue.pptx
use_case+use_case description.pptx
555e81217b39f1c1262b33d0.ppt
12-Lec - Repetition For Loop.pptx
hexagon.pptx
wepik-exploring-the-robust-features-of-samsung-health-app-enhancing-well-bein...
lecture56.ppt
04.ppt
19-Lec - Multidimensional Arrays.ppt
SelectionSort.ppt
Lecture2 (1).ppt
ch06.ppt
Your Title goes Here.pptx
Ad

Recently uploaded (20)

PPTX
Unit1_Kumod_deeplearning.pptx DEEP LEARNING
PDF
GIÁO ÁN TIẾNG ANH 7 GLOBAL SUCCESS (CẢ NĂM) THEO CÔNG VĂN 5512 (2 CỘT) NĂM HỌ...
PDF
anganwadi services for the b.sc nursing and GNM
PPTX
MMW-CHAPTER-1-final.pptx major Elementary Education
PPTX
Single Visit Endodontics.pptx treatment in one visit
PDF
Review of Related Literature & Studies.pdf
PDF
IS1343_2012...........................pdf
PPTX
Key-Features-of-the-SHS-Program-v4-Slides (3) PPT2.pptx
PPSX
namma_kalvi_12th_botany_chapter_9_ppt.ppsx
PDF
Chevening Scholarship Application and Interview Preparation Guide
PPTX
principlesofmanagementsem1slides-131211060335-phpapp01 (1).ppt
PDF
Global strategy and action plan on oral health 2023 - 2030.pdf
PDF
Physical pharmaceutics two in b pharmacy
PPTX
Chapter-4-Rizal-Higher-Education-1-2_081545.pptx
PDF
WHAT NURSES SAY_ COMMUNICATION BEHAVIORS ASSOCIATED WITH THE COMP.pdf
PDF
Horaris_Grups_25-26_Definitiu_15_07_25.pdf
PDF
HSE 2022-2023.pdf الصحه والسلامه هندسه نفط
PDF
LATAM’s Top EdTech Innovators Transforming Learning in 2025.pdf
PPTX
Copy of ARAL Program Primer_071725(1).pptx
PPTX
GW4 BioMed Candidate Support Webinar 2025
Unit1_Kumod_deeplearning.pptx DEEP LEARNING
GIÁO ÁN TIẾNG ANH 7 GLOBAL SUCCESS (CẢ NĂM) THEO CÔNG VĂN 5512 (2 CỘT) NĂM HỌ...
anganwadi services for the b.sc nursing and GNM
MMW-CHAPTER-1-final.pptx major Elementary Education
Single Visit Endodontics.pptx treatment in one visit
Review of Related Literature & Studies.pdf
IS1343_2012...........................pdf
Key-Features-of-the-SHS-Program-v4-Slides (3) PPT2.pptx
namma_kalvi_12th_botany_chapter_9_ppt.ppsx
Chevening Scholarship Application and Interview Preparation Guide
principlesofmanagementsem1slides-131211060335-phpapp01 (1).ppt
Global strategy and action plan on oral health 2023 - 2030.pdf
Physical pharmaceutics two in b pharmacy
Chapter-4-Rizal-Higher-Education-1-2_081545.pptx
WHAT NURSES SAY_ COMMUNICATION BEHAVIORS ASSOCIATED WITH THE COMP.pdf
Horaris_Grups_25-26_Definitiu_15_07_25.pdf
HSE 2022-2023.pdf الصحه والسلامه هندسه نفط
LATAM’s Top EdTech Innovators Transforming Learning in 2025.pdf
Copy of ARAL Program Primer_071725(1).pptx
GW4 BioMed Candidate Support Webinar 2025

Lecture1.ppt

  • 1. ENERGY 211 / CME 211 Computer Programming in C++ for Earth Scientists and Engineers Lecture 1 September 22, 2008
  • 2. 2 Why This Course? • To help students improve or acquire the programming skills they need for research in earth sciences or engineering • Alternative to CS106X, with more relevant examples and exercises
  • 3. 3 What is Covered? • Learning C++ – Basics – Classes – Standard C++ library, including STL • Software Engineering Practices – Computer architecture essentials – Design, testing, debugging – Efficient memory usage • Special Topics
  • 4. 4 Course Staff • Instructor: Prof. Jim Lambers – Acting assistant professor, ERE/ICME – Former software engineer – Email: [email protected] • TA: Alejandro David Leiva – MS student, ERE – Email: [email protected] • TA: Yifan Zhou – MS student, ERE – Email: [email protected]
  • 5. 5 Course Web Sites • http://energy211.stanford.edu – Primary site, for easier access to course materials and information • http://coursework.stanford.edu – For viewing grades, receiving email announcements • Lecture notes, assignments available at either site
  • 6. 6 Your Grade • No midterm or final exam • 6 programming projects, 10-15% each • Final project, 30% • Bonus: 1% added to overall grade if at least 5 coding-related questions asked by e-mail to instructor • Letter grades: straight scale (or nicer)
  • 7. 7 Programming Projects • 6 projects, one week each • Can (and should!) work with a partner – Can be different partner for each project – No changing partners in the middle of a project • Must be submitted electronically (details to come) • First project to be distributed on Friday, October 3
  • 8. 8 Late Days • Programming projects must be submitted electronically by 11:59pm on the due date • You have five late days for the entire quarter that may be used at any time, no questions asked • Use them wisely, they might be all you get!
  • 9. 9 Why C++? • To maximize computational efficiency, best to use low-level programming languages (easy to translate into efficient machine code) • To efficiently build large applications, best to use high-level languages that support modularity, abstraction and encapsulation • C++ combines aspects of both
  • 10. 10 Low-level C/C++ #include <stdlib.h> extern ssize_t write(int, const void *, size_t); int main() { write(1, "Hello world!n", 13); } 0: 1b 00 00 00 sethi %hi(0x0), %o5 4: 82 10 00 0f mov %o7, %g1 8: 92 03 60 00 add %o5, 0, %o1 c: 90 10 20 01 mov 1, %o0 10: 94 10 20 0d mov 13, %o2 14: 40 00 00 00 call 0x14 18: 9e 10 00 01 mov %g1, %o7 C code Assembly code
  • 11. 11 High-level C++ #include <iostream> int main() { std::cout << "Hello world!" << std::endl; } • Easier to understand this program’s purpose: to send text and end-of-line to output device • No need for device descriptors, computing text length, or escape sequences • Being programmer-friendlier carries a cost: assembly code is nearly 4 times as long!
  • 12. 12 A Few Buzzwords • Modularity: the extent to which a program is decomposed into separate modules, thus simplifying design • Abstraction: the practice of reducing or factoring out details so that one can focus on only a few concepts at a time • Encapsulation: hiding the design of a task from the rest of the application, thus protecting it from changes
  • 13. 13 What C++ Offers • All of the power and efficiency of C (which is a subset) • Object-oriented programming (though not truly an object-oriented language) • Generic programming, through templates • Definition and extension of operators • Freedom to use paradigm of choice
  • 14. 14 Why Not Just Use MATLAB? • MATLAB is useful for proof-of-concept, but not for release-grade software • Its language is interpreted, not compiled into machine code • Only offers a subset of the functionality of a compiled language such as C++ • This lack of flexibility significantly, and adversely, impacts usability and performance
  • 15. 15 Examples of Drawbacks • MATLAB uses LAPACK and BLAS for its low-level linear algebra operations • Use of other libraries is much more difficult and less efficient • Forced to use MATLAB’s data structures for dense and sparse matrices, or other data • Lack of control over how data is accessed results in needless copying
  • 16. 16 Effective Software Engineering • Involves much more than just designing and implementing algorithms • Criteria for a program’s usefulness: – Does it accomplish its intended task, and if so, with what limitations? – How efficient is it, in the given computing environment? – How robust is it? Does it handle adverse conditions gracefully?
  • 17. 17 Hard Lessons • The sooner you start writing code, the longer it takes you to finish • Untested code will almost always fail • What works today can be broken tomorrow • The first person to use your code will input the one case that it doesn’t handle • Document code well, because your code can be unintelligible, even to you
  • 18. 18 Sound Programming Practices are Essential! • In 1991 Gulf War, US Patriot missiles intercepted Iraqi SCUD missiles by estimating velocity = distance / time • Time interval obtained by subtracting times at which position was determined • Times measured as seconds since tracking devices first activated in the field
  • 19. 19 Tracking SCUD Missiles Correct Incorrect Source: U.S. GAO Report
  • 20. 20 Little Details Aren’t Really Little • Time values large, but close together, so subtraction inaccurate, due to catastrophic cancellation • Velocity estimates useless, so missile’s position could not be determined • Interception failed, led to 28 deaths • What is a simple remedy?
  • 21. 21 Next Time • Overview of C++: – History – Design • How to write and run C++ programs – Windows – UNIX/LINUX • Understanding simple C++ programs