Skip to content

Program to Create Class Person and Print Name and Age

 C++ Program to Create Class Person and Print Name and Age

Code:

/*C++ Program to Create Class Person and Print Name and Age*/
#include<iostream.h>
#include<conio.h>
class person
{
    char name[30];
    int age;
    public: void getdata(void);
        void display(void);

};
void person :: getdata(void)
    {
    cout<<“n Enter the Name “;
    cin>>name;
    cout<<“n Enter the Age “;
    cin>>age;
    }

    void person :: display(void)
    {
        cout<<“n Name: “<<name;
        cout<<“n Age: “<<age;
    }
int main()
{
clrscr();
person p;
p.getdata();
p.display();
getch();
return 0;
}

Sample Output:

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!