Simple C++ Program to show the use of class
#include <iostream>//Author: Shubham Patil
//copyright
using namespace std;
class person{
char name[30];
int age; //private variables by default
public:
void getdata(void);
void display(void);
};
void person::getdata()
{
cout<<"Enter name: ";
cin>>name;
cout<<"Enter age: ";
cin>>age;
}
void person::display()
{
cout<<"name="<<name;
cout<<"\tage="<<age;
}
int main()
{
int m;
cin>>m;
person *p = new person[m]; //dynamically allot memory
for(int i=0;i<m;i++) //input data for each object
{
p[i].getdata();
}
for(int i=0;i<m;i++) //display for each object
{
p[i].display();
}
return 0;
}
0 Comments