Program for Array of Structures


    #include <iostream.h>
    #include <conio.h>
    struct employee
    {
        char name[10] ;
        char address[15] ;
        long int telephone_numbers[5] ;
    } ;
    void main ( )
    {
        struct employee input ( ) ;
        struct employee e[5] ;
        int i, j, n ;
        clrscr ( ) ;
    cout<<"Enter Number of Employees ( less than 5 ) : ";
        cin>>n ;
        for ( i = 0; i < n; i++ )
            e[i] = input ( ) ;

        clrscr ( ) ;
        cout<<"\n\nEmployee Personal Information displayed... \n";
        for ( i = 0; i < n; i++ )
        {
            cout<<"\nName    :  "<<e[i].name<<endl;
            cout<<"Address : "<<e[i].address<<endl;
            cout<<"\nTelephone Numbers :\n";
            for ( j = 0; e[i].telephone_numbers[j] > 0 && j < 5; j++ )
                    cout<<e[i].telephone_numbers[j];
        }
        getch ( ) ;
    }
    struct employee input ( )
    {
        struct employee temp ;
        long int no;
        int i ;

        cout<<"Input the following -\n" ;
        cout<<"Name : " ;
        cin>>temp.name ;
        cout<<"Address : ";
        cin>>temp.address ;
        cout<<"Telephone Numbers : ";
        i = 0;
        cin>>no;
        while ( no > 0 && i < 4 )
        {
            temp.telephone_numbers[i] = no ;
            i++ ;
            cin>>no;
        }
        temp.telephone_numbers[i] = no ;
        return ( temp ) ;
    }

0 comments:

Post a Comment

 
 
 
 


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