A very first program in c++ with the concept of class

Posted on August 7, 2014
C++

include<iostream.h>
using namespace std;

class person
{
    private:
        char name[20];
        int age;
    
    public:
         void getdata(void);
         void dislpay(void);
};
void person :: getdata(void)
{
    cout<<"Enter name:";
    cin>>name;
    cout<<"Enter age:";
    cin>>age;
}
void person :: display(void)
{
    cout<<"\nName: " << name;
    cout<<"\nAge: " << age;
}
int main()
{
  person p;

  p.getdata();
  p.display();

  return 0;
}

 

Search