1 / 48

Fundamentals of problem solving

Learn the steps in creating and running programs, system development, common errors in coding, and key tips in program development process. Includes compiling, linking, and executing programs.

bettyer
Download Presentation

Fundamentals of problem solving

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. Fundamentals of problem solving Unit-iii

  2. Contents • Creating and Running Programs • System Development • Program Development • Tips and Common Errors

  3. Creating and Running a program There are 4 steps in this process • Writing and editing a program • Compiling the program • Linking the program with the required library modules • Executing the programs

  4. Building a c-program #include<stdio.h> int main ( void) { …. } //main Text Editor Programmer Source 00110 100 10101 010 ………….. 01001 011 Compiler Object 0010100110 100 0101010101 010 …………………… 01010101001 011 Linker Executable Library Runner Results

  5. Writing and Editing programs • The software used to write programs is known as a text editor. • It is used to enter, change and store character data. • The completed program is known as a source file which is input to the complier

  6. Compiling the programs • The job of the complier is to translate source file to machine level language. • The C complier has two separate programs * The preprocessor * The translator *The preprocessor scans for preprocessor commands and makes substitution in special library codes. *The translator takes preprocessed code and results a object module is the code in machine language

  7. Linking & Executing programs • The linker assembles input/output processes and mathematical library functions ,ours and the system’s into final executable program. • To execute a program, we use an operating system command such as run, to load the program into primary memory (loader) and execute it.

  8. System Development • To develop a system using our program which determines the overall quality and success of our program. • The developed system should be * Efficient *Error-free * Easy to maintain

  9. System Development Life cycle • Interrelated phases to build a modern programming projects. • One very popular development life cycle is water fall model. • Depending on the company and type of the software being developed ,this model consists of between five and seven phases.

  10. Waterfall Model

  11. Program Development • Program development is multi step process that requires to • Understand the problem • Develop a solution • Write a program • Test the program

  12. Understand the Problem • Read the requirements carefully • Discuss with user and systems analyst • Ask questions to confirm our understanding

  13. Develop the solution • Once we fully understand the problem, we need to develop our solutions. • Three tools used to develop the solution 1) Structure charts 2) Pseudo code 3) flowcharts

  14. Structure charts • A structure chart , also known as Hierarchy chart, shows functional flow through our program

  15. Structure Chart of Dayananda Sagar Institutions

  16. Pseudo code • English like statements that follow loosely defined syntax and are used to convey the design of the algorithm

  17. Algorithm Algorithm is a step by step procedure to solve the given problem • Characteristic of algorithm • Precise: An algorithm must be simple. • Maintain Order: The instruction is each and every step in an algorithm • are in specific order. • Finite & Correct: They must solve the problem in certain finite number • of steps and produce the appropriate results. • Termination: Each algorithm should terminate.

  18. Write an algorithm to add two numbers

  19. Write a algorithm to find the addition of two numbers Step 1: [Input two numbers] read a, b Step 2: [calculation] result=a + b Step 3: [Display the output] write result or print result Step 6: [Finish]

  20. Write an algorithm to exchange two numbers

  21. Write a algorithm to exchange two numbers Step 1: [Input two numbers] read a, b Step 2: [perform exchange] t=a a=b b=t Step 3: [Display the output] write a , b Step 6: [Finish]

  22. Write an algorithm to calculate area of rectangle .

  23. Algorithm to get area of rectangle. Step 1: [Input length and breadth of the rectangle] Read length, breadth Step 2: [Find the area to the rectangle] Area=length*breadth Step 3: [Output the result] Write area Step 4: [Finished] Exit

  24. More examples • Area of circle( pi*r*r) • Average of Three Numbers • Arithmetic operations • Simple Interest (p*t*r/100) • Compound Interest ( p(1+(r/100))T-p)

  25. Write an algorithm to calculate area of circle.

  26. Algorithm to get area of circle. Step 1: [Input radius of the circle] Read radius Step 2: [Find the area of circle] Area=length*breadth Step 3: [Output the result] Write area Step 4: [Finished] end

  27. Algorithms To find the largest of two numbers To find the largest of three numbers Largest of 3 numbers Find whether given number is odd or even Find whether given number is positive or negative Find the factorial of given number Find the sum of N natural numbers

  28. Flow Chart • A flow chart is a program design tool in which standard graphical symbols are used to represent that logical flow of data through a function.

  29. Flow Chart The graphical or pictorial representation of sequence of steps involved in the solution for a particular problem is called flow chart. Start / stop Input / Output Computing connect Loop Decision Flow

  30. Write a algorithm & flowchart to find the addition of two numbers Start Step 1: [Input two numbers] read a, b Step 2: [calculation] result=a + b Step 3: [Display the output] write result or print result Step 4: [Finish] Read a,b Result= a+b Print result Stop

  31. * Write an algorithm and flowchart to find largest of 3 numbers

  32. Largest of given three numbers • Step1: [Read three numbers] • Read A, B, C • Step2: [Compare A and B] • if(A>B) go to step3 otherwise go to step4 • Step3: [Compare A> C] • if(A>C) write A is largest and go to step 5 otherwise write C is largest and go to step 5 • Step4: [Compare B> C] if(B>C) write B is largest and go to step 5 otherwise write C is largest and go to step 5 • Step5: [Finished] • Stop

  33. Flow chart for largest of three numbers

  34. Write the program • Start with the top box on the structure chart and work our way to bottom, this is knows top-down implementation • It is a very easy and natural way to write programs

  35. Test the program • Checking the results for all type of inputs • Program testing can be very tedious and time consuming part of program development. • There are two types of testing • Blackbox Testing • Whitebox Testing

  36. Blackbox Testing • Testing the program without knowing what is inside it and without knowing how it works. • Example:- Testing the code written by other user

  37. Whitebox Testing • Testing the program knowing what is inside it and knowing how it works. • Example:- Testing the code written by yourself

  38. Tips and Common Errors • Become familiar with the text editor . • Learn different techniques and shortcuts in a text editor will save time in the future. • Become familiar with complier commands and keyboard shortcuts. • Read the complier’s error messages. • Become familiar with the types of error messages and their meanings will be a help as you learn C. • Remember to save and compile your program each time when you make changes and corrections. • Run your program many times with different sets of data to be sure it does what you want. • Make sure that you understand the requirements and take the time to design a solution before you start writing code.

  39. Programming Language

  40. Programming Language • Programming languages bridge the gap between human thought processes and computer binary circuitry. • Programming language: A series of specifically defined commands designed by human programmers to give directions to digital computers. • Commands are written as sets of instructions, called programs. • All programming language instructions must be expressed in binary code before the computer can perform them.

  41. The Role of Languages in Communication • Three fundamental elements of language that contribute to the success or failure of the communication cycle: • Semantics • Syntax • Participants

  42. Computer language: Refers to the specific command you wish the computer to perform. Input, Output, Print Each command has a very specific meaning. Semantics: Refers to meaning

  43. Computer language: Refers to rules governing exact spelling and punctuation: Formatting, repetition, subdivision of tasks, identification of variables, definition of memory spaces. Computers do not tolerate syntax errors. Syntax: Refers to form, or structure.

  44. Computer language: People use programming languages. Programs must be translated into binary code. Computers respond by performing the task or not! Participants: • Human languages are used by people to communicate with each other. • Programming languages are used by people to communicate with machines.

  45. The C-Language

  46. C History • Developed between 1969 and 1973 along with Unix • Designed by Dennis Ritchie & Martin Richards • Evolved from B, which evolved from BCPL Martin Richards Dennis Ritchie

  47. Generation of Languages BCPL (B) C C++ JAVA .NET C#

  48. Pieces of C • Types and Variables • Definitions of data in memory • Expressions • Arithmetic, logical, and assignment operators Statements • Sequences of conditional, iteration, and branching instructions • Functions • Groups of statements and variables invoked recursively

More Related