Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Fundamentals 1 st lecture. ELTE 2/42 2014. 12. 11.2014. 12. 11.2014. 12. 11. Content  Steps of solving problems – steps of writing a computer.

Similar presentations


Presentation on theme: "Programming Fundamentals 1 st lecture. ELTE 2/42 2014. 12. 11.2014. 12. 11.2014. 12. 11. Content  Steps of solving problems – steps of writing a computer."— Presentation transcript:

1 Programming Fundamentals 1 st lecture

2 ELTE 2/ Content  Steps of solving problems – steps of writing a computer program Steps of solving problems  Languages used when programming Languages used when programming  The alogirithm The alogirithm  The specificaion The specificaion  Languages describing and algorithm – structogram Languages describing and algorithm  Coding a program – programming tool Coding a program

3 ELTE 3/ Steps of solving problems Example: build a house  What can you see from the process?  What is behind? 1. Assess the needs (aspects: size of family, their idea, money) 2. Design (plan, building material needs, engineer) 3. Organize (schedule, contractor…) 4. Building operations (supply material, building / contractor…) 5. Put in practice (have a look – how fancy, try out – how good) 6. Move in, live in (make corrections, detect problems)

4 ELTE 4/ Steps of creating a computer program 1. Specify (from what?, what?)  specification 2. Design (with what?, how?)  data and algorithm desc. 3. Coding (how (computer)?)  program source code representation + implementation 4. Testing (any bugs?)  error list (diagnosis) 5. Search for bugs (where is the bug?)  bug location 6. Correction (how is it correct?)  correct program 7. Quality assurance (Q&A), efficiency (can we make better?, how?)  good program 8. Documenting (how does it work? etc…)  usable program 9. Usage, maintenance (still works?)  durable program

5 ELTE 5/ Language tiers Living language = English  Specification  Algorithm description  Programming language  Computer language (machine code) Converge the languages (English  Computer)

6 ELTE 6/ The Algorithm Usage of drink dispensing machine: 1. Choose the drink! 2. Insert 1€! 3. Press the proper button! 4. Wait until the drink runs out! 5. Get the dring! 6. Drink it!

7 ELTE 7/ The Algorithm  Executable (interpreter exists)  Can be executed step by step  The steps themselves are also algorithms  Exactly defined, with given order of steps  The description is finite, however the execution time can be infinite

8 ELTE 8/ The Algorithm Usage of drink dispensing machine: 1. Choose the drink! 2. Insert 1€! 3. Press the proper button! 4. Repeat look at the glass! Until the drink runs out! 5. Get the dring! 6. Drink it! New element: Repetition based on a condition

9 ELTE 9/ The Algorithm Usage of drink dispensing machine: 1. Choose the drink! 2. If you have 1€ then Insert 1€! otherwise Insert 5 x 20 cents! 3. … New element: choice from two options, (can also be non-deterministic)

10 ELTE 10/ The Algorithm Insert 5 x 20 cents: 1. Repeat 5 times: Insert one 20 cents! New element: repeat given times

11 ELTE 11/ The Algorithm Structural elements of an algorithm:  Sequence (execute step by step)  Fork (choice from 2 or more activities based on condition)  Cycle (repeat given times, or until a condition turns true)

12 ELTE 12/ Specification 1. Input data (identifier, domain set, unit) 2. What we know about the input (precondition) 3. Results (identifier, domain, …) 4. The rule how to calculate the result (post condition) 5. Requirements against the solution 6. Restrictions 7. Definitions of the applied notions

13 ELTE 13/ Specification Specification has to be 1. Exact, full 2. Short, compact, formalized 3. Expressive, understandable Specification tools 1. Text description 2. Mathematical formulas

14 ELTE 14/ Example: triangle (specification) Problem: Is it true that given 3 numbers represent the side lengths of a right angle triangle? Specification: Real  Input: x,y,z:Real Logical  Output: possible:Logical  Precondition: x>0 and y>0 and z>0  Post condition: possible=(x 2 +y 2 =z 2 ) Comment: we suppose z is the length of hypotenuse

15 ELTE 15/ Example: triangle (algorithm) Algorithm : Comment: Later we will not include In and Out in our algorithms In: x,y,z [x>0 and y>0 and z>0] possible:=(x 2 +y 2 =z 2 ) Out: possible

16 ELTE 16/ Example: triangle (algorithm) Another algorithm (without In and Out): We can introduce helper (internal, own) variables. xx:=x 2 yy:=y 2 zz:=z 2 possible:=(xx+yy=zz)

17 ELTE 17/ Example : quadratic equation (specification) Problem: Let’s specify one root of a quadratic equation! The equation is: ax 2 +bx+c=0 Questions:  What is the solution? – output  What does it mean: „being a solution”? – post condition  Does there a solution exist? – precondition  Are we sure there is only one solution? – output/post condition

18 ELTE 18/ Example: quadratic equation (specification) Specification 1 : Real  Input: a,b,c:Real Real  Output: x:Real  Precondition: –  Post condition 1 : ax 2 +bx+c=0 Remark: this post condition does not provide us with information how to create the algorithm. No worries, let’s try again!

19 ELTE 19/ Example: quadratic equation (specification) Specification 2 : Real  Input: a,b,c:Real Real  Output: x:Real  Precondition: a  0 What if we allowed?  Post condition 2 : Open questions:  Is there always a solution?  Is there only one solution?

20 ELTE 20/ Example: quadratic equation (specification) Extend the output: Real, Boolean  Output: x:Real, exists:Boolean  Post condition: exists=(b 2  4*a*c) and exists  Open question:  Is there only one solution? – homework

21 ELTE 21/ Example: quadratic equation (specification) d:=b 2 -4*a*c exists:=d  0 exists? True way False way IN Algorithm :

22 ELTE 22/ Example: quadratic equation (specification) Algorithm in another representation: Program QuadraticEquation: d:=b 2 -4*a*c exists:=d≥0 If exists then Program end.

23 ELTE 23/ Languages for algorithms  Text description  Describe by sentences  Pseudo code  Describe with drawing  Flow chart  Structogram

24 ELTE 24/ Example flow chart

25 ELTE 25/ Structogram (and pseudo code)  Sequence:  Fork (2way):  Fork (more): Statement1Statement2 If Condition then Statements1 else Statements2 End if Statements2 End if Fork In case Conition1:Statements1 In case Conition2:Statements2 … … Otherwise Statements otherwise End fork Statement1 Statement2 Condition Statements1Statements2 Condition1Condition2…Otherwise Statements1Statements2…Statements

26 ELTE 26/ Structogram (and pseudo code)  Loops:  How to draw structogram:  Text editor / spreadsheet  Specific tools (e.g. NSD)NSD Loop while Condition Statements End loop Loop Statements Until Condition End loop Loop i=from 1 to n Statements End loop Condition Statements Condition Statements i=1..n Statements

27 ELTE 27/ Coding (programming tool)  Framework (tool): Code::Blocks  Download:  Installation: easy

28 ELTE 28/  At first startup: Choose compiler Coding (programming tool)

29 ELTE 29/  Steps of usage: 1. Create a project, the type determines the platform of you want to deploy to. Create a new project 2. sablon (template) választása: Console application Coding (programming tool)

30 ELTE 30/  Steps of usage:  workspace of project on the disk project name project root folder Coding (programming tool)

31 ELTE 31/  Further steps of usage:  workspace of project on the disk Project name Project root folder projektfájl- név Project file name with full path Coding (programming tool)

32 ELTE 32/  Further steps of usage:  Choose compiler  Finalize compiler development version? debug dirs final version? final version dirs Coding (programming tool)

33 ELTE 33/  Our environment:  on the disk:  in framework: browse program Coding (programming tool)

34 ELTE 34/  Our environment:  on disk:  in framework: Coding (programming tool)

35 ELTE Szlávi-Zsakó: Programozási alapismeretek 1.35/  Compiling our first program Coding (programming tool)

36 ELTE Szlávi-Zsakó: Programozási alapismeretek 1.36/  The output of compilation:  on the disk: Codeing (programming tool)

37 ELTE 37/  The output of compilation:  on the disk: Coding (programming tool)

38 ELTE 38/  Our first program:  the content of main.cpp : #include #include using namespace std; int main() { cout << "Hello world!" << endl; cout << "Hello world!" << endl; return 0; return 0;} Coding (programming tool)

39 ELTE 39/  The project source file:  The content of firstProg.cbp : (mily meglepő!) Coding (programming tool)

40 ELTE 40/  Run the exe in console:  „compilation” –  run (the last compiled) –  compile & run –  the console looks like this: Start the exe directly from file system! What do you experience? Why? returned value execution time The output of the program Coding (programming tool)

41 Programming Fundamentals End of 1 st lecture


Download ppt "Programming Fundamentals 1 st lecture. ELTE 2/42 2014. 12. 11.2014. 12. 11.2014. 12. 11. Content  Steps of solving problems – steps of writing a computer."

Similar presentations


Ads by Google