c++ creating class person with two private variable name and age and two public functions
//create class person with two private variable name and age and two public fn void get data and void put data
#include<iostream>
using namespace std;
class person
{
char name[50];
int age;
public:
void getdata();
void putdata();
};
void person::getdata()
{
cout<<"Enter the name : ";
cin>>name;
cout<<"Enter the age";
cin>>age;
}
void person::putdata()
{
cout<<"Name : "<<name;
cout<<endl<<"age : "<<age;
}
int main()
{
person m;
m.getdata();
m.putdata();
return 0;
}
#include<iostream>
using namespace std;
class person
{
char name[50];
int age;
public:
void getdata();
void putdata();
};
void person::getdata()
{
cout<<"Enter the name : ";
cin>>name;
cout<<"Enter the age";
cin>>age;
}
void person::putdata()
{
cout<<"Name : "<<name;
cout<<endl<<"age : "<<age;
}
int main()
{
person m;
m.getdata();
m.putdata();
return 0;
}
OUTPUT-
Enter the name : bum
Enter the age21
Name : bum
age : 21
Comments
Post a Comment