Programming Methodology

14,307 views

Published on

Explains the basics pf programing methodology

Published in: Technology
1 Comment
17 Likes
Statistics
Notes
No Downloads
Views
Total views
14,307
On SlideShare
0
From Embeds
0
Number of Embeds
133
Actions
Shares
0
Downloads
6
Comments
1
Likes
17
Embeds 0
No embeds

No notes for slide

Programming Methodology

  1. 1. Made By: Ms. Archika Bhatia PROGRAMMING METHODOLOGY
  2. 2. Stylistic Guidelines Developing good programs is a skill and writing good programs is a quality habit. Follow the guidelines given to develop the quality habit.
  3. 3. <ul><li>Give meaningful names to the identifiers </li></ul><ul><li>Avoid giving similar names to the identifiers. </li></ul><ul><li>Ensure clarity of expressions </li></ul><ul><ul><li>Avoid programming tricks </li></ul></ul><ul><ul><li>Avoid unclear expressions </li></ul></ul><ul><li>Use Comments and Indentation </li></ul><ul><ul><li>Comments play a very important role as they provide internal documentation of a program. </li></ul></ul><ul><ul><li>Indentation makes the statements clear and readable. </li></ul></ul><ul><ul><li>// for single line comments /* ----- */ for multiple line comments </li></ul></ul><ul><li>Insert Blank Lines and Blank Spaces </li></ul><ul><ul><li>Blank lines are inserted to separate declaration blocks, comment boxes, procedures and functions, etc. </li></ul></ul><ul><ul><li>Blank spaces may be added before the operators: +, -, *, /, >=, ||, etc. </li></ul></ul>
  4. 4. Characteristics of a Good Program <ul><li>A program written in a good style is easily understandable to a reader. </li></ul><ul><li>Effective and Efficient : should produce correct result and should be faster, taking into account memory constraints. </li></ul><ul><li>User Friendly : should interact with the user by understandable messages. </li></ul><ul><li>Self Documenting code : Use of meaningful names to identifiers and appropriate use of comments and indentation. </li></ul><ul><li>Reliable : must be able to handle unexpected situations like input of wrong data or no data input. </li></ul><ul><li>Portable : should be able to execute on different platforms. </li></ul>
  5. 5. <ul><li>Crack the Problem : </li></ul><ul><ul><li>involves understanding the problem, identifying minimum no. of inputs, step by step solution. </li></ul></ul><ul><ul><li>problem is cracked and an algorithm is formulated. </li></ul></ul><ul><li>Code the algorithm : algorithm is translated into a program ( source code ) using a programming language. This process is called Coding . </li></ul><ul><li>Compile the program : Compilation is the process to convert the source code into the object code ( code in the machine language ). </li></ul><ul><li>Execute the program : After compilation of an error free program, the program is executed. This phase is called run-time . </li></ul>Stages of Program Development
  6. 6. <ul><li>An error, sometimes called a ‘ Bug ’. </li></ul><ul><li>There are broadly three types of errors: </li></ul><ul><ul><li>Compile Time </li></ul></ul><ul><ul><li>Run-Time </li></ul></ul><ul><ul><li>Logical </li></ul></ul>
  7. 7. Compile Time Errors <ul><li>Errors that occur during compile time </li></ul><ul><li>Two types of errors: </li></ul><ul><ul><li>Syntax errors : </li></ul></ul><ul><ul><ul><li>when rules of a programming language are misused. i.e. when grammatical rules of C++ is violated. </li></ul></ul></ul><ul><ul><ul><li>(Syntax refers to formal rules governing the construction of valid statements in a language.) </li></ul></ul></ul><ul><ul><ul><li>E.g. itn a, r-a+b; , if s=a, etc. </li></ul></ul></ul><ul><ul><li>Semantic errors : </li></ul></ul><ul><ul><ul><li>when statements are not meaningful. </li></ul></ul></ul><ul><ul><ul><li>(Semantic refers to set of rules which give the meaning of a statement.) </li></ul></ul></ul><ul><ul><ul><li>E.g. ‘Sita plays Guitar’ is syntactically and semantically correct as it has some meaning but the statement ‘ Guitar plays Sita ‘ is syntactically correct ( as the grammar is correct ) but semantically incorrect. </li></ul></ul></ul><ul><ul><ul><li>Similarly, A * B = Z is incorrect since an expression cannot come on the left side of an assignment statement. </li></ul></ul></ul>
  8. 8. <ul><li>Errors that occur during the execution of the program. </li></ul><ul><li>E.g. Infinite loop, wrong input given e.g. divide error, opening a file which does not exist. </li></ul>Run Time Errors
  9. 9. Logical Errors <ul><li>Incorrect implementation of an algorithm are logical errors. </li></ul><ul><li>Result in incorrect results, even though no errors at the time of compilation or run-time. </li></ul><ul><li>E.g. use of a variable before initialisation, wrong parameters passed in function. </li></ul>
  10. 10. <ul><li>The process of converting one predefined data type into another is called Type conversion. </li></ul><ul><li>It takes two forms: </li></ul><ul><ul><li>Implicit type conversion </li></ul></ul><ul><ul><li>Explicit type conversion </li></ul></ul>TYPE CONVERSION
  11. 11. <ul><li>Conversion performed by the compiler without programmer’s intervention. </li></ul><ul><li>Generally applied when differing data types are mixed in an expression. </li></ul><ul><li>C++ compiler converts all operands upto the type of largest operand, which is called Type promotion . </li></ul><ul><li>E.g. int a = 10 ; long b = 90000 ; cout<< a + b; ans will be in long i.e. 90010 </li></ul>IMPLICIT TYPE CONVERSION <ul><li>Conversion performed by the compiler without programmer’s intervention. </li></ul><ul><li>Generally applied when differing data types are mixed in an expression. </li></ul><ul><li>C++ compiler converts all operands upto the type of largest operand, which is called Type promotion . </li></ul><ul><li>E.g. int a = 10 ; long b = 90000 ; cout<< a + b; ans will be in long i.e. 90010 </li></ul>
  12. 12. EXPLICIT TYPE CONVERSION <ul><li>Explicit conversion is user defined </li></ul><ul><li>Forces an expression to be of specific type. </li></ul><ul><li>Explicit conversion of an operand to a specific type is called Type Casting . </li></ul><ul><li>E.g. int a =10 , b = 3 , c = 65; cout << a / b << endl ; cout << ( float ) a / b << endl ; // explicit type conversion cout << ( float ) ( a / b ) << endl ; cout << ( char ) a ; // Type Casting OP will be 3 3.333333 3 A </li></ul>

×