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

Program is to define a class as employee, Program is to define a class as e...

Program is to define a class as employee: Write a program to define a class as employee and collect information about them by using classes and object class employee   {

Make c++ program that help health visitor statistics, Pupils' heights The ...

Pupils' heights The health visitor at a school is going to measure the heights of all pupils. For each class she makes a statistics giving the number of pupils of each height and

Define variable declaration in c++, Variable Declaration This declarati...

Variable Declaration This declaration of variables in the C language is permitted only in the starting of their block, prior to executable program statements. In C++ declaratio

Structured design of programs, Within software engineering, software is ver...

Within software engineering, software is very rarely written by a single software engineer. Usually a team of engineers write a program; therefore a formal structural design approa

Char, how many bytes required to char

how many bytes required to char

Command-line arguments, Command-line arguments are passed into programs usi...

Command-line arguments are passed into programs using the arguments of main(). Here's a quick example, for a program called by typing "progname file.txt 1 2.7": #include #incl

Program to calculation of mortgage interest rates, This assignment builds o...

This assignment builds on Homework 3. The two major modifications are the instruction of pointers and the calculation of mortgage interest rates. Requirements for Project 2:

Named what can derived class add?, New data members  New member function...

New data members  New member functions  New constructors and destructor  New friends

Write a program to illustrate array of structures, Write a program to illus...

Write a program to illustrate array of structures? struct customer { int id; char name[15]; }; struct customer c[100]; . In the above instance, the array of Structures is

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