Answer to Question #15908 in C# for leena
Question #15908
Define a class called MyString with these features:
1) An overloaded binary + operator that concatenates two MyString objects & create a third object.
2) An overloaded comparison == operator to comapre two strings.
3) An overloaded unary - (minus) operator that returns true if the string object is empty otherwise false.
1) An overloaded binary + operator that concatenates two MyString objects & create a third object.
2) An overloaded comparison == operator to comapre two strings.
3) An overloaded unary - (minus) operator that returns true if the string object is empty otherwise false.
Expert's answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public class MyString
{
& public String plus(String a, String b){
return a + b;
& }
& public bool compare(String a, String b)
& {
return a == b;
& }
& public bool minus(String a)
& {
return a == "";
& }
}
class Program
{
& static void Main(string[] args)
& {
String a;
a = "string";
String b;
b = "string";
MyString c = new MyString();
c.compare(a, b);
& }
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public class MyString
{
& public String plus(String a, String b){
return a + b;
& }
& public bool compare(String a, String b)
& {
return a == b;
& }
& public bool minus(String a)
& {
return a == "";
& }
}
class Program
{
& static void Main(string[] args)
& {
String a;
a = "string";
String b;
b = "string";
MyString c = new MyString();
c.compare(a, b);
& }
}
}
Need a fast expert's response?
Submit orderand get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Comments
Dear visitor
It's a complete code, it should work properly
Is this a complete coding ! Not running the program successfully.
Leave a comment