1.program to add any two objects using operator overloading
2.program to add any two objects using constructors
3.program to add any two objects using binary operator
4.program to add any two objects using unary operator

Answer Posted / vikas

/*Program to add two object using operator overloading */
/* vikas */

#include<iostream.h>
#include<string.h>
#include<stdio.h>
#include<conio.h>



class Stadd
{
private:
char p[20];
public:

void set(char *k)
{
strcpy(p,k);
}
Stadd operator+(Stadd c)
{
Stadd l;
strcpy(l.p,p);
strcat(l.p,c.p);
return l;
}
void display()
{
cout<<"The string is = "<<p;
}
};

void main()
{
char m[]="vikas";
char n[]="kumar";
Stadd ws,wt,wu;
ws.set(m);
wt.set(n);
wu=ws+wt;
wu.display();
getch();
}

Is This Answer Correct ?    38 Yes 18 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

write a program that prompt the user to enter his height and weight,then calculate the body mass index and show the algorithm used

4582


write a program that creates a sequenced array of numbers starting with 1 and alternately add 1 and then 2 to create the text number in the series , as shown below. 1,33,4,6,7,9,............147,148,150 Then , using a binary search , searches the array 100 times using randomly generated targets in the range of 1 to 150

3467


3. Program to find the Sum of give series. a. (1)+(1+2)+(1+2+3)+(1+2+3+4)+……………………………….. b. 1/1+1/9+1/25+1/49+……………...

4568


Write a C/C++ program that connects to a MySQL server and displays the global TIMEZONE.

4759


Write a program that print in screen a tree with its height taken from user by entering number of 4 digits and find the odd numbers then calculate the sum of odd numbers so he get the height of tree?

3123






Write a C++ program without using any loop (if, for, while etc) to print prime numbers from 1 to 100 and 100 to 1 (Do not use 200 print statements!!!)

3491


create a stucture student containing field for roll no,class,year and marks.create 10 student annd store them in a file

2429


Code for Method of Handling Factorials of Any Size?

2175


How to swap two ASCII numbers?

2650


Write a simple encryption program using string function which apply the substitution method.

5786


Ask the user to input three positive integers M, N and q. Make the 2 dimensional array of integers with size MxN, where all the elements of I (I = 1,…,M) line will be members of geometrical progression with first element equal to the number of line (I) and denominator q.

3613


Code for Two Classes for Doing Gzip in Memory?

2986


Teta-Omeg-Big-Oh Show that f(n) = n2 + 3n3 is ;(n3).

3366


how to write a program that opens a file and display in reverse order?

2767


Given a table of the form: Product Sold on A 1/1/1980 B 1/1/1980 C 1/1/1980 A 1/1/1980 B 1/1/1980 C 2/1/1980 A 2/1/1980 There are 30 products and 10,000 records of such type. Also the month period during which sales happened is given to u. Write the program to display the result as: Product Month No. of copies A January 12 A February 15 A March 27 B January 54 B February 15 B March 10 C January 37

2409