16 Aug 2019

  • August 16, 2019
  • Amitraj




 



// cpp program to display age using class          By Amit purohit
http://codevidyalay.blogspot.com

#include<iostream>
using namespace std;
class person
{
char name[10];
int age;
public:
void getdata()
{
cout<<"Enter a name:";
cin>>name;
cout<<"Enter age";
cin>>age;
}
void showdata()
  {
  cout<<"name is:"<<name<<endl;
  cout<<"age is:"<<age;
  }
};
int main()
{
person p;
p.getdata();
p.showdata();
return 0;
}

INPUT/OUTPUT:-
Enter a name:Amit
Enter age 18
name is:Amit
age is:18

Translate

Popular Posts