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?

3 Comments:

Anonymous Anonymous said...

If the work involves just concatenation of two strings then any of ruby, shell, perl, python scripts could be used. But in real industry the work is much more than concatenating 2 strings. If you're part of the industry already you wouldn't have posted this blog, if you're not you'll learn sooner or later. You could use java instead of c++ if you wish.

November 16, 2006 11:26 AM  
Blogger olexandr said...

Is this joke?

#include <iostream>
#include <string>

int main() {
std::string a = "John";
std::string b = "Doe";

std::cout << a << b << std::endl;
return 0;
}

February 05, 2007 5:31 PM  
Blogger blrmaani said...

I agree Ruby is cool. Scripting languages are not scalable when used as part of the embedded systems (atleast not for now). They have their own overheads.

March 05, 2007 5:10 PM  

Post a Comment

Links to this post:

Create a Link

<< Home