Rashakil Fol 978 Super Senior Demiposter Team Colleague

That's right.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

That depends on who's doing the considering. Many languages have constructs that make it easy do object oriented programming, that wouldn't necessarily be considered object oriented languages.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Rashakil,

Seems like a good logic let me try to implement this.
But dont u think that then also I have to walk thru the array twice?

Well, no, you don't; I've implemented this before. And even if you did, what's worng with walking through the array twice? It's still linear time.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

What do you mean by 'search engine'? What are you searching?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

1. It is a way of thinking, especially organizationally. Different tasks are the responsibilities of different objects. For example, in C++, it's the responsibility of the vector to reallocate its own memory as needed, not some that of some procedure that uses the vector.

2. It's a way to create a dynamic typing system. This means I can have and use a Shape object and have it be an Ellipse, a Rectangle, or generalised Polygon without knowing what's underneath. Relative to C, this is C++'s biggest advantage.

3. It's a way of shortening code size and treating data consistently. Instead of needing to se different names, as in vector_get(v,i) and string_get(s,i) and map_get(m,i), you can write v.get(i) and s.get(i) and m.get(i). (Or, depending on the programming language and library, v, s, and m.)

It's not really about hiding implementation, since you can do that in any language with subroutines.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

You could try the Internet.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Then you mean the maximum sublist sum, not subset.

First, you can convert the list into a list of cumulative sums, turning [5,-2,10,-4] into [0,5,3,13,9]. Then walk through the list of cumulative sums, saving the smallest value so far and the maximum difference between what you see as the current value and what is currently the smallest value.

Of course, you don't have to actually create a list of cumulative sums; you can keep track of the cumulative sum as you walk through the first list.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Search the forum or the web for ideas -- there are zilliards of people who ask this question.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

So how then would you find the point of intersection for two lines in 3D space?

You don't unless you're lucky.

And then you would use gaussian elimination to find the point of intersection, assuming of course the two lines actually intersect. Is this logic completely bogus?

The intersection of those two planes forms a line.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

A 3D line can be represented by:-

x + y + z = <number>

No, that's a plane. A 3D line can be represented with two points on the line. For example, (0,3,4) and (3,2,1). Alternately, you can represent a 3D line with a point on the line and a point (or 'vector') representing the direction the line is going. For example, (0,3,4) and (3,-1,-3). Then the formula (0+3t, 3-1t, 4-3t) will compute points on the line based on the real number t. I think the second form tends to be more convenient, if you're representing a 'line', and not a line segment.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

>I'm a CS student and as far as my experience tells me
I'm thinking you need some more experience if you can't tell that 2004 was two years ago.

But 2004 was only 1.5 years ago :-)

Rashakil Fol 978 Super Senior Demiposter Team Colleague

What do you mean by 'algorithms'? Do you just want to memorize a bunch of algorithms? (Pretty useless; you can just look them up in a book.) Or do you want to be good at picking the right algorithm for your task? (Pretty useful.) Or do you want to be good at inventing algorithms to suit your needs? (Requires creative thinking, which you get by experience inventing algorithms to suit your needs.)

A combination of the three is what you want, I guess. It is not necessary to 'master' calculus or theory of computation to get a hold on Algorithms. (There is nobody in the world who has 'mastered' calculus or theory of computation, anyway.) Discrete mathematics, however, is very useful. Particularly, make yourself understand big O notation (otherwise, you won't understand how algorithms' running times and memory usage is measured).

I also strongly recommend making yourself have a solid understanding of proof by induction (part of any decent discrete mathematics course). (People who understand proof by induction and can actually put it into practice are better at writing anything that uses a while loop or recursion, because induction is often needed in order to convince yourself that a while loop or recursive function is programmed correctly. And vice versa -- people who write loops and recursive functions without a second thought are usually those who understand induction quickly.) If you want to understand _why_ an algorithm takes a certain amount of time, you'll need to use proof …

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Here's another Haskell version.

main = mapM_ (putStrLn . show) [1..10]
Rashakil Fol 978 Super Senior Demiposter Team Colleague

I think Python is a good language to start with.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Well talking about python as we all know that it has all the qualities that good prgg. lang. should have and is the amalgum of all the best features or the famous langs.

This is just untrue. Python does not have macros the way Lisp and Scheme have macros, and it does not have lazy evaluation. No good support for anonymous closures.

Why doesn't (lambda x: print x) work?

SO y does it not replace all the langs. existing and rule the world.
Why is C++ so powerful and famous when even Python can offer all the features and much more?

Why is Python the ideal when there are other, 'better' languages out there? Why not Lisp? Why not Haskell?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Yes. Perl, Python, and Ruby all have good string handling abilities. Python's not really based on Perl, though.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

char *p="test";

if i try:

*p="s"; -----error: invalid conversion from 'const char*' to 'char'

You're trying to assign the memory address of the array, "s", into the zeroth character of the string "test". This isn't an error of const vs. non-const; these are fundamentally different types. You could do p = "s" just fine -- this would modify p so that it contains the memory address of the array "s".

is it because when one declares
char *p="test"; p is implied as a const?

More like, "test" is immutable no matter what you assign its memory address to.

What happens when you compile with the option "-Wall" (turn all warnings on)? Does it warn you about char *p = "test"?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I see contradicting replies in this case. How come? I agree with the part where other information can be overwritten. But is this illegal?

Well, the behavior is certainly undefined. You don't want to unpredictably overwrite other variables, do you?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Rookie Disclaimer.

I am confused about what is the difference between:

A: char *p="string";

"string" in this case is an array stored in some global location, and only seven bytes have been allocated for that string. (One is for the character with integer value zero that marks the end of the string.) p is the memory address of that string. By adding one to p, you increase that memory address by the width of one character, so p then contains the memory address of the 't'. You can't strcat onto it because there are only 7 bytes of space for it, and the bytes after the string are used for other information.

B: char q[10]="string";

Here, you have a locally stored array, and you're using "string" as an initializer. You can't change the value of q because that's just not allowed in C -- when used in an expression, q is treated as the memory address of the zeroth element of the array. One reason that you can't make q point to something else, other than q, is that sizeof(q) should return 10, the size of the array in bytes, and that would not make sense if it were a general char* style pointer. Compiled code is able to access the contents of the array more direcly (and quickly) because of this restriction.

You can't strcat " test" onto q, either, because q is an array that is 10 characters wide. You're trying to store 12 characters in …

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I'd guess a good starting place is http://en.wikipedia.org/wiki/IDNA

Rashakil Fol 978 Super Senior Demiposter Team Colleague

He did use srand actually...

The problem, Woobag, is that you're only supposed to seed the random number generator once. If you seed it every time you run rand, then you're resetting the random number generator back to its original state each time! So use srand once - as Ancient Dragon shows.

EDIT: I figured out a much easier way of calculating a rand num that didnt involve all the typecasting (rand()%RANGE_MAX)+RANGE_MIN;

Use the method you were working with previously. The random number generator will not be as 'random' if you scale your values with this method. This depends on the random number algorithm rand uses, but common implementations work better with the other method.

Oh, and it would be (rand() % (RANGE_MAX - RANGE_MIN)) + RANGE_MIN and likewise ((double) rand() / (double) RAND_MAX) * (RANGE_MAX - RANGE_MIN) + RANGE_MIN. Your code works fine, though, as long as RANGE_MIN is zero...

I am hoping you are trying to generate a number that is greater than or equal to RANGE_MIN and (strictly) less than RANGE_MAX.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

4) I have an inch long scar on my leg from when I was 12 and got hit by a spear.

What?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Assemply should be spelled Assembly.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

No.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Microsoft will either split into smaller companies, or it will spend 50 years dying.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

PHP

Did I just actually recommend using PHP? Oh god no! Anything but PHP. That was just an example of what /other/ people use :-)

Rashakil Fol 978 Super Senior Demiposter Team Colleague

The error message was very clear. Check your spelling.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

As for delete[] - this belongs to the last actions I have to do. My primary concern at the moment is that the code starts running as it is supposed to do :-) Optimization belongs to the last stage before giving up the ready code and will be done, I can assure you.

This is absolute nonsense. A memory leak is not something that you 'optimize' with progressive improvements. Either it leaks and is broken, or it doesn't. If you're not going to write code that you know is correct, it is not surprising that it doesn't work. Go through every function in your code and explain why it works correctly. Write it down. You must be able to do this for every correct function -- thus you'll find where your code fails.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Attempt to run the program after restarting your computer, if that does not work then make sure that your opperating system supports the program that you're attempting to run

Could you, um, please explain your reasoning?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Logic - 1

Put 34 gold coins in one bag, and put 66 gold coins and two pennies in the other.

Or, put fifty coins in one bag, fifty in the other, and then put one bag inside the other.

Logic - 2

This doesn't count as a logic puzzle. Somebody's using some liberal twisting of words.

Logic - 3

Take one rope and tie it into a large round knot. Take the other rope and tie it around the knot so that you have a pendulum equal in length to your height (since that is a known measurement). Then use the length to compute the period of the pendulum, and use the pendulum to measure 45 minutes.

Or, you could light both ends of one rope -- it will burn up in 30 minutes. So light both ends of rope A and one end of rope B. When rope A burns up, light the other end of rope B, and you'll have 15 minutes left.

Logic - 4

You can weigh in groups.

Animals

snake - 6
cock - 4

Take the length of the word, then subtract three for every consecutive repeated letter, and give a +1 bonus for words that don't have the letter o.

Or you could give a general -3 penalty for any repeated letter -- then cock would have a score of 1.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Narue tried to kill this thread because nobody could say anything nice about her, but then in doing so created something nice to say about her, in that she tried to kill this thread.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Hmm, but what separates perl from c++? The fact that the regex utilities are built in as opposed to the boost libraries in c++ that are not?

It's quite simple. You can get a lot more done in Perl in a given amount of time than you can with C++. It's not worth the extra effort to use C++ because you don't get any considerable speed benefit. You'd be better off paying for a better server and using Perl than you would be using C++ on one cheap server, because bandwidth and perhaps database access time is the main limitation on the end-user's perception of speed.

#!/usr/bin/perl -ap
eval(("\$s[-2]$_=pop\@s",'push@s,$_')[!/^[-+*\/]$/])for@F;$_="$s[-1]\n"

Nothing beats having a one-line RPN calculator, too.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

If you want to write CGI programs in C or C++, and want to know how it works, read this tutorial: http://www.cs.tut.fi/~jkorpela/forms/cgic.html

This is not how Google does things, though. What do you think web servers like Apache are written in? C and C++. Google has its own software that is a specialized web server.

You should not be using C or C++ to dynamically serve your web documents, not because you can't, or for technical reasons, but because it's really much easier to use a language like PHP that's more suited for the purpose.

I think it would help if you understood a bit about how HTTP works. One computer sends a request to another, looking something like

GET /search?q=foo+bar HTTP/1.1
Host: www.google.com

Then the other computer replies with some information followed by the webpage. The computer that sends the request has no idea what the server is doing on what languages are used to write the web server, and it doesn't care.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

What separates students in college is not their preexisting knowledge of a particular language, it's their problem solving ability (which is called creativity). Therefore, I recommend solving some problems with a language that doesn't have as much to come out and bite you. This will give you more experience trying to solve the problem you're solving, not the problems the languages C and C++ give you. Knowing different languages also causes you to think of different approaches towards solving a problem. So, I recommend solving some problems using the language Python. This will give you the best head start.

I don't know how good you are, so the following list will be in increasing difficulty. All these could be written using command-line style input and output. I don't expect you to complete all of them -- if you did, that would mean the list was too short.

- Write a program that asks for a person's name, then says "Hi, _____!".
- Write a program that prints the Nth Fibonacci number.
- Write a program that prints the Nth row of Pascal's Triangle.
- How many prime numbers are there between 1 and 10000?
- Write a program that tells how many prime numbers there are between 1 and the Nth Fibonacci number.
- Write an RPN calculator, with the functions +, -, *, and /.
- Add built-in functions that let you swap the bottom two elements of the stack, or …

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Well, I certainly agree it's not a good idea to put all your personal information anywhere on the web if you're a child.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

a) Who are you to tell people what to do on the Internet?
b) You think he wouldn't be out to 'solicit sex' from children if MySpace didn't exist?

Should they also ban Yahoo! from having user accounts? I got a 'sexual solicitation' from somebody in my area, reading my Yahoo! account profile, who communicated this to me by emailing to my Yahoo!email address. This was in 2000, when I was thirteen.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

1. Sam I am.
2. I do not like to eat green eggs and ham.
3. Reading that book was the first time I realized that names were not unique.
4. Reading http://qntm.org/ was the first time I realized that it is possible to find a person who has the same first name, same last name, same major, same interests, the exact same set of attitudes and opinions as you, and even puts fractals in his web design, which is exactly what I did for my site.
5. Read number 4 again. That is really uncanny.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

What do you mean by 'random'? What is the range of these numbers? If they're numbers from 0 to 99, then you can prefill the array, do a random_shuffle on them, and then go through the array looking for numbers at their own indices. Whenever you get them, swap them with a randomly numbered index (other than itself). Then you're done.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

oh honestly I'm not answering that question :P

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Put a button on the right, above the search box. And make it catch the eye. Or so I would recommend. Or keep it in the same location, but make it catch the eye.

On the home page, I'd recommend having a listing of all your main forums (using short names, like "C/C++", "PHP", and such) packed together in a wide rectangle, under an oval banner titled, "forums", beneath "DaniWeb Home / Forum Index" and above the bar and ad beneath. Or if you want to keep that ad in the same position there, put the forum names to the left of the ad and push the blog entries listing down.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I continue to nag about making the Post a New Thread button more visually obvious. I remember having a hard time finding it, and now some newbie is on IRC chat trying to find out how to post a new thread.

Usability-wise, I keep getting the impression that this forum is pretty bad. It could be made so much better.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

So, in this problem, are your distances large enough for the sphericity of the Earth to make a difference?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Well, you have 21 digits, which means that the number of bits used for each letter must be a factor of 21... hint hint

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Could you be more specific? How do you want it translated? Your post is vague and makes no sense.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Yes. Want to know how?

It's operating system specific, but one general option is to use the 'system' procedure. Or, if you're using a Unixy operating system and want more control over how things are done, look at execve and its friends ('fork' followed by 'execv' will start a new process. You'd have to understand how these work, which you can do by, um, reading documentation). (If you're looking at a Windows operating system, you can find documentation on its API online somewhere too.)

Rashakil Fol 978 Super Senior Demiposter Team Colleague

You know how the bitwise operators work, right? You know how to add two numbers in binary, or can look that up, right? Flex your creativity muscles, or you'll continue to be unable to solve your own problems.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

There are many ways. You could do how you do it on paper. You could use the property x + y = (x-1)+(y+1).

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Yes, that is what you're assuming :)

And yes, there is no limit to the number of initializers. (Hopefully you don't use more initializers than you have variables... :))

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Your syntax for initializers is incorrect. Use only one colon, then separate with commas.

class Point
{
    friend void setX( Point &, int ); 
    friend void setY( Point &, int ); 
  public:  
    Point() 
      : xCoordinate( 0 ), yCoordinate( 0 ) 
    {
 
    }
Rashakil Fol 978 Super Senior Demiposter Team Colleague

Oh, wait, my answer was dumb and wrong, because if they're evenly distributed random numbers, then S = 0.5n....

You can't come up with any reasonable answer with just the information you've been given. You could for small values of n and extreme values of S, for example if n = 2 and S = 1.6, or the opposite case, n = 2 and S = 0.4. But if n = 2 and S = 1, or if n = 3 and S = 1, then you're out of luck.

Unless you either
(a) know what pattern the numbers tend to be distributed, or
(b) get an extreme case where all the numbers must lie in one of the halves,
you cannot make any nontrivial claims about the expected values of n1, n2, S1, and S2.