480 likes | 531 Views
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.
E N D
Fundamentals of problem solving Unit-iii
Contents • Creating and Running Programs • System Development • Program Development • Tips and Common Errors
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
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
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
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
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.
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
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.
Program Development • Program development is multi step process that requires to • Understand the problem • Develop a solution • Write a program • Test the program
Understand the Problem • Read the requirements carefully • Discuss with user and systems analyst • Ask questions to confirm our understanding
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
Structure charts • A structure chart , also known as Hierarchy chart, shows functional flow through our program
Pseudo code • English like statements that follow loosely defined syntax and are used to convey the design of the algorithm
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.
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]
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]
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
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)
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
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
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.
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
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
* Write an algorithm and flowchart to find largest of 3 numbers
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
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
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
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
Whitebox Testing • Testing the program knowing what is inside it and knowing how it works. • Example:- Testing the code written by yourself
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.
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.
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
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
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.
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.
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
Generation of Languages BCPL (B) C C++ JAVA .NET C#
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