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

What output does this program generate as shown? Why? class A { A() { cout << "A::A()" << endl; } ~A() { cout << "A::~A()" << endl; throw "A::exception"; } }; class B { B() { cout << "B::B()" << endl; throw "B::exception"; } ~B() { cout << "B::~B()"; } }; int main(int, char**) { try { cout << "Entering try...catch block" << endl; A objectA; B objectB; cout << "Exiting try...catch block" << endl; } catch (char* ex) { cout << ex << endl; } return 0; }

575


write a program that can LOCATE and INSERT elements in array using c++ programming languages.

3431


How to Split Strings with Regex in Managed C++ Applications?

3120


How can I Draw an ellipse in 3d space and color it by using graph3d?

2130


Code for Method of Handling Factorials of Any Size?

2000






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

2214


solve the problem in the programming language C++"if a five digit number is input through the keyboard.Write a program to calculate the sum of its digits(hint: use the modulus operator)

2930


write a program that reads a series of strings and prints only those strings begging with letter "b"

2668


Implement a command console for changing settings on a particular object. The command console should allow you to enter a string and will return the response (very similar to a terminal session). The commands are as follows: SET propertyname=newvalue will change the target object’s member named “propertyname” to have a value equal to “newvalue”. If the input value is incompatible (i.e. an int being set to a string), print out an appropriate error message. GET propertyname will print out the current value of the target object’s member named “propertyname”. GET * will print out a list of all target object members and their current values. The system should be extensible for future commands and should accept an arbitrary object, such that another developer could insert another object into the system and rely on the command console to get and set the properties correctly.

3393


write a function that reverse the elements of an array in place.The function must accept only one pointer value and return void.

3952


Code for Easily Using Hash Table?

2385


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

3262


Definition of priority queue was given. We have to implement the priority queue using array of pointers with the priorities given in the range 1..n. The array could be accessed using the variable top. The list corresponding to the array elements contains the items having the priority as the array index. Adding an item would require changing the value of top if it has higher priority than top. Extracting an item would require deleting the first element from the corresponding queue. The following class was given: class PriorityQueue { int *Data[100]; int top; public: void put(int item, int priority); // inserts the item with the given priority. int get(int priority); // extract the element with the given priority. int count(); // returns the total elements in the priority queue. int isEmpty(); // check whether the priority queue is empty or not. }; We had to implement all these class functions.

4392


how to take time as input in the format (12:02:13) from user so that controls remains between these columns?

1813


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

4349