Chapters 1 & 2 Programming and Programs
Chapters 1 & 2 Programming and Programs
Abstract
Today, well outline the aims for this course and
present a rough course plan. Well introduce
the basic notion of programming and give
examples of areas in which software is critical
to our civilization. Finally, well present the
simplest possible C++ program and outline
how it can be made into running code.
Stroustrup/Programming/2015
Overview
Stroustrup/Programming/2015
This is a course
In Programming
For beginners
i.e., people who can produce systems that others will use
Stroustrup/Programming/2015
Not!
A Washout course
A course in
For students
Using
Stroustrup/Programming/2015
The Aims
Teach/learn
An expert programmer
A C++ language expert
An expert user of advanced libraries
Stroustrup/Programming/2015
The Means
Lectures
Notes/Chapters
Stroustrup/Programming/2015
Work
Exercises
Course specific
Projects
Thats where the most fun and the best learning takes place
Quizzes
Exams
Stroustrup/Programming/2015
Cooperate on Learning
Except for the work you hand in as individual contributions,
we strongly encourage you to collaborate and help each other
Dont claim to have written code that you copied from others
Dont give anyone else your code (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
Stroustrup/Programming/2015
Why C++ ?
You cant 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
Stroustrup/Programming/2015
10
Why C++ ?
C++ is precisely and comprehensively defined by
an ISO standard
Stroustrup/Programming/2015
11
12
Throughout
Note: Appendices
Stroustrup/Programming/2015
13
Promises
There is no magic
Stroustrup/Programming/2015
14
More Promises
Stroustrup/Programming/2015
15
Feedback request
Stroustrup/Programming/2015
16
Why programming?
Stroustrup/Programming/2015
17
Ships
Design
Construction
Management
Monitoring
Engine
Hull design
Pumps
Stroustrup/Programming/2015
18
Aircraft
Communication
Control
Display
Signal processing
Gadget control
Monitoring
Stroustrup/Programming/2015
19
Phones
Voice quality
User interfaces
Billing
Mobility
Switching
Reliability
Provisioning
Images
Stroustrup/Programming/2015
20
Energy
Control
Monitoring
Analysis
Design
Communications
Visualization
Manufacturing
Stroustrup/Programming/2015
21
PC/tablet/workstation
Stroustrup/Programming/2015
22
23
}
// quotes delimit a string literal
// NOTE: smart quotes will cause compiler problems.
//
so make sure your quotes are of the style " "
// \n is a notation for a new line
Stroustrup/Programming/2015
24
int main()
{
cout << "Hello, world!\n";
return 0;
}
// note the semicolons; they terminate statements
// braces { } group statements into a block
// main( ) is a function that takes no arguments ( )
//
and returns an int (integer value) to indicate success or failure
Stroustrup/Programming/2015
25
A second program
// modified for Windows console mode:
#include "std_lib_facilities.h"
int main()
{
cout << "Hello, world!\n";
keep_window_open();
return 0;
}
// without keep_window_open() the output window will be closed immediately
// before you have a chance to read the output (on Visual C++ 20xx)
Stroustrup/Programming/2015
26
Hello, world!
Compiler
Program development environment
Program execution environment
After you get it to work, please make a few mistakes to see how the
tools respond; for example
Stroustrup/Programming/2015
27
Hello world
Thats 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
Style Matters!
Stroustrup/Programming/2015
28
The compiler translates what you wrote into object code (sometimes called
machine code)
29
So what is programming?
Conventional definitions
Specifying the structure and behavior of a program, and testing that the
program performs its task correctly and with acceptable performance
30
Programming
Programming is understanding
31
Stroustrup/Programming/2015
32