Hello There, Guest! RegisterLogin with Facebook
Login with Facebook

New Anna University Nov / Dec 2016 Examination Important Questions
New Anna University (UG / PG) Nov/Dec 2016 and Jan 2017 Theory , Practical Exam Timetable
>>> Anna University Sixth Semester Question Bank Collection (R2013) ECE,MECH,CSE,IT,EEE,CIVIL,EIE
>>> Anna University November/December 2015 Examination Question Papers
>>> Anna University Study Materials for all Departments
>>> Anna University Question Papers : April May June 2015 Question Papers | Nov Dec 2014 and Jan 2015 Question Papers

Register or Login to Submit Study Materials , Shoutbox and also to access Many Features !!

Vidyarthiplus Shop :: Handwritten Premium Lecture Notes
Share your Study Materials with us
Share your Study Materials with us : Click Here

Operators and functions in oops
#1


Operator:

An operator is a symbol that specifies an operation to be performed.

The basic types of operators are:
  • Arithmetic operator

  • Relational operator

  • Logical operator

  • Conditional operator

Arithmetic operators: +, - , *, /, %, ^

    They are used to perform some arithmetic operations.

Relational operators: <,>,<=,>=,!=, ==
    They are used to compare values.These operators return either true or false.

Logical operators: &&, ||, !

    These are the basic logical operators and they are used in decision making statements.

Conditional operator: ?:
     
    This operator is known as conditional operator. It may also be called as ternary operator.

A c++ program to perform arithmetic operations:
Code:
#include<iostream.h>
#include<conio.h>
class arith
{
 private:
    int opt,num1,num2,res;
 public:
    void getdata()
    {
      cout<<"enter your option\n 1.add\n 2.sub\n 3.mul\n 4.div";
      cin>>opt;
      cout<<"enter the first number";
      cin>>num1;
      cout<<"enter the second number";
      cin>>num2;
 
    }
};
void main()
{
  arith a;
  a.getdata();
  switch(opt)
  {
     case 1:
          cout<<"ADDITION";
          res=num1+num2;
          cout<<"result of addition is"<<res;
          break;
     case 2:
          cout<<"SUBTRACTION";
          res=num1-num2;
          cout<<"result of subtraction is"<<res;
          break;

      case 3:
          cout<<"MULTIPLICATION";
          res=num1*num2;
          cout<<"result of multiplication is"<res;
          break;
      case 4:
          cout<<"DIVISION";
          res=num1/num2;
          cout<<"result of division is"<<res;
          break;
      default:
         cout<<invalid choice";
         break;
   }
 getch();
}
     
Quote:Output of the above program:
enter your option
1. add
2. sub
3. mul
4. div
1
enter the first number
25
enter the second number
25
ADDITION
result of addition is 50


Functions:

   Functions are the building blocks of any program.The program which is implemented using functions will be more effective since it establishes reusability of code.
  
Parts of function:
  • Declaration

  • Definition

  • Calling
Here the declaration part is optional.The function may or may not be declared.But the when the functions are used in the program, then it must be defined and called.

Syntax:
  
 return_type fun_name(arguments)

Example:
 void fun()

Calling functions:
  
  The function may or may not contains arguments.The function may be called in three ways:
  •   Passing no arguments and returning nothing
  •   Passing arguments and returning nothing
  •   Passing arguments and returning something
A program implemented using functions:
Code:
#include<iostream.h>
#include<conio.h>
class fun
{
 private:
   int n;
 public:
   void getdata(); // Fnction declaration
   void showdata()
   {

     cout<<"REGISTER NUMBER:"<<regno;
     cout<<"BRANCH:"<<branch;
   }
};
void fun::getdata() // function definition
{
 cout<<"enter your register number";
 cin>>regno;
 cout<<"enter your branch";
 cin>>branch;
}
void main()
{
 fun f;
 f.getdata();
 f.showdata();
 getch();
}  

 


Fear is a reaction,but courage is a destination


Reply
#2

Nicethread @arthi how did u insert the text box

Thanks to V+ Bye1


Reply
#3


just click the "insert code" icon in the toolbar

Fear is a reaction,but courage is a destination


Reply

Subscribe


Recommend on Google