Tuesday, May 8, 2012

Program to understand array of object

#include <iostream>
using namespace std;

class info
{
    char name[20];
    int roll;
   
    public:
        void
getinfo()
        {
            cout << "\n Enter name: ";
            cin >> name;
            cout << "\nEnter roll number: ";
            cin >> roll;
        }
   
        void displayinfo()
        {
            cout << "\n\n\tName: " << name;
            cout << "\n\tRollNumber:" << roll;
        }
};

int main()
{
    info obj[5];     //Here i am creating 5 object using array


    for(int i=0; i<5; i++)
    {
        obj[i].getinfo();
    }
   
    for(int i=0; i<5; i++)
    {
        obj[i].displayinfo();
    }
   
    cout << "\n\n";   
}

No comments:

Post a Comment