Tuesday, February 1, 2011

Computer Programming Lab Viva Details

PROGRAM DEVELOPMENT STAGES:

a)      Program design: At this stage define a problem and its solution.
      problem specification: the program must be  thoroughly understand the problem       and the input output and special processing specification represent the most important information collection during this phase.
Solution: The solution method is to be developed.
b) Using planning tools: The solution method is described step by step when       solution method had been outlined. It must be represent by using alorithm       notations or flow charts symbols.
c)     Coding: It is relatively easier to convert the algorithm into a program in a computer   language i.e. C,C++.
d)     Compiling: Translate the program into machine code. typing errors(syntax errors) are found quickly at the time of compiling the program most C implementations will generate diagnostic messages when syntax errors are detected during compilation.
e)     Executing: Running the program the run time errors may occur during the execution of programs even though it is free from syntax errors.
            Syntactic & Run time errors generally produce error messages when        program executed. These are easy to find and can be corrected. The logical  error which is very difficult to detect. These are existence of logically incorrect   instructions. These errors can be know only after output is executed.
f)       Testing and validation: Once program is written , a program must be tested and then  validated. The program always must guarantee to produce correct results.                    In above stages a), b),c) are purely manual process. remaining all
      stages   related  its computer.

 ALGORITHM:  A method of representing the step by step logical procedure for solving program in natural language is algorithm.
 SPARSE NOTATIONS FOR ALGORITHAMS:
1) General form of PROCEDURE
                            Procedure NAME (parameter list)
                                      Declarations
                                       Statements
                            end NAME
2) General form of FUNCTION
                                                          Function  NAME (parameter list)
                                                                     Declarations
                                                                      Statements
                                                         end NAME
3)      For comment line: //  This is comment//
4)      Variable declaration :
                           integer x ,y;
                           char  c, d;
                           Boolean  a,b;
5) Assignment  of variables
                          <variable>  ¬<expression>
6) Boolean values:  
                             true ,false
7) Logical operators:  
                            and , or , not
8) Relational operators:
                           < , <= , = , >=, >
9) Conditional statement:
                          a)  if cond   then  s1
                               else   s2
                               endif
                                                          b)    case
:  cond 1: s1
:  cond 2 : s2
………….
:  cond :n
: else : s n+1
                                                                end case
                                                           10) Iterative statements:
a)      while condition  do     s       repeat
b)      loop   s     until condition repeat
c)      for vble <- start to finish by increment do s
                 repeat
                                                         11)   Input
                                                                                            read (argument list);
                                                                 Output
                                                                                            print(argument list); 
                             FLOWCHART:
       There is another way to write the steps involved in any process ,this is by making use of various symbols . The symbols form a diagram that represents the steps in a pictorial fashion similar to an algorithm. This is also very easy to understand such a diagram is flow chart.
       Flowcharts help us understand the logic of an operation easily. They are good communication devices and also helps in algorithm maintenance.
       The most common symbols using drawing flow charts are given below:

FLOWCHART SYMBOLS:

Oval
Terminal
Start/stop symbol

Parallegram
Input/output
Input/output

Rectangle
Process
Any processing can be performed

Document
Hard copy
Show’s data output in the form of document

Diamond       
Decision
Decision


Circle
Connector
Used to connect different parts of flowchart


Double sided Rectangle
Sub program
Sub program

Hexagon        
Iteration
Iteration
<----------------
Arrow
Flow
Joins two symbols


Special Symbols:








STARTING TO TURBO 'C':
Double clicking the mouse's left button on a Turbo C icon
or
By clicking start, selecting programs and then clicking Turbo C
or
Selecting MS-DOS prompt mode and change the directory to TC or Turbo C   and then  type TC at the DOS prompt and press Enter.Turbo C opens and  displays a main menu.   Pressing any key removes                       the version copyright notice, and places the cursor on the File option of the menu bar.

HOT KEYS IN TURBO 'C':
                          F1     Provides context-sensitive help for the items selected.
                          F2      Save the current file to disk.
                          F3     Window to enter file name to load.
                          F5     Toggle: Zoom or Unworn active window.
                          F6      Switch to active window.
                          F7      Move to previous error.
                          F8      Move to next error.
                          F10    Go to the top line of main menu bar.
                         ALT-F5   To view the results.
                         Alt-F9      Compile current file to .OBJ.
                         Alt-D      Pull-down Debug menu.
                         Alt-E        Go to Edit mode.
                         Alt-F        Pull-down File menu.
                         Alt-O        Pull-down Options menu.
                         Alt-R       Pull-down Run menu (may Compile Link first).
                         Alt-X       Exit from the Turbo C to DOS/Windows desktop.
                         Ctrl-F9       Run the current file.
                          Esc          To cancel the running command.

 C   SYNTAX 
Structure of 'C' Program:
           Documentation section                         ex:  /*name of the program*/
           Link section                                                    #include<stdio.h>
           Definition section                     
           Global declaration section
           main( )  function section                                    main()
                  {                                                                           {
                     Declaration part                                                  int i=10;
                      Execution part                                                    printf("%d",i);
                   }                                                                          }
           Sub program section
                    Function 1
                    Function 2
                    …………
                   
Documentation section: It consists with name of the program and other details.
Link section: It provides header files to the computer to link library functions.
Definition section: It defines all Symbolic constants.                     
Global declaration section: It declares Global variables which are useful in all
              functions of the program.
main( )  function section: It consists with declaration part and executable part.
Sub program section: It contains the entire user defined functions called in main function.
Character set: The Character set in C are grouped into 1(Letters,2)Digits,
              3)Special characters.
a)      Alphabets: A,B,C…….Z; a, b, c ……z.
b)      Digits  0,1,2……..9.
                                                      c)   Special character: @,#,$,^………….etc.  
Key words: These are pre defined words have a fixed meanings. All key words must be written in lower case letters.
Auto             break                 case                char                const
char             continue            default            do                    double
                        else              enum                 extern                         float                 for
                        goto              if                         int                   long                 register
                        return          short                   signed                        sizeof              static
                        struct          switch                typedef          union                         unsigned
                        void              volatile                while

Constants: Constants in C refer to fixed values do not change during the execution of the program.
1)      Integer constant: It refer to a sequence of digits, 0 through 9 preceded
       by - or +.    Ex:  149,        -980,    +45.
2)      Real constants: the quantities which are represented by numbers
     containing fractional part.     Ex:0.78,      2.45.
         It is also represented  in exponential notation
                Ex: the value   4356.78 can represented as 4.35678e3.
3)      Single character constant: It contains a character enclosed within a pair
      of single quote marks. Ex:  '2'  ,  'a' .
4)      String constant: It is a sequence of characters enclosed in double quotes.
                            Ex: "india"  ,   "2*3",     "n".
                 5)  Back slash character constant(Escape sequences):
                 '\n'             for new line
                 '\t'              for horizontal tabulator
                 '\v '            for vertical tabulator  
                 '\0'             Null character.    

Data Types:
                         Data type                              size                                  range
                            int                                       2 bytes                       -32,768 to 32,767
                            char                                    1 byte                         -128 to 128
                            float                                    4 bytes                       -3.4e-38 to 3.4e+38
                        double                                 8 bytes                       -1.7e-308 to1.7e+308

Variables: It is a data name that may be used to store value. Variable name may consist of letters ,digits, underscore(_) characters subject to the following conditions:
1)      Variable must begin with letter.
2)      Variable name should not be more than 8 characters.
3)      Upper case and Lower case are significant.
4)      Variable name should not be key word.
5)      White space is not allowed.
Declaration of variables: Declaration tells to the compiler variable name with
          specifying data type.
                    
a)     Primary type :
                    Syntax :   data-type variable1,variable2,……..variable n;
                                                            Ex :  float marks;
           
                b) User defined type : C supports a feature known as  type definition that
                                                allows user to define an identifier.
                                                Syntax :               typedef  data-type  identifier;
                                                            Ex: typedef int units;
    c) Enumerated data type: It contains enumeration constants represented
                                    by identifiers.                     
                      Syntax:     enum  identifier  { value 1,value 2,…..value n};
                                     Ex: enum  day { Monday, Tuesday,……Sunday};
                  
d) Declaring variable as constant: The value of variable can be made to
                               remain constant.
                               syntax:       const   data-type variable = value;
                                                                              Ex : const  int max = 40;
 e) Declaring variable as volatile :The value of variable may be changed
                               by some external reasons from out side.
                                Syntax :     volatile data-type variable;
                                                                             Ex : volatile int date ;
Declaration of storage classes:
                 a) Automatic variable: Local variable known to only to the function in
                                                          which is declared default is auto .
                                syntax :         auto data-type variable;
                                                                  Ex : auto int number;
b)     Extern variables: Global variable known to all functions in the file. It is used to crossing files.
                                Syntax:             extern data-type variable;
                                                                 Ex: extern int number;
                c) Static variables: Local variable, which exists and retains its value
                                  even after the control is transferred to the calling function.
                                Syntax :               static data-type variable;
                                                                  Ex :static int  x;
d) Register variables: Local variable, which is stored in the CPU register. It is fast access variable.
                                Syntax :               register data-type variable;
                                                                  Ex :register int  x;
       ** Very local variables are more priority than local, local variables are more
            priority  than global.

Assigning values to variables: Value can be assigned to variables using the
                                                assignment operator.
                                                Syntax :  data-type  variable-name =constant;
                                                                  Ex: int  units =123;
                               Multiple assigning :   Ex :       x = y= z = max;
Type casting: C allows, if the operation are of different it types the lower type
                        is converted to the higher type to before operation proceed.
                                                Syntax : (type-name) expression/value;
                                                                 Ex:  x = (int) 7.5      result = 7
Abstract data type: It is a tool which specifies the logical properties of a data type .
                                    Syntax:  abstract typedef  < integer , integer > RATIONAL
Defining symbolic constants: This is useful when a constant will be used number
                          of places in a program.          
                                                      # define   symbolic-name   value
                                               Ex : #define MAX  100
                                                       # define PI  3.14159       
Operators:
                              a)  Arithmetic operators:  +, - , * ,  /  , %
          b)Assignment operators: Use to assign result of expression to variable.
                                    = operator                   
                              c)  Relational operators: These are used to compare two operands and then depend on their relation certain decision are made.   
                                                                      < ,> , <= , >= ,!= ,==,
                              d)  Increment operators: Used for incrementing by 1.
                                                                       ++var (pre) ,var++ (post)
                              e) Decrement operators: Used for decrementing by 1.
                                                                       --var (pre),  var-- (post)
                              f) Bit operators: These are low level operators it works only on
                                  integers used for testing and shifting bits.
                                                                       & (and), | (or) ,<< (left shift) ,>>(right shift) ,
                                                                        ^(ones compliment)
        g) Logical operators :These operators are used test more than one
            condition. The result must be in either TRUE or FALSE.
            Logical not   operator changes TRUE to FALSE vise versa.
                                                  && (and) ,   || (or) ,  ! ( Logical not)
        f) comma operator: It is used to combine two related expressions.
                                                   ( , )

 Precedence of operators:
  Operator                          priority
  * / %                                   high 
   + -                                      low    
   Note: evaluate from left  to right    
Format descriptor:
                 %d          for signed decimal integer
                 %u           for unsigned decimal integer
                 %s           for string
                 %f            for  float
                 %c           for character
Input / Output functions:
                  These functions permit the transfer data between computer and the standard input/output devices.                      
a)      Formatted I/O Functions: Used to transfer single character, numerical
                                              values, strings.
                        Output syntax     printf( "control string", arg1, arg2,………….argN);
                                              Ex: printf ("%c", a);
                         Input syntax: scanf( "control string ", & var1,&var      2,……&var n);
                                              Ex: scanf("%d",  &x);
              b)Character I/O Functions: Used to transfer single character.  
                          Input syntax:    char variable = getchar();
                          Output syntax:  putchar(char variable);
              c) String I/O Functions: Used to transfer strings.
                           Input syntax:     gets(string);                  
                          Output syntax :  puts(string);
Control flow structures:
                   1)Selective control structure(conditional structures):
a)      Simple if statement:
                 syntax:    if(condition)
                                                           {
                                                              statement-block;
                                                            }
b)      if-else statement
                syntax:     if(condition)
                                                                      {
                                                                       statement-block;
                                                                      }
                                                                  else
                                                                       {
                                                                         statement- block;
                                                                       }
                               c) else if statement
                                               syntax:         if(condition 1)
                                                                {
                                                                  statement-block;
                                                                }
                                                              elseif(condition 2)
                                                                 {
                                                                  statement-block;
                                                                 }
                                                              else
                                                                 {
                                                                  statement-block;
                                                                  }
c)      nested  if-else statement
          
                                                    syntax:    if(condition1)
                                                               {
                                                                     if(condition 2)
                                                                 {
                                                                   statement-block;
                                                                  }
                                                                 else
                                                                 {
                                                                  statement-block;
                                                                  }
                                                         else
                                                            {
                                                                  statement-block;
                                                             }
d)      switch statement  :It provides an alternative of several if
                                     statements.
                                                    Syntax:  switch (expression)
                                                              {
                                                                case value1:
                                                                              statement 1;
                                                                              break;
                                                                case value2:
                                                                              statement 2;
                                                                               break;
                                                                ……………..
                                                                 …………….
                                                                 Default:
                                                                              statements;
                                                                               break;
                                                                }
e)      Ternary operator ( ? : ): It is used replace the statements in the
                                                form  if-then-else
              syntax:
                    conditional expression ? expression 1: expression 2
                     Ex: flag = (x<0) ? 0 : 1
 Iterative control structure(Repetitive structures): These structures repeats sequence of instructions until condition satisfies.
a)      while loop:
          syntax: while(expression)
                    {
                           statement:
                     }            
b)      do - while loop: The statements in the loop are executed and the testing done at the end of loop.
        syntax:      do
                    {
                         statement;
                     } while(condition);   
c)      for loop:
                                                syntax:     for ( initialization ; condition ; increment)
                     {
                          statement;
                    } 
d)      break statement: It transfer the control to the end of the
                                  construct.
                                                         if(condition)
                                                           break;
e)  continue statement: It transfers the control to next iteration by skipping following statements.
                   if(condition)
                     continue;
           f)  goto statement: It transfer control  to the statement that
                               follows the label where it is defined.
                                                          if( condition)
                                                            goto label  
   Arrays: An array is a group of related data items that share a common name
                               a) One dimensional array: It is a list of items can be given a variable name using only one subscript.
                                                    syntax : data-type array-name [array-size];
                                                              Ex: int number[10];
                                    Initialization:
                                          syntax: data-type  array-name [array-size]={list of values};
                                                       Ex:       int number [5] = {1,4,6,10,32 };
                 b) Two dimensional array : It is a list of items can be given a
                                                            variable  name using two subscripts.
                                               Syntax: data-type  array-name [row-size][column-size];
                                                           Ex:     int table[2][4];
                                    Initialization : 
                                    data-type array-name[row-size][column-size]={list of values};
                                               Ex:    int table[2][4]={ {1,6,4,8,9},{4,3,8,5}};  
a)      Multi dimensional array:
                                             syntax:  data-type array-name [s 1][s 2][s3]……..[sn];
                                                     Ex:   float table [4][5][2];
 String:     String is an array of characters terminated by the null character.
a) String declaration:
                       syntax:    char string-name[size];
                                   Ex: char city[10];
      Initialization:  Ex : char city[10]= "hyderabad";
b)  String functions:
      String concatenation                   strcat(s1,s2);
      String comparison           int n= strcmp(s1,s2);
      String copying                            strcpy(s1,s2) ;
      String length                      int n=strlen(string);  
Pointers: It is nothing but  a variable that contains the address of another variable.
Pointer&variable:
         Declaration of pointer variable:
                            Syntax:  data-type  * pointer-variable;
                                      Ex:   int *p;    (integer pointer)
                                              char *p;   (character pointer)
                                              float*p;  (float pointer)
          Initialization:    
                            Syntax: pointer-variable= &variable;
                                       Ex:  int a=10; int*p;
                                                p=&a;
                Pointers to pointer:
                                  Syntax : data-type ** pointer variable;
                Declaration of void pointer :
                                  Syntax: void * pointer-variable;
                                           Ex: void * e;    e= &a;
Pointers & arrays:              
          Declaration of array of pointers:
                           Syntax:  data-type   *variable[size];
                                      Ex:  char  *ptr[5];
          Declaration of pointer to array:
                             Ex:   (int *p) [5];
Pointers &functions:
          Declaration of pointer to function;
                           Syntax: return-type data-type (*fptr)(fun.arg.list);
                                      Ex : int test (double);
                                              int(*p)(double);
                                               p=test;
 Pointers  &structures:
          Declaration of pointer to structures:
                    Syntax : Struct  tag
                                 {
                                   data-type member1;
                                   data-type member2;
                                   ………..
                                     }:
                              struct  tag * p,a;
                                  p=&a;
           Accessing structure contents by pointer variable
a)      Dot operator  ( . )          ex : (*ptr).member1;
b)      Arrow operator (->)      ex: ptr-variable-> member1;
                                Structure with pointers:
                                                      Ex:   struct node
                                                                   {
                                                                     int data;
                                                              struct node * link;(link is a pointer to structure)
                                                                    };
Functions: It is meant for performing a specific task which is repeated each time the program calls it. Functions are two types 1) Library functions 2) User defined
                   functions.
 Function definition(called function): It introduces a new function by declaring type of value it returns and parameters.
                                         Syntax:    function-name(formal arg-list)
                                                           argument declaration:
                                                                {
                                                                 local variable declaration;
                                                                   executable statement1;
                                                                         ………………
                                                                   return(expression);
                                                               }     
                      Function declaration(function call):
                                           Syntax:   function-name (actual arguments);     
                      Actual arguments: These parameters used in calling function.
                                                      They may be constant or variable.
                      Formal arguments: These parameters used in called function.
                                                        These must be  variable.
Command line Arguments: It is a parameter applied to a program when program is invoked.
                                               Syntax: main(arg c, arg v)
                                                          argc(argument counter) : It is an integer variable
                                                                     which contains number of arguments.                                  
                                                            argv(argument vector):It is an array of string,
                                                                 it contains arguments passed from command
                                          line. argv[0] always specifies name of the program.
Structures: It is a collection of logically related data items of different types using a single name. Structure allocates separate memory space for each member.
          

   Structure definition:  It creates a format of structure variables that
                                                 may be used in structure.
                           syntax:
                                   struct  structure-name                     Ex:  struct student
                                         {                                                               {
                                           data-type variable 1;                              int rollno:
                                            data-type variable 2;                          float marks;         
                                           ……………………;                           ………….;
                                        };                                                                };
             Structure declaration: It allocates a memory for declared structure.
                          syntax:
                                  struct  structure-name  variable1,variable2……;
                                      ex: struct student  s1,s2,s3;
               Structure initialization:
                            ex : struct  student s1={ 123 , 67.89};
               Accessing structure contents:
                     Syntax : Dot operator ( . )   structure-name . structure-member;
                           Arrow operator(->) pointer to structure. Structure member.

Union: It permits several different data types to be stored in the same memory space on single name. Union save the memory space but it can handle only one member at
             a time.
               Union definition: Syntax:    union  union-name
                                                           {
                                                             data-type member 1;
                                                              data-type member 2;
                                                              …………………
                                                                                                                        };     
                Union declaration: syntax :   union   union-name   variable;       
Memory Allocation Functions: Memory allocation classified in to two categories.
1)      Static memory allocation, which is at, compiles time.
2)      Dynamic memory allocation which is at run time.
a)      Allocating a block of memory:
                                             Syntax: ptr = (cast-type*)  malloc(n* (sizeof(data-type));
b)      Allocating multiple blocks of memory:
               Syntax:  ptr=(cast-type*) calloc (n, sizeof(data-type));
c)      Releasing the used space:
                                             Syntax:    free(ptr);
                   d) Altering the size block:
                                  Syntax :   ptr = realloc(ptr, newsize);
File Handling Functions: File is a collection of similar type of records. fwrite(),
                              fread() files are binary files ,remaining files are  ASCII files
                   a) Declaration of file pointer:
                                                                 Syntax:  FILE  *fp;
b) File opening:
                                   Syntax: fp = fopen("filename",mode);
                                        if  mode = r   Open in reading mode.
                                                      = w  Open in writing mode.
                              c) File closing:
                                                                Syntax:   fclose(fp);
                              d) Character i/o from files
                                                                Syntax:  fgetc(fp);
                                                                          fputc( character,fp);
                              e) String i/o with files:
                                                                syntax:   fgets( string,length,fp);
                                                                           fputs(string,fp);
                               f) Formatted i/o  with files
                                                                          fscanf(fp,"control string",list);
                                                                          fprintf(fp,"control string",list);

f)       Records i/o with files: Used to perform i/o operations on binary files.
                                               fwrite( &structure,size of one record,,no.of records,fp);
                                                      fread(  &structure,size of struct,no. of records,fp);

                               h) Random access to files:
                                                     To returns current offset position in the file.
                                                                          long int n=ftell(fp);
                                                     To reposition the pointer at the beginning of file
                                                                           rewind(fp);
                                                     To shift in current position on a file.
                                                                            fseek(fp,offset,position);
 i)  Error handling:
                   Test end of file condition.
                                                                Syntax:  feof(fp);
                                                 Test status of file an error has been detected.
                                                                Syntax:  ferror(fp);
   DOS CAMMANDS
                The book is summarizes the main features and used of data structures, using
      C  programming language under MS_DOS operating system, hence the following
         DOS  commands helps to use the operating system
File: A file consists of group of characters. A file consists of two
            parts:  1. File name           Ex:  STAFF
            2. Extension           Ex: TXT, .EXE, .COM, .DOC, .DAT, .PAS,
                                               .C, .CPP, AND.BAT
Directory: A directory is nothing but group of files like:
    Ex:    File name            file size             date of creation            time of creation
             CMRIT.EXE     22                        27-08-03                       12.00AM
                                                  DOS Commands: There are basically two types of commands:
                                                                                                         1. Internal Commands
                                                       2. External Commands
       1. Internal Commands: These commands are generally loaded when an operating system itself is loaded into the memory. So these commands are stored in computer main memory.     Ex: CLS, DIR, TYPE, TIME, DATE, REN etc.
2. External Commands: These commands are stored in Disk Files. Stored in Secondary memory like disk. Ex: FORMAT, MEM etc.
                         MS-DOS Prompt: C:     \ MYDIR                                     
TIME: This command displays time of system and ask the user to change if he wants
                                              Syntax: TIME
      DATE: This command displays date of the system and asks the user to change
                     if he wants.             Syntax: DATE
DIR: This command displays contents in the directory.
                                               Syntax: DIR </Options>
    COPY : By using this command a user can copy various file into another file and also copy a group files from one directory to other directory and also copy a group files from one disk to the other disk.        .
                                  Syntax: COPY <File1> <File2>
                                   COPY  <File1><Directory Name>
                                   COPY  < Disk1 > < Disk>
                                                    Ex: COPY  my.txt your.txt
                                                           COPY  my.txt c:\tc
                                                           COPY c: \my. txt a:
                        TYPE: Displays the content of the file
                                Syntax: TYPE <FILE>
                               Ex: TYPE AUTOEXEC.BAT
REN: Renames one file to another name. It will changes the filename.
                          Syntax: REN <File!> <File2>
                               Ex:  REN my.txt cmrcet.txt
CLS: Clears the screen
                           Syntax: CLS        
                               Ex: CLS
      CD: Changes the directory
                           Syntax: CD <Directory Name>
                               Ex: CD CMRIT
                                      Changes from any directory to Parent directory
                                      CD\
                                      Changes from any Directory to Root directory
 MD: Creates a new sub-directory. A sub-directory is nothing but directory with in
             a Directory
                           Syntax: MD<Directory Name>

No comments:

Post a Comment