1 / 40

Programming Fundamentals 1 st lecture

Programming Fundamentals 1 st lecture. Content. Steps of solving problems – steps of writing a computer program Languages used when programming The alogirithm The specificaion Languages describing and algorithm – structogram Coding a program – programming tool. Steps of solving problems.

trentb
Download Presentation

Programming Fundamentals 1 st lecture

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming Fundamentals1st lecture

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

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

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

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

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

  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. The Algorithm Usage of drink dispensing machine: Choose the drink! Insert 1€! Press the proper button! Repeatlook at the glass!Until the drink runs out! Get the dring! Drink it! New element: Repetition based on a condition

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

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

  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. Specification Input data (identifier, domain set, unit) What we know about the input (precondition) Results (identifier, domain, …) The rule how to calculate the result (post condition) Requirements against the solution Restrictions Definitions of the applied notions

  13. Specification Specification has to be Exact, full Short, compact, formalized Expressive, understandable Specification tools Text description Mathematical formulas

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

  15. Example: triangle(algorithm) Algorithm: Comment: Later we will not include In and Out in our algorithms

  16. Example: triangle(algorithm) Anotheralgorithm(without In and Out): We can introducehelper (internal, own) variables.

  17. Example: quadratic equation(specification) Problem: Let’s specify one root of a quadratic equation! The equation is: ax2+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. Example: quadratic equation(specification) Specification1: Input: a,b,c:Real Output: x:Real Precondition: – Post condition1: ax2+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. Example: quadratic equation(specification) Specification2: Input: a,b,c:Real Output: x:Real Precondition: a0What if we allowed? Post condition2: Open questions: Is there always a solution? Is there only one solution?

  20. Example: quadratic equation(specification) Extend the output: Output: x:Real,exists:Boolean Post condition: exists=(b24*a*c) andexists  Open question: Is there only one solution? – homework

  21. Example: quadratic equation(specification) Algorithm: I N True way False way

  22. Example: quadratic equation(specification) Algorithm in another representation: ProgramQuadraticEquation: d:=b2-4*a*c exists:=d≥0 Ifexiststhen Program end.

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

  24. Structogram(and pseudo code) Sequence: Fork (2way): Fork (more): Statement1 Statement2 IfConditionthenStatements1else Statements2End if ForkIn case Conition1:Statements1In case Conition2:Statements2 … …OtherwiseStatements otherwiseEnd fork

  25. Structogram(and pseudo code) Loops: How to draw structogram: Text editor / spreadsheet Specific tools (e.g. NSD) Loop whileConditionStatementsEnd loop LoopStatementsUntilConditionEnd loop Loopi=from 1 to nStatementsEnd loop

  26. Coding(programming tool) Framework (tool): Code::Blocks Download: www.codeblocks.org Installation: easy

  27. At first startup: Choose compiler Coding(programming tool)

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

  29. Steps of usage: workspace of project on the disk Coding(programming tool) project name project root folder

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

  31. Further steps of usage: Choose compiler Finalize Coding(programming tool) compiler development version? debug dirs final version? final version dirs

  32. Our environment: on the disk: in framework: Coding (programming tool) browse program

  33. Our environment: on disk: in framework: Coding(programming tool)

  34. Compiling our first program Coding(programming tool) Szlávi-Zsakó: Programozási alapismeretek 1.

  35. The output of compilation: on the disk: Codeing(programming tool) Szlávi-Zsakó: Programozási alapismeretek 1.

  36. The output of compilation: on the disk: Coding(programming tool)

  37. Our first program: the content ofmain.cpp : Coding(programming tool) #include <iostream> usingnamespace std; intmain() { cout << "Hello world!" << endl; return 0; }

  38. The project source file: The content offirstProg.cbp: Coding(programming tool) (mily meglepő!)

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

  40. Programming FundamentalsEnd of 1st lecture

More Related