Friday, 26 January 2018

Create a class called Person, that has member data name. Include member functions getdata() to get data from the user, and putdata() function to display its data. Write a main( ) program that creates an array of pointers, persPtr[100] to Person. In a loop, ask the user for data, and use new to create an object of type Person to hold the data. Put the pointer to the object in the array. When the user has finished entering the data for all the persons, use a for loop and a single statement such as persPtr[I]->putdata( ) to display the data from each object in the array. C++ GTU

#include<iostream>
using namespace std;
class person
{
    string name;
    public:
    void getdata()
    {
        cout<<"ENTER NAME : ";cin>>name;
    }
    void putdata()
    {
        cout<<"NAME : "<<name<<endl;
    }
};
main()
{
    int n,i;
    person *persptr[100];
    cout<<"ENTER NUMBER OF PERSON : ";cin>>n;
    for(i=0;i<n;i++)
    {
        persptr[i]=new person;
        persptr[i]->getdata();
    }
    cout<<"\nPRINTING DETAILS:\n";
    for(i=0;i<n;i++)
    {
        persptr[i]->putdata();
    }
}

No comments:

Post a Comment

It's time To increase blogging capability. To have a chance to contribute in digital world. Any Interested People who want to make t...