1 Programming
1 Programming
Programming is learned
by writing programs.
– Brian Kernighan
Abstract
Stroustrup/Programming/2024/Chapter1 3
Overview
Stroustrup/Programming/2024/Chapter1 4
This is a course
• In Programming
• For beginners
• who want to become professionals
• i.e., people who can produce systems that others will be happy
using
• who are assumed to be bright
• Though not (necessarily) geniuses
• who are willing to work hard
• Though do need sleep occasionally, and take a normal course
load
• Using the C++ programming language
Stroustrup/Programming/2024/Chapter1 5
Not!
• A Washout course
• “If you can get into the science/engineering parts of a
university, you can handle this course”
• A course in
• The C++ programming language
• For students
• who want to become language lawyers
• We try not to get bogged down in technical obscurities
• who are assumed to be a bit dim and fairly lazy
• We try not to spoon feed
• Using
• Some untested software development methodologies and
a lot of unnecessarily long words
Stroustrup/Programming/2024/Chapter1 6
The Aims
• Teach/learn
• Fundamental programming concepts
• Key useful techniques
• Basic Standard C++ facilities
• After the course, you’ll be able to
• Write small colloquial C++ programs
• Read much larger programs
• Learn the basics of many other languages by yourself
• Proceed with an “advanced” C++ programming course
• After the course, you will not (yet) be
• An expert programmer
• A C++ language expert
• An expert user of advanced libraries
Stroustrup/Programming/2024/Chapter1 7
The Means
• Lectures
• Attend every one
• Notes/Chapters
• Read a chapter ahead (about one per lecture)
• Read the chapter again after each lecture
• Feedback is welcome (typos, bugs, suggestions,
etc.)
Stroustrup/Programming/2024/Chapter1 8
The Means (Cont.)
• Work
• Review questions in chapters
• Review “Terms” in Chapters
• Drills
• Always do the drills
• Always do the drills before the exercises
• Exercises
• Course specific
• Projects
• That’s where the most fun and the best learning takes place
• Quizzes
• Exams
Stroustrup/Programming/2024/Chapter1 9
Cooperate on Learning
• Except for the work you hand in as individual contributions, we
strongly encourage you to collaborate and help each other
• If in doubt if a collaboration is legitimate: ask!
• Don’t claim to have written code that you copied from others
• Don’t give anyone else your code (that you are to hand in for a grade)
• When you rely on the work of others, explicitly list all of your sources – i.e.,
give credit to those who did the work
• Don’t study alone when you don’t have to
• Form study groups
• Do help each other (without plagiarizing)
• Go to your TA's office hours
• Go prepared with questions
• The only stupid questions are the ones you wanted to ask but didn’t
Stroustrup/Programming/2024/Chapter1 10
Rough course outline
• Part I: The basics
• Types, variables, strings, console I/O, computations, errors, vectors,
functions, source files, modules, classes
• Part II: Input and Output
• Text I/O
• Graphical output
• Graphical User Interface
• Part III: Data structures and algorithms
• Free store, pointers, and arrays
• Lists, maps, sorting and searching, vectors, templates
• The STL
• Part IV: Broadening the view (Web only, possibly just self study)
• Software ideals and history
• Text processing, numerics, embedded systems programming, testing, C,
etc.
Stroustrup/Programming/2024/Chapter1 11
Rough course outline (Cont.)
• Throughout
• Program design and development techniques
• C++ language features
• Background and related fields, topics, and languages
Stroustrup/Programming/2024/Chapter1 12
Promises
• Detail: We will try to explain every construct used in this course in
sufficient detail for real understanding
• There is no “magic”
• Utility: We will try to explain only useful concepts, constructs, and
techniques
• We will not try to explain every obscure detail
• Completeness: The concepts, constructs, and techniques can be
used in combination to construct useful programs
• There are, of course, many useful concepts, constructs, and techniques
beyond what is taught here
Stroustrup/Programming/2024/Chapter1 13
More Promises
• Realism: The concepts, constructs, and techniques can be used
to build “industrial strength” programs
• i.e., they have been used to …
• Simplicity: The examples used are among the simplest realistic
ones that illustrate the concepts, constructs, and techniques
• Your exercises and projects will provide more complex examples
• Scalability: The concepts, constructs, and techniques can be
used to construct large, reliable, and efficient programs
• i.e., they have been used to …
Stroustrup/Programming/2024/Chapter1 14
Feedback request
Stroustrup/Programming/2024/Chapter1 15
Why programming?
• Our civilization runs on software
• Most engineering activities involve software
Stroustrup/Programming/2024/Chapter1 16
Ships
• Design
• Construction
• Management
• Monitoring
• Loading
• Engine
• Hull design
• Scheduling
• Pumps
• Route planning Stroustrup/Programming/2024/Chapter1 17
Aerospace
• Communication
• Control • Signal processing
• Display • “Gadget” control
• Routing • telemetry
Stroustrup/Programming/2024/Chapter1 18
Cars
(distributed computers with wheels)
Stroustrup/Programming/2024/Chapter1 21
Commerce, finance, and governance
• Banks
• Stock exchanges
• Currency exchange
• Social services
• Medical records
• Taxes
• Online stores
Stroustrup/Programming/2024/Chapter1 22
Medicine
• Scanners • Genomics
• Vaccine development and • Materials design
production • Simulations
• Analysis (blood, tissue) • ???
• General research Stroustrup/Programming/2024/Chapter1 23
Energy
• Control
• Monitoring • Communications
• Analysis • Visualization
• Design • Manufacturing
Stroustrup/Programming/2024/Chapter1• Transport 24
Science
• Physics
• Biology
• Engineering
• Astronomy
Stroustrup/Programming/2024/Chapter1 25
Foundations
• Microelectronics
• Computers
• Routers • Operating
systems
• Networking
• Browsers
• Manufacturing
• Virtual machines
• Wireless
Stroustrup/Programming/2024/Chapter1 • Search engines
26
Laptops, tablets, workstations, servers, …
Stroustrup/Programming/2024/Chapter1 27
Why C++ ?
• You can’t learn to program without a programming language
• The purpose of a programming language is to allow you to
express your ideas in code
• C++ is the language that most directly allows you to express
ideas from the largest number of application areas
• C++ is the most widely used language in engineering areas
• http://www.stroustrup.com/applications.html
• Other languages often use C++ for computation intensive
tasks
• E.g., Python doing AI
• The implementation of many languages are C++ programs
• E.g., Java and Javascript
Stroustrup/Programming/2024/Chapter1 28
Why C++ ?
• C++ is precisely and comprehensively defined by an ISO
standard
• And that standard is almost universally accepted
• The most recent standard is ISO C++ 2023
• C++ is available on almost all kinds of computers
• Programming concepts that you learn using C++ can be
used fairly directly in other languages
• Including C, Java, C#, and (less directly) Fortran
Stroustrup/Programming/2024/Chapter1 29
Where is C++ Used?
• Just about everywhere
• C++ plays a major part in all the examples and photos used here
• See www.stroustrup.com/applications.html
• Note: a large system is not written exclusively in one language
Stroustrup/Programming/2024/Chapter1 30
A first program – complete
// a first program:
// the std:: says that cout comes from the standard library
Stroustrup/Programming/2024/Chapter1 32
// main( ) ‘s result indicate success (value 0) or failure (non zero value)
A first program – use while
// a first program:
learning
#include “PPP.h” // get PPP support
Stroustrup/Programming/2024/Chapter1 35
Hello world
• It’s almost all “boiler plate”
• Only cout << "Hello, world!\n" directly does anything
• That’s normal
• Most of our code, and most of the systems we use simply exist to make
some other code elegant and/or efficient
• “real world” non-software analogies abound
• “Boiler plate,” that is, notation, libraries, and other support is
what makes our code simple, comprehensible, trustworthy, and
efficient.
• Would you rather write 1,000,000 lines of machine code?
• This implies that we should not just “get things done”; we
should take great care that things are done elegantly, correctly,
and in ways that ease the creation of more/other software:
Style Matters!
Stroustrup/Programming/2024/Chapter1 36
C++ source code
Compilation and linking
C++ compiler Object code
Stroustrup/Programming/2024/Chapter1 41