Wednesday, September 5, 2018

क्रोशे आकार : चौकोन

Tuesday, August 12, 2014

 [Enter Post Title Here]


Lecture 1
Contents:
·         Algorithm and Examples
·         Flowcharts and Examples
·          Importance of Indentation
·         Structured Programming

Algorithm:


Definition 1:

An algorithm is a well-ordered collection of unambiguous and effectively computable operations that when executed produces a result and halts in a finite amount of time

Definition 2:

A finite set of instructions having the following characteristics:
·         Precision: Steps are precisely stated.
·         Uniqueness: Results of each step uniquely defined.
·         Input:  Algorithm receives input.
·         Output: Algorithm produces output.
·         Generality: Algorithm applies to a set of inputs.


Characteristics of algorithms:

1.     Algorithms are well-ordered.
2.     Algorithms have unambiguous operations.
3.     Algorithms have effectively computable operations.
4.     Algorithms produce a result.
5.     Algorithms halt in a finite amount of time.

An Example Algorithm

Let’s look at a very simple algorithm called find_max().
Problem: Given a list of positive numbers, return the largest number on the list.
Inputs: A list L of positive numbers. This list must contain at least one number. (Asking for the largest number in a list of no numbers is not a meaningful question.)
Outputs: A number n, which will be the largest number of the list.
Algorithm:
1.       Set max to 0.
2.       For each number x in the list L, compare it to max. If x is larger, set max to x.
3.       max is now set to the largest number in the list.
An implementation in Python:
def find_max (L):
    max = 0
    for x in L:
        if x > max:
            max = x
    return max



Does this meet the criteria for being an algorithm?
·         Is it unambiguous? Yes. Each step of the algorithm consists of primitive operations, and translating each step into Python code is very easy.
·         Does it have defined inputs and outputs? Yes.
·         Is it guaranteed to terminate? Yes. The list L is of finite length, so after looking at every element of the list the algorithm will stop.
·         Does it produce the correct result? Yes. In a formal setting you would provide a careful proof of correctness. In the next section I’ll sketch a proof for an alternative solution to this problem.

Flowchart:


Flowcharting is a tool developed in the computer industry, for showing the steps involved in a process.
A flowchart is a diagram made up of boxes, diamonds and other shapes, connected by arrows - each shape represents a step in the process, and the arrows show the order in which they occur.
Flowcharting combines symbols and flowlines, to show figuratively the operation of an algorithm.
Flowcharting is the first step towards process understanding.

Flowcharting Symbols:

There are 6 basic symbols commonly used in flowcharting of assembly language
1.       Process
2.       Terminal,
3.        input/output,
4.       Decision,
5.        Connector and
6.       Predefined Process.
Process: Indicates any type of internal operation Inside the Processor or Memory  

Input/output: Used for any Input / Output (I/O) operation. Indicates
 that the computer is to obtain data or output results

Decision:  Used to ask a question that can be answered in a binary
format (Yes/No, True/False)
 

Connector:  Allows the flowchart to be drawn without
intersecting lines or without a reverse flow.
Predefined Process:  Used to invoke a subroutine or an interrupt program.

Terminal : Indicates the starting or ending of the
 program, process, or interrupt program.

 Flow Lines: Shows direction of flow.          

Importance of Indentation

Programming style and indentation can be defined as the way you follow to organize and document your source code. Code indentation is a part of style and it is more of aesthetic interest.  A proper code indentation will make it:
·         Easier to read
·         Easier to understand
·         Easier to modify
·         Easier to maintain
·         Easier to enhance

We refer the code again during
·         Reading an understanding the program
·         Code debugging
·         Adding new code to the existing program
·         Updating the existing program


Indentation:

Indentation is done with SPACES not TABS. SPACE is of fixed length in all types of system. But TAB is not of fixed length. The matching braces should be in the same column.

 Spacing:


It also makes the code more readable if properly maintained. So we should follow proper spacing throughout our coding and it should be consistent.
Following are some examples showing the usage of spacing in code indentation.

1.        Left parenthesis should start immediately after the method name.

// NOT Recommended
 Function   (i, j);
 // Recommended
Function (i, j); 
2.        All array names should be immediately followed by a left square bracket.

// NOT Recommended
         arr   [0];
// Recommended
         arr[0]; 
3.       All binary operators should maintain a space on either side of the operator.
                  // NOT Recommended
                                  a=b-c;         
  a = b-c;       
                                  a=b - c;       
            
               // Recommended
         a = b - c;     
 // NOT Recommended
                      z = 6*x + 9*y;        
                  // Recommended
                 z = 6 * x + 9 * y;    
                   z = (7 * x) + (9 * y);
  
4.       All unary operators should be written immediately before or after their operand.
    // NOT Recommended
    count ++;
                 // Recommended
                    count++;
5.        All commas and semicolons must be followed by single whitespace.
       // NOT Recommended
             for (int j = 0;j < 10;j++)  
       // Recommended
             for (int j = 0; j < 10; j++)
       // NOT Recommended
             getDetails(id,age);
      // Recommended
       getDetails(id, age);
6.       All casts must be written without any space
     // NOT Recommended
        (ClassA) m.get(3); 
        ( ClassA )m.get(3);
   
      // Recommended
         (ClassA)m.get(3);  

7.       All keywords like if, while, for, switch, and catch should be followed by a single space.
     // NOT Recommended
     if(true) 
     // Recommended
     if (true)

     // NOT Recommended
     while(conut < 7)
     // Recommended
     while (count < 7)

     // NOT Recommended
     for(int j = 0; j < 10; j++) 
     // Recommended
     for (int j = 0; j < 10; j++)
    
     // NOT Recommended
     catch(Exception e) 
     // Recommended
     catch (Exception e)


Maximum Line Length:

    Maximum line length should not exceed 120 characters. 

 

Self Documenting Code:

The best practice is to write the code in a way so that it can explain itself without any comment.

 // NOT recommended
if ( (a == Good) && ( (b == better) || (b == best) ) )
 // Recommended
boolean isbetterbest = ( (b == better) || (b == best) );
 if ( (a == Good) && isbetterbest )

 

Structured Programming:


A method of writing a computer program that uses:
1.       Top-down analysis for  problem solving
2.       Modularization of program structure and organization and
3.       The structured code for the individual modules

Advantages of structured Programming:

1.       Programs are more easily and more quickly written. Big programming tasks are broken down far enough that each subtask is easy to program as a separate unit.
2.       Programs have greater readability. Fewer organizational and logical errors occur in the initial stages of program development and writing.
3.       Programs require less time to debug and test. Because fewer errors are made in the programs. However, modularity also makes it much faster to localize and correct those that do occur.
4.       Programs are easier to maintain. The logic of well organized, modular program is much easier to follow. Therefore, one can easily discover how and where to make necessary changes.
a.        Since modules are separate, independent units, an old module is simply replaced by a new module.
b.      Adding new features of capabilities to a program becomes as easy as adding new modules to a superstructure already available.

Structured Programming and Programming languages:

Three statements can be made about structured programming and programming languages:
1.       Programmer can apply a method of structured programming in any language
2.       Some languages have been designed in such a way that one virtually has to write a modular program.  E.g. ALGOL, Pascal, PL/I, Ada. These languages are sometimes said to be Block Structured Languages.
3.       The ease with which one can write structured code depends o some extend on the language used.


Monday, August 5, 2013

Hello World!

Hi all,

Just came across this link...check out Hello World program in different languages....

http://www.mycplus.com/featured-articles/hello-world-programs-in-300-programming-languages/

Have a nice day!

Tuesday, February 26, 2013

Dear Student,

PL refer to the following link for FPL-II unit -I

Microprocessor book for Pune university, First Year Engineering, FPL-II reference:

https://docs.google.com/file/d/0BwBMbY_2VMQsTkp3VUVxLU9XY0k/edit?usp=sharing


Best Luck

Wednesday, June 30, 2010

Turbo C

1987 – Version 1.0 of the Turbo C programming language is released. It offers the first integrated edit-compile-run development environment for the C programming language for IBM-compatible personal computers. Turbo C was developed by Bob Jervis as “Wizard C”. It runs on just 384KB of memory and is capable of inline assembly with full access to C symbolic names and structures.

Steve Yegges Blog about Why compilers matter?

Principles of Compiler Design

This semester I will be helping my B.E Computer Students to understand Compilers and its working.

OVERVIEW


A compiler or interptreter for a programminning language is often decomposed into two parts:

1. Read the source program and discover its structure.
2. Process this structure, e.g. to generate the target program.


Why to learn it?

To enhance understanding of programming languages


• To have an in-depths knowledge of low-level machine executables

• To write compilers and interpreters for various programming languages and domain-specific languages
   Examples: Java, JavaScript, C, C++, C#, Modula-3, Scheme, ML, Tcl/Tk, Database Query Lang., Mathematica, Matlab, Shell-Command-Languages, Awk, Perl, your .mailrc file, HTML, TeX, PostScript, Kermit scripts, .....

• To learn various system-building tools : Lex, Yacc, ...

• To learn interesting compiler theory and algorithms.

• To learn the beauty of programming in modern programming lang.