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

Related Posts:

  • Single inheritance in C++ 1.) single inheritance -> A derived class with only one base class, is known as single inheritance. -> When a single class is derived from a single parent class, it is called Single inheritance. It is the simplest o… Read More
  • multilevel Inheritance in C++ 3.)  Multilevel - Inheritance *In this type of inheritance, a derived class is created from another derived class.      *If a class is derived from another derived class then it is called multilevel inh… Read More
  • Hybrid - Inheritance in C++ 5.) Hybrid - Inheritance   What is Hybrid ? The inheritance in which the derivation of a class involves more than one form of any inheritance is called hybrid inheritance. Basically C++ hybrid inheritance is&nb… Read More
  • Hierarchical - Inheritance in C++ 4.)  Hierarchical - Inheritance  Inheritance is the process of inheriting properties of objects of one class by objects of another class. The class which inherits the properties of another class is called Derived… Read More
  • multiple inheritance in C++ 2.) multiple inheritance Multiple inheritance occurs when a class inherits from more than one base class. So the class can inherit features from multiple base classes using multiple inheritance. This is an important… Read More

Translate

Popular Posts