C-Tutorial: BASICS

Latest

Showing posts with label BASICS. Show all posts
Showing posts with label BASICS. Show all posts

Saturday, 19 November 2016

SOFTWARE DEVELOPMENT METHOD (or) Soft Development Life Cycle

Saturday, November 19, 2016 0
SOFTWARE DEVELOPMENT METHOD


            
Modern projects are built using a series of interrelated phases commonly referred as the software development life cycle (SDLC).  The exact number and name of the phases of SDLC are differing from one environment to other.  One of the popular development life cycles is Water fall model. 

            The main important phases in software development method are:

1.                  Requirement gathering & Analysis
2.                  Algorithm & Flowchart
3.                  Program Design
4.                  Testing
5.                  Deployment
6.                  Maintenance

1. Requirement gathering & Analysis:
Ø  Requirements are gathered in this phase
Ø  In this phase project managers and stack holders are involved
Ø  Meeting with managers, stake holders and users are held in order to determine the requirements
·         who is going to use the system
·         how will they use the system
·         what data should be input into the program
Ø  After gathering requirements these requirements are analyzed and incorporate the requirements  into the system
Ø  Finally a requirement specification document is created, which serves guideline for the next phase
:                      
            Analysis phase is also referred as specification requirement analysis.  In this phase, analyze the given problem to determine the input requirements and the expected output.

Example:         Problem Statement                  :           Addition of given two values

Input requirements      :           Read two numbers as A and B
                        Expected output         :           Addition Value as A+B


2. Algorithm & Flowchart (or) System design:  In this phase the system and software design is prepared from the requirement specification. Solution of the given problem statement is represented interms of a step-by-step procedure is known as an algorithm.  The steps of the algorithm is represented in the form of a pictorial representation is called as a flowchart.

Example:         Algorithm & Flowchart for addition of given two values



 Algorithm:
Step 1: START
Step 2: READ A, B
Step 3: sum ← A + B
Step 4: WRITE sum
Step 5: STOP

Flowchart

3. Program Design (Code/Implementation):  After receiving/completing system design documents, the work is divided into modules/units and actual coding is started. The flowchart and algorithm steps developed in the previous phase is converted into actual programs by selecting any programming languages like C, C++ etc., This is the longest phase in software development method.

Example:         Program for addition of given two values in C language

#inlcude<stdio.h>
            #include<conio.h>
            main()
            {
                        int x,y,sum;
                        clrscr();
                        pritnf(“\nEnter Two Numbers:”);
                        scanf(“%d%d”,&A,&B);
                        sum = A+B;
                        printf(“\nTotal:%d”,sum);
            }

4. Testing & Validation: After the code is developed it is tested against the requirements. To make sure that the product is actually solving the needs that are gathered during the requirements phase. During this phase unit testing, integration testing, system testing and acceptance testing are done. In this phase, the program is tested by submitting proper input values.  And then program is validated with different valid inputs.  With this, the program is maintained for future re-use.

Example:

           Input               :           Enter  Two Numbers   :           10        20
           Output             :           Total                            :                 30

5. Deploment: After completing the testing process the devloped product delivered to the customer is called deployment.

6. Maintenance: Once when the customer starts using the developed system then the actual problems comes up and needs to be solved from time to time. This process whose take care by the developed product is known as maintenance.
Read More

TYPE CONVERSION (or) CASTING

Saturday, November 19, 2016 0
TYPE CONVERSION (or) CASTING


The process of converting data item from one data type to another data type is called type casting.
Conversion rank procedure is:

Type casting can be classified into two types as:

1. Implicit Type Casting
2. Explicit Type Casting


1. Implicit Type Casting: If the operands are of different data types, the lower data type is automatically converted into the higher data type by the compiler before the operation proceeds.  Such conversion is known as implicit type casting.  Implicit type casting is also known as automatic type conversion.
In implicit type casting, the result is in higher data type and there is no loss of data.

Example: int i,j;
float p;
double d,r;
r= i*j + p/j +  p*d;
int*int + float/int + float *double
int + float + double
float + double
double

2.  Explicit Type Casting: Users can also be convert the data items from one data type to another data type.  Such conversion is known as explicit type casting.

For explicit type casting, the target data type placed within in parenthesis before the data item.

The general format of explicit type casting is:

Syntax: (TargetDataType) Expression;

Here,
Expression may be a constant, variable, or any expression.

In explicit type casting, there may be a loss of data which converting from higher data type into lower data types.

Example:

int x=14, y=3;
float z;

z = x/y; z = (float) x/y;

z = 14/3; z = 14.000000/3;
z = 4.000000; z = 4.666667

/* EXAMPLE PROGRAM FOR TYPE CASTING */

#include<stdio.h>
#include<conio.h>
main()
{
int x,y,z,total;
float avg;
clrscr();
printf("\nEnter Three Values:");
scanf("%d%d%d",&x,&y,&z);
total=x+y+z;
avg=(float)total/3;
printf("\nAverage Result:%f",avg);
}
Read More

Saturday, 29 October 2016

Difference between malloc and calloc in C

Saturday, October 29, 2016 0
Difference between malloc and calloc


malloc()
calloc()
malloc allocate the memory at runtime
calloc allocate the memory at runtime
The name malloc stands for memory allocation.
The name calloc stands for contiguous allocation.
malloc() takes one argument that is, number of bytes.
calloc() take two arguments those are number of blocks and size of each block.
malloc() initializes the allocated memory with garbage values.
calloc() initializes the allocated memory with 0 value.
Syntax :
int * ptr = (casttype *) malloc(n * sizeof(int));
Syntax:
int * ptr = (casttype *) calloc(n, sizeof(int));
Ex:  int n=5;

                 10bytes
Ex:  int n=5;





    2bytes     2bytes        2bytes          2bytes          2bytes
The malloc() function allocate single block of memory
The calloc() function allocate multiple blocks of memory
Read More

Difference between while and do-while in C

Saturday, October 29, 2016 0
Difference between while and do-while in C


WHILE
DO-WHILE
while ( condition)
 {
statements; //body of loop
}
Do
{
statements; // body of loop.
} while( Condition );
In 'while' loop the controlling condition appears at the start of the loop.
In 'do-while' loop the controlling condition appears at the end of the loop.
The iterations do not occur if, the condition at the first iteration, appears false.
The iteration occurs at least once even if the condition is false at the first iteration.
#include<stdio.h>
#include<conio.h>

main()
{
int i=1,n;
clrscr();
printf("\nEnter how many numbers:");
scanf("%d",&n);
printf("\nNatural Numbers Are:");
while(i<=n)
            {
                        printf(" %3d",i);
                        i++;
            }
}

main()
{
int i=1,n;
clrscr();
printf("\nEnter how many numbers:");
scanf("%d",&n);
printf("\nNATURAL NUMBERS ARE:");
            do
            {
                        printf("%5d",i);
                        i=i+1;
            }
            while(i<=n);
}

Read More

Difference between structure and union in C

Saturday, October 29, 2016 0
Difference between structure and union


STRUCTURE

UNION
Allocation of memory
Members of structure do not share memory. So A structure need separate memory space for all its members i.e. all the members have unique storage.
A union shares the memory space among its members so no need to allocate memory to all the members. Shared memory space is allocated i.e. equivalent to the size of member having largest memory.
Members access
Members of structure can be accessed individually at any time.
At a time, only one member of union can be accessed.
Keyword
To define Structure, ‘struct’ keyword is used.
To define Union, ‘union’ keyword is used.
Initialization
All members of structure can be initialized.
Only the first member of Union can be initialized.
Size
Size of the structure is > to the sum of the each member’s size.
Size of union is equivalent to the size of the member having largest size.
Syntax
struct struct_name
{
datatype member _1;
datatype member _2;
.................................datatype member_n;
}struct_variable_name;
union union_name
{
datatype member_1;
datatype member_2;
———-
datatype member_n;
}union_variable_name;
Change in Value
Change in the value of one member can not affect the other in structure.
Change in the value of one member can affect the value of other member.
Read More

DIFFERENCE BETWEEN ARRAY AND POINTER

Saturday, October 29, 2016 0

DIFFERENCE BETWEEN ARRAY AND POINTER 

ARRAY
POINTER

1. Array is a collection of homogeneous data elements that are stored in successive memory locations.
1. Pointer is a variable that holds address of another variable.
2. The general form of array declaration is :
Syntax    :   Datatype ArrayName[size];
Example :  int x[10];
2. The general form of a pointer variable declaration is :
Syntax    :   Datatype *PtrVaribale;
Example :  int *ptr;
3. The general form of initializing a array is:
Syntax   :
Datatype Array[size]={List of values};

Example: int x[4] = {2,5,1,7};
3. The general form of initializing a pointer variable is:
Syntax   :   PtrVariable = &Variable;

Example:  int x, *p;
                  p = &x;
4. For an array, compiler allocates memory space based on the size of the array.
Example:   int x[5];

Here, compiler allocates 10 bytes of memory for the variable x.
4. For any type pointer variables compiler allocates only 2 bytes of memory.

Example:  int *p;     char *q;

For p compiler allocates 2 Bytes and for q also compiler allocates 2 Bytes memory.
5. sizeof(arrayname) gives the number of bytes of the memory occupied by the array.
5. sizeof(pointervaraible) returns only 2 bytes.
6. For arrays only static memory allocation is possible.
6. For pointer variables dynamic memory allocation is possible.
7. Arrays can’t be resized.
7. Pointer allocation can be resized using realloc() function.
8. It cannot be reassigned.
8. It can be reassigned.
9. /* Example Program */

#include<stdio.h>
#include<conio.h>
main()
{
     int x[5]={2,4,6,1,3},i;
     clrscr();
     printf(“\nArray Elements Are=”);
     for(i=0;i<5;i++)
     printf(“    %d”,x[i]);
}

9. /* Example program for Pointer */

#include<stdio.h>
#include<conio.h>
main()
{
    int x = 10, *p=&x;
    clrscr();
    printf(“\nResult = %d”,*p);
}
Read More