Thursday, October 26, 2006

Object Oriented programing

Lets see conventional way of C++ to do some things.

#include

class string
{
char str[20];
public:
string();
void operator+(string &);
void operator>>(istream &);
void operator<<(ostream &);
};

string::string()
{
}

void string::operator + (string &s)
{
cout << strcat (str,s.str);
}

void string::operator>>(istream &din)
{
din>>str;
}

void string::operator<<(ostream &dout)
{
dout<str;
}

void main()
{
string s1,s2;

cout <<"Please enter a string"<s1>>cin;
cout <<"Please enter second string"<s2>>cin;
s1+s2;
}

Now for some Ruby work

#!/usr/bin/ruby
a='harshad'
b='joshi'
c=a+b
print"c"

Job over. Isent Ruby more cool??

Why do Indian engineering institutes and colleges prefer more of C++, when many good options are available?