arrays with animation

Upload: drgopi-krishna

Post on 04-Jun-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 Arrays With Animation

    1/8

    Computer Programming for Engineering

    ( Course Code: EECP 1290 )

    Lecturer : P. GOPI KRISHNAB.Tech, M.Tech, (Ph.D), MIE,MISTE

    Arrays Conceptwith Animations

  • 8/13/2019 Arrays With Animation

    2/8

    Today Topics

    1. What is Array?

    2. Why Use Array?

    3. Where Arrays will be useful?

    (i.e Applications of Arrays)

    4. How arrays are used with some

    Programming Examples

  • 8/13/2019 Arrays With Animation

    3/8

    1. Introduction to Arrays:

    char v[0]=a, v[1]=e ,v[2]=i ,v[3]=o ,v[4]=u ;

    The same will be represented easily aschar v[5]={ a , e , i , o, u} ;

    char grade[6]={ A, B , , D , E , F}

    char fruits[4]= {apple, banana, cherry, mango }

    char subject[4]= { C++, Physics,Chemistry, Maths}

    int marks[11]={100, 90, 80 , 70, 60, 50,40,30,20,10,0}

    int speed[5]={80, 60, 40,20,0}

    In the above lines vowel[5], grade[6], fruits[4],

    subject[4], marks[11], speed[5] are ARRAYS.

  • 8/13/2019 Arrays With Animation

    4/8

    What is Array ? Name of array is c

    Position number of

    the element within

    array c

    c[6]

    -456

    0

    72

    1543

    -89

    0

    62

    -3

    1

    6453

    78

    c[0]c[1]

    c[2]

    c[3]

    c[11]

    c[10]

    c[9]

    c[8]

    c[7]

    c[5]

    c[4]

    int c[12]={-45,6,0,72,1543,-89,0,62,-3,1,6453,78}

    Here c[0], c[1] ,c[2] . . . ., c[10], c[11] are

    Variable names.

    Now let us define array ?

    An array is a sequence of variablenames that shares same name c forvariables c[0], c[1] ,c[2] . . . ., c[10], c[11] .

    A single dimensional array is just like

    one row of MATRIX.

    A multi dimensional array is just like

    MATRIX with rows and columns.

  • 8/13/2019 Arrays With Animation

    5/8

    Why use Array ? Arrays are useful to store a large number of values

    of the same data type.Where Array are useful? (Applications)

    To create students data base with marks, details

    Bank Applications, Industry &Scientific applications ,Air Ticket Reservations, .

    In all these applications a large data will be stored

    and retrieved (recall).

  • 8/13/2019 Arrays With Animation

    6/8

    How Arrays Used ?The array syntax is as follows

    Datatype ArrayName[Length];

    Examples:

    char grade[6]={ A, B , , D , E , F}

    char fruits[4]= {apple, banana, cherry, mango }

    char subject[4]= { C++, Physics,Chemistry, Maths}

    int marks[11]={100, 90, 80 , 70, 60, 50,40,30,20,10,0}

    int speed[5]={80, 60, 40,20,0}

  • 8/13/2019 Arrays With Animation

    7/8

    Program to Print Elements of Arrayint _tmain(int argc, _TCHAR* argv[])

    {int i;int Marks[5] = {96, 85, 59, 90, 76};

    for(i=0 ; i

  • 8/13/2019 Arrays With Animation

    8/8

    Program to Print Elements of Array in REVERSE ORDER

    int _tmain(int argc, _TCHAR* argv[])

    {int i;int Marks[5] = {96, 85, 59, 90, 76};

    for(i=4 ; i >= 0 ; i=i-1 )

    {

    cout=0 YES

    Marks[1]=85 85

    i= 1-1=0

    0 >=0 YES

    Marks[0]=96 96

    i= 0-1=-1

    -1 >=0 NO

    Program Ends

    M[0] M[1] M[2] M[3] M[4]