Skip to main content

C++ Program to implement Operator Overloading for String Comparison with relational op (+, , ==)


#include
#include
#include
using namespace std;

 
class CStrings{
    private:
        char str[20];
    public:
        void getdata();
        friend CStrings operator+(CStrings&, CStrings&);
        friend int operator<(CStrings&, CStrings&);
        friend int operator>(CStrings&, CStrings&);
        friend int operator==(CStrings&, CStrings&);
    };
 
void CStrings :: getdata(){
    cout<<"\n Enter a String: ";
    cin>>str;
    }
 
CStrings operator+(CStrings &s1, CStrings &s2){
    CStrings Os;
    strcpy(Os.str, s1.str);
    strcat(Os.str, s2.str);
    cout<<"\n Concatenation of Str1 & str2: "<
    return Os;
    }
 
int operator<(CStrings &s1, CStrings &s2){
    if(strcmp(s1.str, s2.str) < 0)
        return 1;
    else
        return 0;
    }
 
int operator>(CStrings &s1, CStrings &s2){
    if(strcmp(s1.str, s2.str) > 0)
        return 1;
    else
        return 0;
    }
 
 
int operator==(CStrings &s1, CStrings &s2){
    if(strcmp(s1.str, s2.str) == 0)
        return 1;
    else
        return 0;
    }
 
void main(){
    clrscr();
    CStrings Ostr, Ostr1, Ostr2;
 
    cout<<"\n Enter the Information:-"<
    Ostr1.getdata();
    Ostr2.getdata();
 
    cout<<"\n String Concatenation:-"<
    Ostr = Ostr1 + Ostr2;
 
    cout<<"\n String Comparison:-"<
    if(Ostr1 < Ostr2)
        cout<"\t str1 is less than str2";
    else if(Ostr1 > Ostr2)
        cout<"\t str1 is greater than str2";
    else if(Ostr1 == Ostr2)
        cout<"\t str1 and str2 are equal.";
 
    getch();
    }


Comments

Popular posts from this blog

13 websites to register your free domain

Register your Free Domain Now!! 1)  .tk Dot TK is a FREE domain registry for websites on the Internet. It has exactly the same power as other domain extensions, but it’s free! Because it’s free, millions of others have been using .TK domains since 2001 – which makes .TK powerful and very recognizable.  Your website will be like www.yourdomainname.tk . It is free for 1 year. It’s a ccTLD domain whixh having the abbreviation  Tokelau. To create a .tk domain, Visit   www.dot.tk 2) co.cc Co.cc is completely free domain which is mostly used by blogspot bloggers because of it’s easy to use DNS system. Creating a co.cc for blogger is simple ( for instructions- “click here”). Your website will be like www.yourdomainname.co.cc . To create a .co.cc domain, visit www.co.cc 3)   co.nr co.nr is too like co.cc. Your website will be like  www.yourdomainname.co.nr . You can add it for blogger also.. To create a .co.cc domain, vi...

Binary Search Tree in C++( dynamic memory based )

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 #include<bits/stdc++.h> using namespace std; struct bst { int val; bst * left, * right; }; bst * root = nullptr; void srch ( int num,bst * head) { if (head == nullptr){ cout << " \n Number is not present \a " << endl; return ; } if (head -> val == num) { cout << " \n Number is present \n\a " ; return ; } else { if (num < head -> val) srch(num,head -> left); else srch(num,head -> right); ...

C++ Program to implement Operator Overloading with binary arithmetic op (*,+,-)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 Define a class complex with two data members real & imag. Perform the following operations: – Find the sum of two complex numbers – Find the difference of two complex numbers – Find the Product of two complex numbers – Find the Product of a complex number with a constant

Track Lost Android Phone and Tablet

1. Use the IMEI Number Every Android phone carries a unique IMEI number. It will be printed at the back of your device. If you are unable to find the number, you have to launch your phone app and dial the number *#06#. This will give you the IMEI number of your phone. Store this number in a safe place so that it helps you in locating your phone when it is lost 2 Android Device Manager Google has recently released a new locator feature for Android gadgets called Android Device Manager, which helps its users locate their lost or stolen phones and tablets. It functions in the same way as Lookout and Samsung’s “Find My Mobile”. Here’s how to use Android Device Manager. Go to the Google Settings app, then select Android device manager. By default, the locator feature is activated but to activate remote data wipe, select the box next to “Allow remote factory reset”, then select “activate”. To use this feature, open the site https://www.google.com/android/devicemanager and sig...

Binary Search Tree in Java implementation (reference based, dynamic memory)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 import java.util.Scanner ; class BST { static BST . Node root = null ; public void insert ( int num ) { if ( root == null ) { root = new BST . Node ( num ); } else { // root node is not empty BST . Node temp = root ; while ( temp != null ) { if ( num <= temp . getVal ()) { if ( temp . getLeft () != null ) temp = temp . getLeft (); ...

Exception Handling in Java

Exception Handling() it is an event that stops the normal flow of execution of the program and terminates the program abnormally. Exception always occurs at runtime. There Is two type of Exception: Checked Exception.:-The exception which is checked by the compiler at the compilation time. Ex: IOException,ClassNotFoundException. Unchecked Exception: The Exception which Cant be checked by the compiler at the compilation time and directly occurs at runtime is called an unchecked Exception. Ex:NullPointerException,StringIndexOutOfBoundsException. Error: Error is the type of unchecked Exception which occurs due to programmers mistake, end-user input mistake, resource unavailability or network problem etc. OutOfMemoryError StackOverFlowError etc. 5 keywords to handle Exception: try catch finally throw throws possible combination: try-catch try-catch-catch try-catch-finally try finally try-...

Live bootable linux usb

Unetbootin ..  UNetbootin has built-in support for automatically downloading and loading the following distributions: Ubuntu, Debian, Fedora, PCLinuxOS, Linux Mint, Sabayon Linux, Gentoo, MEPIS, openSUSE, Zenwalk, Slax, Dreamlinux, Arch Linux, Elive, CentOS, Damn Small Linux, Mandriva, SliTaz, FaunOS, Puppy Linux, FreeBSD, gNewSense, Frugalware Linux, NetBSD but can work with others too. Link... Download from here UNetbootin can also be used to load various system utilities, including: Parted Magic , a partition manager that can  resize , repair, backup, and restore partitions. Super Grub Disk , a boot utility that can  restore and repair  overwritten and misconfigured GRUB installs or directly boot various operating systems Backtrack , a utility used for network analysis and penetration testing. Ophcrack , a utility which can recover Windows passwords. NTPasswd , a utility which can reset Windows passwords and edit the registry. ...

How To Add A Background Image Behind Your Blogger Posts

n this latest blog i will show you how to use an image in the background of your blog posts.This background image will only be behind the post area of your blog. Once you choose your image here's how to add it to your blog: 1.Click 'Layout'-->'Edit html' For your blog 2.Find the following piece of code in your blogs html: (Click'CTRL F' on your keyboard for a search box to help find code) #main-wrapper { You will see ' #main-wrapper { 'Followed by code similar to this : #main-wrapper { float: left; width: 486px; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; word-wrap: break-word; /* fix for long text breaking sidebar float in IE */ overflow: hidden; /* fix for long non-text content breaking IE sidebar float */ } 3.Now add the following code Directly Below ' #main-wrapper { ' background:url(PUT IMAGE URL HERE) repeat top right; /* background-attachment: fixed; */ 4.Replace the text 'PUT IMAGE URL HERE...

how to Send a Confirmation Email Upon Form Submission-Woofoo

When someone successfully submits an entry, you can automatically send them a confirmation email to let them know. You can customize the email to include any follow-up info you'd like, and you can choose to include a copy of their entry in the email as well. To set up confirmation emails in Form Settings: Log in and go to  Forms . Hover over  Edit  next to the form you want to edit. Choose  Edit form . Click the  Form Settings  tab. Under Confirmation Options, select  Send Confirmation Email to User . From the  Send To  dropdown, select an Email field from your form. We'll send the confirmation email to the email address the person filling out your form entered into this field. If the dropdown says "No Email Fields Found", add an  Email  field to your form. In the  Reply To  textbox, enter the reply-to email—if someone replies to their confirmation email, this is the email address that their reply will be s...

Internet Download Manager (IDM}

Internet Download Manager (IDM) is a tool to increase download speeds by up to 5 times, resume and schedule downloads. Comprehensive error recovery and resume capability will restart broken or interrupted downloads due to lost connections, network problems, computer shutdowns, or unexpected power outages. Simple graphic user interface makes IDM user friendly and easy to use.Internet Download Manager has a smart download logic accelerator that features intelligent dynamic file segmentation and safe multipart downloading technology to accelerate your downloads. Unlike other download managers and accelerators Internet Download Manager segments downloaded files dynamically during download process and reuses available connections without additional connect and login stages to achieve best acceleration performance. Internet Download Manager supports proxy servers, ftp and http protocols, firewalls, redirects, cookies, authorization, MP3 audio and MPEG video content processing. IDM integra...