Thursday, December 8, 2011

Counting Words in a String using C

Counting words in a String using C:
This is very good exercise to test new programmers pointer skills. The task is to count the words in a given string using C. Well there might be many ways you can do it, I will demonstrate mine way.
Note that mine solution might not be the optimal one, but it gets the job done.

Operator Overloading using Friend Functions with Complex Numbers

Operator overloading using friend functions:


Operators can be overloaded in c++ with friend functions also. The procedure is same as we discussed earlier. Here I will demonstrate operator overloading with "+" operator which is a binary operator. I will be using a complex number class (called complex). The class will have 2 data types, real and imaginary.
Operator overloading will not be a part of class complex, but we will declare that this function is a friend of class complex.