Presentation is loading. Please wait.

Presentation is loading. Please wait.

Imperative Programming

Similar presentations


Presentation on theme: "Imperative Programming"— Presentation transcript:

1 Imperative Programming
A 5 ECTS course for for first year students Based on “C”

2 Goal Learn how to program with an imperativ language. “C”
Do it in real life on your PC Install of SW like compilers Get things up and running Use it in P1 project if possible Get an programming skill platform for the next languages to come to you (java, C++,C#,Python,Php,matlab,...)

3 Goal II

4 Rough layout of course Basic C and programming
Embedded programming on Arduino Ask your supervisor for an Arduino pr group And maybe buy one you self (200 DKK)

5 Basic C part On a tradional basis – editor,compiler, run an executable
No fansy GUI etc GUI based: Eclipse,... The war of operating systems Mac, Windows XP/V/7, Linux, embedded We try to cover it all Please help your neighbour

6 Embedded part Arduino based AVR micro controller 1/2/4/8 kByte of RAM
Up to 128 kByte of flash for program code IO Up to 14 channels 10 bit analog input Up to 7 or so analog output (by PWM) Digital in and out – a lot Serial (rs232),i2c,.. Use nearly no current (use a battery) Cheap

7 Arduino's

8

9 It is your choice To be here We are here to help (you)

10 TODAY Chapter 1 Chapter 2 Exercises

11 Den gang far var ung ... Var der rigtige kompjutere til

12

13 Characteristics Difficult to program Difficult to run programs on
High salaries Died after the PC arrived ? 64 kByte Ram 4.77 Mhz processor (today 1000 times more) 1 or kByte floppy drive

14 The return of the main frame ?!

15 Very simple model GUI IO NET IO OS HW

16 From code to executable
Editor – write program in language (C,...) Compile it to binary for a specific architecture (PC,ARM,...) Link it with libraries for specific platform windows,linux,arduino,... Different platforms different facilities/possibilities Save executable In filesystem (on “disk”) In flash memory Loadable via net ...

17 Let's do it /* A simple Program */ #include <stdio.h> int main(void) { printf(“Hello World\n”); }

18

19

20 SW Development method Specify problem requirements Analyze the problem
Design the algorithm to solve the problem Implement the algorithm Test and verify the completed program Maintain ... and update the program Very simplified ...

21

22 Fig 2.1 ... on the comming slides
C is en general a very small language No fancy graphics, GUI, network,... All extra is by purpose on a specific platform And is supplied in libraries/part of Operating Sys

23 Only simple types: Integers : 16/32/64 bit wide dep of architecture Floating point: IEEE given character/byte 8 bit void (nothing) ...

24 /* include statements – for extending “language”*/
#include <stdio.h> /* standard input/output stuff */ /* C can only + - * / /* the rest comes as library / “extensions” */ Sin, cos, atan, printf, file I/O, GUI (!),...

25 double float_1; int int_1, int_2; /* upper case is not equal lower case */ int main(void) { int_1 = 3; int_2 = int_1 *3 – 44; float_1 = int_1; } /* p.. of cake */

26 Beware about conversions
/* declaration part */ int i_1, i_2, i_3; double float_1; i_1 = 3; i_2 = 4; i_3 = i_1 / i_2; float_1 = i_1 / i_2; /* ??? */

27 int int1, int2; ... int2 = 12785; Int1 = int2 ; /* an assigment is a copy !!! */

28 stdio.h Need something one the computer screen ...
Output like print “hello ...” Input like “read_an_integer_from_keyboard

29 stdio.h - output printf (“hello”); printf (“hello\n new line”);
printf(“hello – I have %i legs “ , 2 ); printf(“ hello – I have %&i legs” , int_1) ; %i : integer %f : floating point %c : character + variants : %3i Integer written out as xxx

30 printf (“ %i %f %c”, 3, , 3 ); int i,j,k; i = 3 ; j = 4; k = 4444; printf(“%i%i%i”, i,j,k); /* writes out */ printf(“%i %i %i”, i,j,k); /* writes out */

31 stdio.h - input read from keyboard No error handling today
I ask for an integer you type dumpkopf ...

32 stdio.h - scanf int a_number; scanf ( “%i “, & a_number); /* read & as location or address */ /* i for int, f for float c for character – as printf*/

33 int i1,i2,i3; scanf(“%i %i %i”, & i1, &i2, &i3 ) ;

34 Operator Hierarchy See inside first page in book and page 96..
Level x Level x-1 * / ... 2 + 5 * = ??? I guess

35 (())(()) Use ( ) to clarify: ((2*3) +5) / (3+7)
You can never use to many – only to few ...

36

37


Download ppt "Imperative Programming"

Similar presentations


Ads by Google