Search This Blog

Thursday 28 January 2016

Writa a C++ program using class which contains two member functions getdata and putdata to read the information(name and age) of the person and disply it on the screen respectively. Use Scope Resolution Operator

#include<iostream>
using namespace std;

class Person
{
      int age;
      char name[10];

      public:

      void getdata();

      void putdata();
};

void Person::getdata()
{
cout<<"\nEnter name:";
cin>>name;
cout<<"Enter age:";
cin>>age;
}
void Person::putdata()
{
cout<<"\nName:"<<name<<endl;
cout<<"Age :"<<age<<endl;
}
int main()
{
Person p;
p.getdata();
p.putdata();
return 0;
}

No comments:

Post a Comment