C++ 020 Basics
C++ 020 Basics
Im
pl_
Trip
dis
tan
ce_
A UDI C
Im
pl_
Trip
dis
tan
ce
Pro
gra
m a
D
ata
_Ad
apte
r l
c
calc_ value():void u
disp lay():void Imp_Triptime_Alarm l
ignition_on():void Im
pl_
Trip
tim
e_Ala
rm_
A UDI a
ig
nitio
n_o
ff(
):vo
id t
i
rese
t():void Im
pl_
Trip
tim
e o
< <?>>e ep ro
m _
chang
ed():... n
need_reca
lc():bool
Im
p l_
M e a
n_ Cons
umption_
A UDIS
Im
pl_
M e
an_
C o
nsu
m p
tio
n e
Impl_Average_Speed
write
_str(
)
<
<draft>
>write_
sym
bol()
<
<cto
r>>in
it(
)
D
i
s
Dis
pla
y_Trip
tim
e_Ala
rm_
A UDI p
D
is
pla
y_Trip
tim
e_Ala
rm l
Disp
lay_
Valu
e a
OSEK-VGC y
(
fro
m SYS) sh
ow(va
lue:d
w o
rd):vo
id D isp
lay_Mean_
C o
nsumtio n
_AUDI
Dis
pla
y_Me
an_
C o
nsu
m p
tio
n S
e
c
t
i
OSEK-win
32 Dis
p la
y_ Cu
rre
nt_Cons
ump tion
_AUDI
o
Dis
pla
y_Cu
rre
nt_
C o
nsu
m p
tio
n
(
fro
m SYS) n
Dis
pla
y_Trip
dis
tan
ce_
A UDI
Dis
pla
y_Trip
dis
tan
ce
c
on s
ole
-win
3 2
(
from SYS)
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 2
A brief history of computer and programming language development
Ada Lovelace’s first program
Turing machine
Software Engineering
Software development process
Modelling
Major drivers
Increase developers productivity
Improve project reliability (costs / schedule)
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 3
With the availability of more powerful computers, software
development could be supported beyond program editing and
compilation
After the age of punched cards, programmers could edit the
programs at a terminal, and invoke the tool chain (compiler,
assembler, linker) from the command line (maybe with the help of
batch processing e. g. using a tool like make)
From 1984 on, the text editor Emacs became generally available
Invocation of tool chain integrated in editor's user interface
Automatic jump from compiler error to source code
Syntax highlighting
Available on a monochrome text terminals (developer's standard
environment at that time)
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 4
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 5
With more computer power becoming available (notably PCs)
developer's tools became more powerful
Colour
Graphics based instead of text based (enabling e. g. tool tips)
Code completion
On-the-fly code grammar checks and code analysis
Improved debugging environment
CASE Tools (Computer-aided software engineering) for support
beyond programming
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 6
2010
Microsoft: IBM
.NET
2005 Borland:
Together, Caliber, Telelogic
Starteam Eclipse.org
2000
Togethersoft: Rational: iLogix: Telelogic:
Together Rose, RoseRT Rhapsody DOORS, Tau
1995
Borland: Microsoft: IBM: Rational: Continuus:
C++ Builder MSVC Eclipse Clearcase Synergy
1990 Borland:
Turbo Pascal
Turbo C
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 7
Programming Environment
Eclipse
UML Tool (Graphical Modelling)
Borland Together Architect 1.1
Lab Exercises
All tools available in “Lernzentrum”
http://www.eit.h-da.de/studium-eit/lernzentrum/index.htm
Account provided to [email protected]
Option: install on your PC
Download from
http://skript.eit.h-da.de/wiki/index.php/Software_Engineering_Tools
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 8
A first C++ project (looking like C)
Life demonstration:
Setting up a project in Eclipse
Getting “Hello world” up and running
Compiling
Debugging
Life demo
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 9
Create a directory for your workspace
Create an empty project
Write some code
Compile it
Et voilà, either
the compiler produces an error message (usually it does)
or the program runs as expected (hopefully at the end of the
course)
or the program compiles but crashes (really nasty)
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 10
Editor
Project
Explorer
Console
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 11
Tool Chain “MinGW (GIT)” is “MinGW”
plus linker options for improved output
behaviour
Next use context menu of project to create
“New... | Source Folder” named “myCode”
Then use context menu of source folder to
create “New... | Source File” named “main.cpp”
Enter your source code
Use context menu of project to build and run the project
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 13
Not really C++, but shows full backward compatibility
#include "stdio.h"
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 14
Remember software engineering? Requirements
analysis and
definition
System and
software design
A program may
simulate an aspect of reality Implementation
and unit testing
provide functions to a user
configure generic hardware for a specific purpose Integration and
system testing
…
Before starting to program, there should be a thorough
understanding of the program's purpose (requirement analysis)
and a design
Any serious project involves several people, the requesters usually
not being the programmers
How can we make sure that requirements of the requesters are
properly understood?
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 15
You have to develop a device which has 12 buttons
It is operated by 3 AA batteries
The oscillator shall operate with frequencies between 300kHz and
3000kHz
The LCD display has a resolution of 300 x 150 pixel.
…
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 16
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 17
There are several ways how to describe requirements
Textual
Pictures
Oral communication
Diagrams
Real and virtual prototypes
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 18
Challenge:
Do we have all requirements (Elicitation)
Did we understand the requirements (Analysis)
Do we have the requirements in such a format, that the
development team can work with them? (Specification)
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 19
Bittner and Spence, “Use cases, stated simply, allow description of
sequences of events that, taken together, lead to a system doing
something useful.”
Each use case describes how an actor will interact with the system
to achieve a specific goal
Easy to understand!
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 20
Describes one activity an actor performs with the system.
Content:
Title
Description
Normal behavior
Exception behavior
Precondition
Post condition
Reference to requirements
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 21
Example
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 22
Anybody who has an interest in the system
Can be humans or technical systems
Example
Novice End-User
Expert End-User
Other developer using your component
Other ECU (Electronic Control Unit) communicating with your ECU
(e.g. network requesting an ACK)
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 23
UML defines a graphical notation for use cases
The use case is represented by an eclipse with the use case's name
in it
The actor is represented by a small figure with the role's name under
it
An association line links actors with the use cases that they may
perform
In addition there may be relationships between use cases
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 24
Include <<include>>
A given use case may include another. The first use case often
depends on the outcome of the included use case. This is useful for
extracting truly common behaviors from multiple use cases into a
single description.
<<extend>>
Extend
A given use case (the extension) may extend another. This can be
useful for dealing with special cases (when A extends B, A is a special
case of B), or in accommodating new requirements during system
maintenance and extension.
Generalization
In the third form of relationship among use cases, a
generalization/specialization relationship exists. A given use case
may be a specialized form of an existing use case. This resembles
the object-oriented concept of sub-classing.
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 25
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 26
Some rules:
Every actor is connected to at least one use case (direct or indirect)
Every use case is connected to at least one actor (direct or indirect)
Use cases are descriptive - every use case has a verb and a noun
Actors are explicit – a “User” is not a good actor
Focus is to get an overview of the system, not the discussion of
details
Technical language is avoided
Architectural aspects should be avoided
Focus: Input / Action relations
Not suited e.g. for non functional or algorithmic requirements
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 27
The use case diagram is the first of several UML diagrams that we
will learn about during this lecture
To support creation and maintenance of diagrams we use the tool
“Together”
Life demo
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 28
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 29
Use “File | New … | New Project” to create a new project
Click “Next”
As location, choose the “<prj>/myCode” directory of the existing
C++ project (created with Eclipse)
Click “Next”
Adapt paths and set options as shown below
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 30
Use context menu (right mouse click) of “<default>” and to create a
new package
Rename package to “model”
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 31
Use context menu of “model” and “New | Diagram ...”
Select “Use Case”
Draw diagram
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 32
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 33
Eclipse Environment
Setting up a project
Writing some code
Adding some files
Compiling
Debugging
Running
Use cases
First Glance at Together
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 34
Install Eclipse or use a university PC
Generate a “Hello world” project
Calculate the square numbers from 1 to 10 and generate an output
1x1=1
2x2=4
...
Calculate 10 values of sin in the range between 0 and 2*Pi (check the
math library)
Advanced Programming Techniques and Engineering Processes, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 14/10/15 35