0% found this document useful (0 votes)
6 views

C++ 020 Basics

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

C++ 020 Basics

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Advanced Programming Techniques

Development Tools – Eclipse and Together


State_
Con
tro
l
Sig
nal_
Adap
ter C
Sta
te_
C o
ntro
l_AUDI o
o
n_s
ele
ct_
pre
v() n
in
it(
) o
n_select_ nex t() t
raise
_tick() o
n_tick() on_se le ct_ ne xt() r
raise
_select_ p rev() o
n_triptim e_ alarm () on_tick () o
raise
_select_ n e xt() 1 o
n_m em _level_ do w n() on_triptim e _a larm (
) l
raise
_trip time_ ala rm () o
n_m em _level_ up () on_s ele ct_ pre v (
)
S
raise
_ign ition
_ o n () o
n_ig nitio
n _ on () on_m em _ leve l_dow n(
)
e
raise
_ign ition
_ o ff() o
n_ig nitio
n _ off() on_m em _ leve l_up() c
raise
_res et_ pro g ram () o
n_reset_ pro gram () on_ig nitio n _off() t
raise
_res et_ all_ p ro gram s
() o
n_reset_ all_p rogram s() on_ig nitio n _on () i
raise
_e ep rom_ ch ang ed() o
n_ee p rom _ ch an ge d() re
se t_p ro g ram () o
raise
_m e m le
ve l_ d o
w n
() <
<cto
r>>in
it(
) re
se t_a ll_ p r
og ra m s
() n
raise
_m e m le
ve l_ u p
() Crea te( )

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

Prof. Dr.-Ing. Peter Fromm


c
t
i
Impl_Current_
C o
nsumptio
n_AUD I
Im
pl_
C u
rre
nt_
C o
nsu
m p
tio
n o
n

Impl_Average_Speed

Prof. Dr.-Ing. Michael Lipp clea


r()
Disp
lay_
Adap
ter
Impl_Range

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)

"cla sses"o flefth an d c


o loumnsinth
em id
delbu
ildu
pthetripcomputerc
ore
. T
hec las
sesontherig
htsideall
colo um na c
ta sin erfaceto All c
odehastobeinde
penden
tofma nufa
ctu
rer. b
elongtotheA UDIp a
ckage
ha re wa rea ndO S .T hey a
nda ren o
tparto
fthem ainc
la s
s
ared eclareda b s tractinthe TheIm pl_ X
XXa n
dD is
pla
y_X
XXc
las
sesd
esc
rib
ewh
atfla
vou
rso
fpro
gra
m h
iera
rchy.
m a incla sshiera rc hya nd fu
nctio
nalityareexp
e c
ted
im p le
m e ntedins eve ral Theya rein c
lud
edtos howw here
SY Sp a ckage s. t
h em ainc lasshie
rarc
hyh as tobe
expande dfo rmanufac
tore
r's
r
e qu
ir
e m en ts
 Development Tools
 IDEs
 Case-Tools
 Getting started Eclipse
 Use Cases
 Getting started Together

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

Together may only be used for studying purposes!

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"

int main(int argc, char* argv[]) {


printf ("Hello world!\n");
}
 Basic enhancement
 C++ provides new “streams” library for input and output
 Values are “shifted” to console output (cout)
 Values may also be shifted from console input (cin) into variables
#include <iostream>
using namespace std;
„Magic“, will be
int main(int argc, char* argv[]) { explained in detail
int i; later
cin >> i;
cout << "Value is " << i << endl;
}
 “Real” C++ will be introduced in next lecture

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.
 …

Usually, a system is best understood


by describing what a user can do with
it, rather than how it looks like

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

You need all of them!

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)

 Proven approach is to structure (functional) requirements as “Use


Cases”

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

 Title: Draw triangle


 Normal behavior: Draws a triangle on the screen and fills it with the
preselected color.
 Exception behavior: In case memory is not sufficient, a warning is
generated.
 Precondition: Sufficient memory (heap) is available
 Post condition: None
 Requirement references: R145-149

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

Remove path <prj>/myCode/diagrams


Remove path <prj>/myCode/src
Add path <prj>/myCode

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

You might also like