Program for Structure passed to a function ( by Value )


    #include <iostream.h>
    #include <conio.h>
    struct student
    {
        int student_roll_no ;
        int marks_in_subject1 ;
        int marks_in_subject2 ;
    } ;
    void main ( )
    {
        void print_structure ( struct student s1 ) ;
        float find_average ( struct student s1 ) ;
        struct student s1 = { 3032, 89, 78 } ;
        clrscr ( );
    /* Structure variable passed by value */
    print_structure ( s1 ) ;
    cout<<"Average Marks  =  "<<find_average ( s1 ) ;
    getch ( ) ;
    }
    void print_structure (  struct student s1  )
    {
    cout<<"Student Record : \n";
    cout<<"Roll Number    :  "<<s1.student_roll_no<<endl;
    cout<<"Subject 1 marks : "<<s1.marks_in_subject1<<endl;
    cout<<"Subject 2 marks : "<<s1.marks_in_subject2<<endl;
    }
    float find_average ( struct student s1 )
    {
        float average ;
        average = s1.marks_in_subject1 + s1.marks_in_subject2 ;
        average = average / 2 ;
        return ( average ) ;
    }

0 comments:

Post a Comment

 
 
 
 


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