Array of Students as a function argument


    #include <iostream.h>
    #include <conio.h>
    struct student
    {
        int roll_no ;
        int physics_marks ;
        int chemistry_marks ;
        float average_marks ;
    } ;
    void main ()
    {
        void find_average ( struct student a[] ) ;

        /* array of structure initialisation --
           ( average_marks are initially set to 0 ) */
        struct student s[5] = { { 1, 50, 70, 0 },
                        { 2, 67, 89, 0 },
                        { 3, 78, 87, 0 },
                        { 4, 56, 77, 0 },
                        { 5, 49, 45, 0 } } ;
        int i ;
        clrscr ();
        find_average ( s ) ;
        cout<<"Student Information --\n\n" ;
        for ( i = 0; i < 5; i++ )
        {
            cout<< "Student Roll No. :   "<<s[i].roll_no<<endl ;
            cout<< "Physics marks  : "<<s[i].physics_marks<<endl;
            cout<<"Chemistry marks :  "<<s[i].chemistry_marks<<endl;
            cout<<"Average marks : "<<s[i].average_marks<<endl;
        }
        getch ();
    }
    void find_average ( struct student a[] )
    {
        int i ;

        for ( i = 0; i < 5; i++ )
        {
                        a[i].average_marks = a[i].physics_marks + a[i].chemistry_marks ;
                a[i].average_marks /= 2 ;
        }
    }

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|