Computer Science, asked by malikhassan2, 6 months ago

Create a myString class. 1. An overloaded method for subtracting two myString objects. All the characters common to first and second string object should be subtracted from first string. Result: reduced first string. Result should be stored in a third object which shall be returned. 2. An overloaded ‘>’ operator to check if first myString object is longer than the second. A bool value should be returned. In main program, create a menu allowing usage of the above methods.

Answers

Answered by Anonymous
1

Answer:

// C++ Program to concatenate two string

// using unary operator overloading

#include <iostream>

#include <string.h>

using namespace std;

// Class to implement operator overloading

// function for concatenating the strings

class AddString {

public:

// Classes object of string

char s1[25], s2[25];

// Parametrized Constructor

AddString(char str1[], char str2[])

{

// Initialize the string to class object

strcpy(this->s1, str1);

strcpy(this->s2, str2);

}

// Overload Operator+ to concat the string

void operator+()

{

cout << "\nConcatenation: " << strcat(s1, s2);

}

};

// Driver Code

int main()

{

// Declaring two strings

char str1[] = "Geeks";

char str2[] = "ForGeeks";

// Declaring and initializing the class

// with above two strings

AddString a1(str1, str2);

// Call operator function

+a1;

return 0;

Similar questions