Presentation is loading. Please wait.

Presentation is loading. Please wait.

Evolution of C and C++ n C was developed by Dennis Ritchie at Bell Labs (early 1970s) as a systems programming language n C later evolved into a general-purpose.

Similar presentations


Presentation on theme: "Evolution of C and C++ n C was developed by Dennis Ritchie at Bell Labs (early 1970s) as a systems programming language n C later evolved into a general-purpose."— Presentation transcript:

1 Evolution of C and C++ n C was developed by Dennis Ritchie at Bell Labs (early 1970s) as a systems programming language n C later evolved into a general-purpose language C is a high-level language and is portable C also has the power of assembly languages C is standardized by American National Standards Institute (ANSI) n C++ was developed by Bjarne Stroustrup at Bell Labs (early 1980s) as an extension of C

2 Integrated Development Environments n A typical C integrated development environment (IDE) consists of Text editor C compiler Preprocessor Libraries Linker Other development and debugging tools n Some popular IDEs MS Visual Studio GNU C

3 The C Programming Environment n The language Carry out basic operations on data Create memory locations Compare values Repeat operations n The libraries Collection of routines that can carry out operations that are not part of the language Examples: Taking the square root of a number, printing to screen, reading from keyboard, etc. Libraries enable us to avoid “reinventing the wheel”

4 Preprocessing, Compiling, and Linking n Preprocessor Component of C system Checks the source code for special instructions (preprocessor directives) and either includes other files into program or replaces some special symbols with an appropriate text n Compiler Translates the source code into object code (machine language instructions) n Linker Combines the object code of your program and object codes of libraries Creates an executable machine language program

5 The Loader n The executable machine language program is called the load module n To execute a program, we ask the OS to load it into memory n Loader is a program that loads the executable load module into the main memory for execution It puts the address of the first instruction into program counter n The CPU can begin execution of a program only after the program is loaded into main memory

6 Steps in Software Development 1.Requirements specification n Understanding what the problem is, what is needed to solve it, what the solution should provide, existing constraints 2.Analysis n Deciding on inputs/outputs, formulas, equations to be used 3.Design n Development of an algorithm (pseudocodes and flowcharts) 4.Implementation n Writing the software in a programming language 5.Testing (demonstrating correctness) and verification (ensuring that program meets user’s requirements) 6.Documentation

7 Designing Algorithms n An algorithm is a sequence of a finite number of steps arranged in a specific logical order, which, when executed, produce the solution for a problem n Two techniques for representing algorithms Pseudocode: Semiformal, English-like language with limited vocabulary Flowchart: Graph consisting of geometrical shapes that are connected by flow lines

8 More on Designing Algorithms n Structured programming In 1966, Bohm and Jacopini demonstrated that any algorithm can be described using only three control structures: sequence, selection, and repetition n Divide and conquer Splitting a problem into several simpler sub-problems, solving each individually, and then combining solutions into one n Top-down stepwise refinement Start from the original problem and proceed down to sub- problems

9 Sequence Structure n Series of steps or statements that are executed in the order in which they are written Statement_1 Statement_2 Statement_n Statement_1 Statement_2 … Statement_n begin Statement_1 Statement_2 … Statement_n end Blocked

10 Selection Structure I n Defines two courses of action, depending on the outcome of a condition n A condition is an expression that, when evaluated, computes to either TRUE or FALSE condition else-part then-part truefalse if condition then-part else else-part end_if

11 Selection Structure II n Missing else-part condition then-part truefalse if condition then-part end_if We will study selection structure in C in Chapters 4 and 9 Nested selection structures will also be studied

12 Repetition Structure I n Specifies a block of one or more statements that are repeatedly executed as long as a condition is satisfied condition loop-body true false while condition loop-body end_while

13 Repetition Structure II n Loop-body can also be executed first condition loop-body true false do loop-body while condition We will study repetition structure in C in Chapters 4 and 9 Nested repetition structures will also be studied

14 Divide and Conquer n A simple example: Calculate the income tax paid by an employee n Divide the problem into smaller sub-problems Sub-problem 1: Read the income of the employee Sub-problem 2: Determine the tax rate based on income Sub-problem 3: Calculate the income tax based on the determined tax rate Sub-problem 4: Print the tax to be paid

15 Top-Down Stepwise Refinement n Here are the steps for solving the problem: 1.Read the income 2.Determine tax rate for that income 3.Calculate the income tax 4.Print the tax and net income n An example refinement of Step 2: If the income is between 0 and 1,000 then tax_rate=5% If the income is between 1,001 and 2,000 then tax_rate=7.5% If the income is between 2,001 and 3,000 then tax_rate=10% etc.

16 Errors and Debugging n Syntax errors and compiler errors Compiler cannot finish compilation n Linker errors Even if program compiles successfully, linker may generate errors n Execution (run-time) errors Successfully compiled and linked programs may still contain errors that become apparent during execution n Design errors Incorrect solution method The process of finding and correcting errors is called debugging

17 Documenting Programs n Your program must contain the following elements: A concise requirement specification Description of inputs, outputs, formulas, constraints A pseudocode and/or flowchart for its algorithm A source program listing A hard copy of a sample test run A user’s guide n It is also very important to have in-program documentation in the form of comments that will clarify the program and its logic


Download ppt "Evolution of C and C++ n C was developed by Dennis Ritchie at Bell Labs (early 1970s) as a systems programming language n C later evolved into a general-purpose."

Similar presentations


Ads by Google