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