Sunday 21 February 2016

Operator Overloading String Operations in C++

Q:-Write a C++ program to perform String operations
i. = Equality
ii. == String Copy
iii. + Concatenation
iv. << To display a string
v. >> To reverse a string
vi. Function to determine whether a string is a palindrome
vii.To find occurrence of a sub-string. Use Operator Overloading

Code

Framework:- QT 5.5.1
Os :- Linux 64 bit(Ubuntu 14.04 LTS)
Language :- C++

Thoughts on Operator Overloading

I managed to write concise and clear code, despite the fact that I don't like operator overloading. Being a Java Programmer I prefer a.add(b) constructs as against a+b .

Thought a+b seems more logical in some cases such as of Addition of Matrices. Long Equations involving Matrices can be written way cleaner using operator overloading. Actually operator overloading is a great feature in OOP until abused!

Here are some arguments against operator overloading:-
  1. Its syntactical sugar.
  2. Easier to make mistakes.
  3. Often operator don't do what you expect them to do.
Do refer this also.


Download Link

Includes executables, source files and screenshots

mediafire



No comments:

Post a Comment