C++ Program to Create Class Person and Print Name and Age
Code:
Sample Output:
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;
}
#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:
0 comments:
Confused? Feel free to ask
Post a Comment