C++ code into Ruby, I need it fast, no time for RTFM

[code]
#include <iostream.h>
#include <conio.h>

void r_string(int n, int v)
{
int i;

for(i=0;i<n;i++)
{
cout<<"v["<<i<<"]=";
>>v[i];
}

}

void p_string(int n, int v)
{
int i;
cout<<"\nThe string is : ";

for(i=0;i<n;i++)
    cout<<v[i]<<" ";

}

float avarage_string(int n, int v)
{
int i,s=0;
float av;
for(i=0;i<n;i++)
s+=v[i];

av=(float)s/n;

return av;
}

void main()
{
clrscr();

int no, a[20];
cout<<" no = ";

no;

r_string(no,a);
p_string(no,a);

cout<<"String avarage is : "<<avarage_string(no,a);

getch();
}
[/code]

Strings value are read from the keyboard, and i need a getch and clrscr
method.
And how can I export the ruby code into *.exe ?

Can somebody translate this into ruby ? I need it fast...

···

--
Posted via http://www.ruby-forum.com/\.

DYOH - Do Your Own Homework

···

On 4/25/07, Andrei Ursan <steelheart222@gmail.com> wrote:

Strings value are read from the keyboard, and i need a getch and clrscr
method.
And how can I export the ruby code into *.exe ?

Can somebody translate this into ruby ? I need it fast...

Please read:
http://www.catb.org/~esr/faqs/smart-questions.html#urgent

Then read the whole of the rest of that document.

···

On Wed, Apr 25, 2007 at 06:29:35PM +0900, Andrei Ursan wrote:

Can somebody translate this into ruby ? I need it fast...

Translate this for me, right now. No, by yesterday. == A time when you pay someone to do it. Or ask much nicer. But if you are trying to say that you're going to learn Ruby by comparing that C++ code to some Ruby code that accomplishes the same thing, you are either fooling us OR fooling yourself. Ruby and C++ are different enough that a side-by-side comparison isn't going to teach you much of anything in this case. It would more likely just confuse you, friend.

···

On Apr 25, 2007, at 6:29 PM, Andrei Ursan wrote:

[code]
#include <iostream.h>
#include <conio.h>

void r_string(int n, int v)
{
int i;

for(i=0;i<n;i++)
{
cout<<"v["<<i<<"]=";
>>v[i];
}

}

void p_string(int n, int v)
{
int i;
cout<<"\nThe string is : ";

for(i=0;i<n;i++)
    cout<<v[i]<<" ";

}

float avarage_string(int n, int v)
{
int i,s=0;
float av;
for(i=0;i<n;i++)
s+=v[i];

av=(float)s/n;

return av;
}

void main()
{
clrscr();

int no, a[20];
cout<<" no = ";
>>no;
r_string(no,a);
p_string(no,a);

cout<<"String avarage is : "<<avarage_string(no,a);

getch();
}
[/code]

Strings value are read from the keyboard, and i need a getch and clrscr
method.
And how can I export the ruby code into *.exe ?

Can somebody translate this into ruby ? I need it fast...

--
Posted via http://www.ruby-forum.com/\.

Andrei Ursan wrote:

[code]
#include <iostream.h>
#include <conio.h>

void r_string(int n, int v)
{
int i;

for(i=0;i<n;i++)
{
cout<<"v["<<i<<"]=";
>>v[i];
}

}

void p_string(int n, int v)
{
int i;
cout<<"\nThe string is : ";

for(i=0;i<n;i++)
    cout<<v[i]<<" ";

}

float avarage_string(int n, int v)
{
int i,s=0;
float av;
for(i=0;i<n;i++)
s+=v[i];

av=(float)s/n;

return av;
}

void main()
{
clrscr();

int no, a[20];
cout<<" no = ";
>>no;
r_string(no,a);
p_string(no,a);

cout<<"String avarage is : "<<avarage_string(no,a);

getch();
}
[/code]

Strings value are read from the keyboard, and i need a getch and clrscr
method.
And how can I export the ruby code into *.exe ?

Can somebody translate this into ruby ? I need it fast...

Well, since you ask _that_ nicely...
This may get you started

print "number of entries: "
no = gets.to_i

a =
no.times do |i|
   print "enter item nr. #{i}: "
   a << gets.to_i
end

p a

puts a.inject(0){|s, x| s + x}.to_f / a.size unless a.empty?

It's rather quick-and-dirty, but then, so was your C++ code.

HTH,

Michael

···

--
Michael Ulm
R&D Team
ISIS Information Systems Austria
tel: +43 2236 27551-542, fax: +43 2236 21081
e-mail: michael.ulm@isis-papyrus.com
Visit our Website: www.isis-papyrus.com

---------------------------------------------------------------
This e-mail is only intended for the recipient and not legally
binding. Unauthorised use, publication, reproduction or
disclosure of the content of this e-mail is not permitted.
This email has been checked for known viruses, but ISIS accepts
no responsibility for malicious or inappropriate content.
---------------------------------------------------------------

Have you gotten a suitable answer yet?

There are several options for you here.
1) Transliterate into Ruby (as you imply)
2) Leave your code as-is and wrapper it using Ruby's C api
3) Leave your code as-is and use the Ruby DL module to load your
library and invoke the methods
4) Use the RubyInline module to simply "inline" your C/C++ code into a
Ruby program

By far the quickest solution is going to be the RubyInline route.
You'll need a compiler installed on your machine to handle the C++
code compilation step RubyInline performs. You can install RubyInline
via the gem command:

gem install -r rubyinline

Shoot a nice note of thanks off to Eric Hodel and Ryan Davis. They've
done a great job with that little gem.

Have fun learning Ruby! I've learned far more about programming by
using Ruby than I ever learned using C/C++ or Java.

Blessings,
TwP

···

On 4/25/07, Andrei Ursan <steelheart222@gmail.com> wrote:

Strings value are read from the keyboard, and i need a getch and clrscr
method.
And how can I export the ruby code into *.exe ?

Can somebody translate this into ruby ? I need it fast...

Andrei Ursan wrote, On 4/25/2007 4:29 AM:

Can somebody translate this into ruby ? I need it fast...

I don't mean to be rude, but I'm with most of the others on this. I found it amusing (is that mean of me?) that you have no time to RTFM, but you have time to wait longer than it would have taken to RTFM for someone to answer. You don't need an entire book for loops and printing strings. Thats page one stuff in any language, I would think.

Richard Conroy wrote:

···

On 4/25/07, Andrei Ursan <steelheart222@gmail.com> wrote:

Strings value are read from the keyboard, and i need a getch and clrscr
method.
And how can I export the ruby code into *.exe ?

Can somebody translate this into ruby ? I need it fast...

DYOH - Do Your Own Homework

It's not homework. I need the code for personal use today. I want to
learn ruby and if i have that code in ruby i can understand some things.
I wan to use ruby code 4 some algorithms and if i have that code
translated i can do it myself the rest of them.

--
Posted via http://www.ruby-forum.com/\.

Translate this for me, right now. No, by yesterday. == A time when
you pay someone to do it. Or ask much nicer. But if you are trying to
say that you're going to learn Ruby by comparing that C++ code to
some Ruby code that accomplishes the same thing, you are either
fooling us OR fooling yourself. Ruby and C++ are different enough
that a side-by-side comparison isn't going to teach you much of
anything in this case. It would more likely just confuse you, friend.

I need that 'cause i want to use ruby for some algorithms, i don't want
to write them in C i want them in ruby. So if i had that example i can
do the rest myself.

···

--
Posted via http://www.ruby-forum.com/\.

doh, sorry to all of you cos i'm not so polite as you want... :frowning: c'est
la vie;
some person aren't so polite but that don't means that they don't
respect your work or help.

Thanks to all off you who tried to help me :slight_smile:

This is what i was trying to do :

[code]
def r_string( n, v )
        n.times do |i|
                print "v[#{i}] = "
                v << readline.to_i
        end
end

def p_string( v )
        print "\nThe string is: " + v.join(" ")
end

def average_string( v )
        v.inject {|sum, x| sum + x} / v.size.to_f
end

print "no = "
no = readline.to_i
a = []
r_string( no, a )
p_string( a )

puts "\nString average is #{average_string(a)}"

readline
[/code]

Thanks again to those who helped me !!
Have a nice day !
(sorry for any speeling mistakes, english isn't my first language )

···

--
Posted via http://www.ruby-forum.com/.

Sammy Larbi wrote:

Andrei Ursan wrote, On 4/25/2007 4:29 AM:

Can somebody translate this into ruby ? I need it fast...

I don't mean to be rude, but I'm with most of the others on this. I
found it amusing (is that mean of me?) that you have no time to RTFM,
but you have time to wait longer than it would have taken to RTFM for
someone to answer. You don't need an entire book for loops and printing
strings. Thats page one stuff in any language, I would think.

No, i did rftm and i'm doing it even now :)) :stuck_out_tongue:
It's ok... I'm fine, don't need to worry 4 me, btw if u have some good
ruby doc pleas links gimme to me i'm ruby doc hungry.

···

--
Posted via http://www.ruby-forum.com/\.

<snip>

DYOH - Do Your Own Homework

Speaking of which, I have a biology lab report due next wednesday, so I need someone to do it for me - make sure it's GOOD!

-------------------------------------------------------|
~ Ari
crap my sig won't fit

···

On Apr 25, 2007, at 5:35 AM, Richard Conroy wrote:

On 4/25/07, Andrei Ursan <steelheart222@gmail.com> wrote:

Just tried RubyInline - amazing!
I had one GCC hiccough on my Ubuntu 6 system, I had to do this:

ln -s /usr/lib/gcc/x86_64-linux-gnu/4.0.3/cc1 /usr/bin/cc1plus

..to get GCC to recognise that G++ had been installed. Otherwise it
gave me this:
gcc: installation problem, cannot exec `cc1plus': No such file or directory

···

On 4/25/07, Tim Pease <tim.pease@gmail.com> wrote:

On 4/25/07, Andrei Ursan <steelheart222@gmail.com> wrote:
>
> Strings value are read from the keyboard, and i need a getch and clrscr
> method.
> And how can I export the ruby code into *.exe ?
>
> Can somebody translate this into ruby ? I need it fast...
>

Have you gotten a suitable answer yet?

There are several options for you here.
1) Transliterate into Ruby (as you imply)
2) Leave your code as-is and wrapper it using Ruby's C api
3) Leave your code as-is and use the Ruby DL module to load your
library and invoke the methods
4) Use the RubyInline module to simply "inline" your C/C++ code into a
Ruby program

You can´t blame C/C++ or Java or any programming language for your
learning skills.

···

On Apr 25, 11:54 am, "Tim Pease" <tim.pe...@gmail.com> wrote:

On 4/25/07, Andrei Ursan <steelheart...@gmail.com> wrote:

> Strings value are read from the keyboard, and i need a getch and clrscr
> method.
> And how can I export the ruby code into *.exe ?

> Can somebody translate this into ruby ? I need it fast...

Have you gotten a suitable answer yet?

There are several options for you here.
1) Transliterate into Ruby (as you imply)
2) Leave your code as-is and wrapper it using Ruby's C api
3) Leave your code as-is and use the Ruby DL module to load your
library and invoke the methods
4) Use the RubyInline module to simply "inline" your C/C++ code into a
Ruby program

By far the quickest solution is going to be the RubyInline route.
You'll need a compiler installed on your machine to handle the C++
code compilation step RubyInline performs. You can install RubyInline
via the gem command:

gem install -r rubyinline

Shoot a nice note of thanks off to Eric Hodel and Ryan Davis. They've
done a great job with that little gem.

Have fun learning Ruby! I've learned far more about programming by
using Ruby than I ever learned using C/C++ or Java.

--
"Minds are like parachutes, they work best when open."
"I know nothing except the fact of my ignorance."
Bruno Patini Furtado
Software Developer
text adventures suite: http://bpfurtado.net/tas
software development blog: http://bpfurtado.livejournal.com
Ruby related topics: http://bpfurtado.livejournal.com/tag/ruby

There are still ways to ask for things.

···

On 4/25/07, Andrei Ursan <steelheart222@gmail.com> wrote:

> Translate this for me, right now. No, by yesterday. == A time when
> you pay someone to do it. Or ask much nicer. But if you are trying to
> say that you're going to learn Ruby by comparing that C++ code to
> some Ruby code that accomplishes the same thing, you are either
> fooling us OR fooling yourself. Ruby and C++ are different enough
> that a side-by-side comparison isn't going to teach you much of
> anything in this case. It would more likely just confuse you, friend.

I need that 'cause i want to use ruby for some algorithms, i don't want
to write them in C i want them in ruby. So if i had that example i can
do the rest myself.

--
Posted via http://www.ruby-forum.com/\.

Still, being polite does not hurt.
And not everyone does read C++ fluently.

As far as I can see, the code is
concerned with printing some stuff.
But I have evaded C++ for long
enough to not be sure about its intention.

What is it that you're trying to do?

We can show you how to do this in Ruby,
which might be surprisingly different from
a line-by-line translation of the code you posted.

s

···

On Wed, 25 Apr 2007 20:44:52 +0900, Andrei Ursan wrote:

I need that 'cause i want to use ruby for some algorithms, i don't want
to write them in C i want them in ruby. So if i had that example i can
do the rest myself.

This is something I can read :slight_smile:
You want to calculate the arithmetic mean of some numbers.

I'd do the following as a basic attempt without any
bells and whistles:

1 lines = $stdin.readlines
2 numbers = lines.collect { |line| line.to_f }
3 total = numbers.inject(0) { |sum, x| sum + x }
4 mean = total / numbers.size
5 puts("Arithmetic mean: #{mean}")

You could insert some filter for non-parseable input
between 1 and 2, skip over the unnecessary calculations
in case there was no input with a conditional between 2 and 3,
show the entered values like you did between 4 and 5.

There's no need to "preallocate" arrays, as you can return
any object in ruby. You can even return multiple objects and
access them immediately or through the wrapping array.

HTH,
s.

···

On Thu, 26 Apr 2007 00:16:01 +0900, Andrei Ursan wrote:

This is what i was trying to do :

Andrei Ursan <steelheart222@gmail.com> writes:

It's ok... I'm fine, don't need to worry 4 me, btw if u have some good
ruby doc pleas links gimme to me i'm ruby doc hungry.

Here's a link for you: <http://www.dictionary.com>

sherm--

···

--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net

http://www.rubycentral.com/book/ (or better: buy the 2nd edition)

http://www.ruby-lang.org/en/documentation/quickstart/

···

On Thu, Apr 26, 2007 at 02:49:45AM +0900, Andrei Ursan wrote:

if u have some good
ruby doc pleas links gimme to me i'm ruby doc hungry.

Guys, let's back off, please. I think the OP has gotten the message
loud and clear.