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

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();

       }

Posted Date: 10/18/2012 7:50:37 AM | Location : United States







Related Discussions:- Program of function overloading in c++ , Assignment Help, Ask Question on Program of function overloading in c++ , Get Answer, Expert's Help, Program of function overloading in c++ Discussions

Write discussion on Program of function overloading in c++
Your posts are moderated
Related Questions
Can you overload a function depend only on whether a parameter is a value or a reference? A: No. Passing by value and reference looks identical to the caller.

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

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]

Define a structure of student class:  Write a program to define a structure of student record in C. class student { char name[20]; int roll_no; int marks[2];

Floating  literal They can be written in common decimal as well as scientific notation (floating point representation). By default it is of type double. F, L is applied only to

Static Variables Static variables have the similar scope s automatic variables, but, unlike automatic variables, static variables retain their values over number of function ca

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

one of the segments is showing compilation error...

Here is a short program. It prints out the value of a variable "x". Ernie and Bert disagree about what will be printed: Ernie says, the value gets changed in "changeX" so it will p

#write a program that counts the number of occurances of the string in the n-th padovan string p(n)