Program of function overloading in c++ , C/C++ Programming

Assignment Help:

Program of function overloading:

class vector{

                private :

                int v[3];

 

                public:

                /*friend istream & operator >> (istream & ,vector &);*/ //overloading the

                                                                                                                //insertion operator

                                                                                                                // for the vector type object

                friend vector operator * (vector,int);

                friend vector operator * (int ,vector);

 

                vector()  dummy constructor

                {

                }

       vector (int *p);

 

                 void show();

 

                 }; // class termination

 

                /* istream & operator >>(istrream &din ,vector & b )

                                {

                                for( int i=0;i<3;i++)

                                                din >> b.v[i];

                                  return din;//for cascading

                                }*/

 

 

       vector operator *(vector a,int b)//function overloading

                                {          vector c;

                                                for(int i=0;i<3;i++)

                                                                c.v[i]=b*a.v[i];

                                  return c;

                                  }

 

                vector operator *(int a,vector b)

                                {

                                vector c;

                                                for(int i=0;i<3;i++)

                                                                c.v[i]=a*b.v[i];

                                  return c;

 

                       }

      vector:: vector( int *p)

      {

                                for(int i=0;i<3;i++)

                                                v[i]=p[i];

 

                }

                void vector ::show()

                {

                                 for (int i=0;i<3;i++)

                                                cout << "\n"<

                                 }

 

                void main()

                {

                int t[]={ 1,2,3};

                vector a,b(t),c;

                clrscr();

                a=b*10;

                c=20*b;

                b.show();

                a.show();

                c.show();

                getch();

       }


Related Discussions:- Program of function overloading in c++

Copy constructor and an overloaded assignment operator, What is the differe...

What is the difference among a copy constructor and an overloaded assignment operator? Ans) A copy constructor constructs a latest object by using the content of the argument

COMPILER DESIGN, Compiler Design - Limit In The Method Instructions

Compiler Design - Limit In The Method Instructions

A Padovan string P(n) for a natural number n, c program for padovan string ...

c program for padovan string   Padovan series are positive integers obtained by the following process: The Padovan series is the sequence of integers P(n) defined by the

C program to demonstrate pointer to array, C program to demonstrate Pointer...

C program to demonstrate Pointer to array: void p2a(int *); void main() {                 int x=10, *a,**b;                 int arr[5];                 a=&x;//po

Program to calculate pie, This problem familiarizes you with using random n...

This problem familiarizes you with using random numbers in C++. The program is to compute a good approximation of π using a simulation method called "Monte Carlo". The following fi

#CompilerRelated, #C Why don''t online compilers support the header file?...

#C Why don''t online compilers support the header file? What can I do to resolve this? PS. I have tried , does''nt work either. Thannk in advance.

Explain object conversions, Object Conversions Just like initialization...

Object Conversions Just like initialization, conversions are also done automatically when an object of a derived class is assigned to an object of the base class. Though, the c

Mr. D. Mclean, A Network of routers have been configured for the ...

A Network of routers have been configured for the purposes of handling data traffic within your company. You would like to have an application that does a network

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd