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++

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

Constructor and destructor function with derived classes, Constructor and D...

Constructor and Destructor function with derived classes If there are constructors included in the base class and the derived class, the compiler automatically calls both of th

Age guessing game, Write a program that predicts users’ age (0-128 years ol...

Write a program that predicts users’ age (0-128 years old) with at most 7 questions. The game starts with asking the user whether he/she is younger or older than G (an initial gues

Primary data type in cpp, What are  P r im a r y D a t a T y p...

What are  P r im a r y D a t a T y p es? Integer can be defined according to the size of the data and it can be modified further by using keyword unsigned and si

Luminous Jewels - The Polishing Game, Damjibhai and Shamjibhai are two jewe...

Damjibhai and Shamjibhai are two jeweler friends. They decide to play a simple game. The game comprises of removing the jewels for polishing, turn by turn. Once a jewel is removed

Bank account system, To implement a back account system for new users

To implement a back account system for new users

C program to allocate memory dynamically for 2-d array, Aim: To implement ...

Aim: To implement a program to allocate memory dynamically for 2 dimensional array (accept and print matrix) using pointers. Code:                       #include #inc

C programming assignment, good night i have an assignment that i really nee...

good night i have an assignment that i really need help with. i have to create a struct file with tag name book to have members int book_id char isbn[255]

Loops, how do i print out invalid input?

how do i print out invalid input?

Curve, Write a program to find the area under the curve y = f(x) between x ...

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

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