9 Aug 2019

  • August 09, 2019
  • Amitraj









// c++  program to check given no. is odd or even using class    By Amit raj purohit

http://codevidyalay.blogspot.com

#include<iostream>
using namespace  std;
class number
{
private:
int n;
public:
void getdata()
{
cout<<"Enter a no.";    //  << = insertion operator
cin>>n;    // >> = extraction operator
}
  int oddoreven()
  {
  if(n%2==0)
    return 0;
    else
    return 1;
  }
  void showresult()
  {
  int r;
  r= oddoreven();
    if(r==0)
 
        cout<<"even number";
        else
        cout<<"odd number";
  }

};
int main()
{
number N;
N.getdata();
    N.showresult();
 
    return 0;
}


OUTPUT:
Enter a no.4
even number

Related Posts:

  • 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
  • Types of Operator Overloading in C++ *Overloading Binary Operators:- -> The Binary operators take two arguments and following are the examples of Binary operators. You use binary operators very frequently like addition (+) operator, subtraction (-) operator… Read More
  • Inheritance in C++ Inheritance in C++ The capability of a class to derive properties and characteristics from another class is called Inheritance. Inheritance is one of the most important feature of Object Oriented Programming. Sub… Read More
  • 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
  • Types of Operator overloading in C++ * Overloading unary operators:-      A minus operator when used as a unary, takes just one operand . we knows that this operator changes the sign of an operand when applied to a basic item. we can overlo… Read More

Translate

Popular Posts