Rashakil Fol 978 Super Senior Demiposter Team Colleague
Rashakil Fol 978 Super Senior Demiposter Team Colleague

operator() lets your values look like functions.

For example

struct greeter {
  std::string greeting_text;

  int operator()(const std::string& greetee) {
    std::cout << greeting_text << ", " << greetee << "!" << std::endl;
    return 12345;
  }
};

// later:
greeter alien_greet, programmer_greet;
alien_greet.greeting_text = "Greetings";
programmer_greet.greeting_text = "Hello";
int x;
x = alien_greet("earthling"); // prints "Greetings, earthling!"
programmer_greet("world"); // prints "Hello, world!"

std::cout << x << std::endl; // outputs 12345

Generally speaking, operator() tries to provide the ability to create functions that contain internal parameters of their own.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

There's an infinite number of purposes, and only a finite number of languages, so at least one language has to be the best for an infinite number of purposes.

While Python is a decent language, it just doesn't seem to shine at any particular thing. I'd use it if one of its libraries had some ability that happened to be direly useful to me at the moment.

For interacting with the OS (especially Unix OSes), I feel very comfortable with Perl -- more comfortable than with anything else. I can't recommend against Perl. But I keep looking at Lua (haven't used it) and it just seems very nice.

I think anything but PHP is tolerable. It's not like you're only allowed to learn only one language -- I end up using different languages for different things, anyway.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I do not know what you mean by 'scripting language,' so I'll take it to mean 'a language with garbage collection, rapid development, and general ease of use.'

PERL, Python, LUA, PHP etc.

Perl is a good language for short programs that need to chop text around, and it's a trippy language to learn, too. Python is a somewhat decent language, big on batteries but small on power. (I'm such a language bigot, aren't I?) PHP is utter crap. Well, I'm being a bit mean about PHP, since people use it to do useful things, but it's just about the most poorly designed language that is frequently used today. It's basically a retarded version of C++, and that's only a bit more powerful and versatile than assembly language.

Lua is an excellent programming language, and of the four you have mentioned, I recommend it the most. The reasons are simple: it's simple, and it's got closures, first class functions, and proper tail calls. But this is still not my recommendation...

the most powerful and versatile scripting language.

It is quite simple: every other language you will see in this thread has a set of features that is a subset of the features of Common Lisp. I recommend learning Lisp for a few reasons:

1. It's the most powerful and versatile language*. (Or maybe some other variant of Lisp is; this is just standardized and the most popular.)
2. If you learn Lisp, you'll never have …

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Tea. Earl Grey. Hot.

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

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

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

If all you have is an AK-47, everything looks like an enemy combatant.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Iraq doesn't cost many American lives, only several thousand. We should stay in there, then invade Iran, followed by Pakistan, India, Sri Lanka, Bangladesh, Burma, Thailand, and so on. After we conquer Australia we'll get two extra soldiers every turn, and that should make rolling through Asia like a walk in the park.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

= is the assignment operator, not equivalence test operator, and you probably declared a as const.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Um... yes. But not with the + operator, of course; with some specially built procedure. I don't know what you mean by 'add', either, but surely there's some way for you to write the algorithm.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I'm not sure what you mean exactly by "using char instead of string," but if that means something like

for (int i = 0; i < s.size(); ++i) {
    s[i] = toupper(s[i]);
}

then you should be fine.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Look in the directory of your C++ project. In that directory, or in some subdirectory ('Debug' or 'Release'?) should be your exe, once it's been built.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I've never seen a double posted thread.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

ANSI C allows 15 levels of nesting but some compilers evem allow more

Bah, now I'm angry. Fortunately, Hell has probably frozen over by now :-) (http://en.wikipedia.org/wiki/Hell,_Michigan)

Rashakil Fol 978 Super Senior Demiposter Team Colleague

If there is a built-in limit in the C++ language, then hell is frozen over. There are practical issues -- you don't want to run out of memory or with two billion nested loops, each having its own counter variable, but the restriction there isn't from nested for loops, it's from other externalities.

for (;;) {
for (;;) {
for(;;) {
... 2 billion times ...
for (;;) {
    goto end;
}
... 2 billion times ...
}
}
end:

This should be valid C++ code, and if your compiler can handle it (good luck!), and handle it smartly (haha), it should have no memory usage at all.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

They're right; it's a lot of theory. You should still study computer science for what you want. (I don't know whether this recommendation comes from my honest assessment of your situation or my desire to sic theoretical classes onto unsuspecting victims.)

-- Web Programming (Web Development using PHP, ASP, .NET, etc)

These won't be taught except maybe in some specialty course. You should be able to learn these on your own, anyway. (PHP is a crappification of C++, and ASP and .NET use some programming languages that are similar to ones you'll probably be using in getting a CompSci degree.)

-- Software Programming (Video Games using Direct3D, OpenGL, C++, etc. Also regular application programming

Once I hear 'video games', even though I doubt that's what you'll be doing when you graduate, I have to say go into Computer Science.

I think the most important thing, though, is not your degree, but how hard you work and how smart you make yourself.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

OOOOOOh....you'll be listening very soon from someone

Good call!

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I'm guessing he used some plugin or something with Microsoft Word.

Another way is to use LaTeX, and he might have used that, but the font and size of the integral signs doesn't look right.

One easy way, without installing software, is to use Wikipedia. Click an edit button on this page and you can use Wikipedia's math notation feature -- you can preview your changes and save whatever images you see of your notation.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I need to evaluate the definite integral from 1 to 2 of 5/(8)(x to the 6th power) dx. From my notes from years ago, I know the answer is 31/256, but I keep coming up with 29/256.

Rewrite this as (5/8)*x^(-6) (where ^ is an operator indicating exponentiation). Then an antiderivative is (5/8)*(x^(-5)/(-5)) = -x^(-5) / 8. (I've omitted the 'plus C' that is usually written.) Then -(2)^(-5) / 8 - -(1)^(-5) / 8 = -1 / (32 * 8) + 1 / 8 = -1/256 + 32/256 = 31/256.

I'm also trying another problem...the definite integral from 4 to 9 of the function (t-3)/(the square root of t) dt. I don't show that as one of the problems I worked previously, so again I don't have my notes. I keep coming up with 55/18, when the answer should be 20/3. I believe my errors occur when raising the denominator portion of the function.

I'd begin by rewriting: (t - 3) / sqrt(t) = (t / sqrt(t)) - 3 / sqrt(t) = sqrt(t) - 3 / sqrt(t). Then I'd split this into two integrals.

The integral of t^(1/2) from 4 to 9 is 38/3, and the integral of 3 * t^(-1/2) is 6. Hence, the integral of t^(1/2) - 3 / t^(1/2) from 4 to 9 is 38/3 - 6, or 20/3.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Im trying to define a function seg, which is supposed to take a finite list xs as its argument and returns the list of all the segments xs. What is meant by a segment, is a list of adjacent elements i.e.
seg [1,2,3] = [[1,2,3], [1,2], [2,3], [1], [2], [3]]

I would have guessed that the correct output should include [] as a segment.

cons :: Int -> [Int] -> [Int]
cons x l = (x:l)
seg :: [Int] -> [[Int]]
seg [] = []
seg [x] = [[x]]
seg (x:xs) = (map (cons x) (seg xs)) ++ seg xs

This code looks more like the code that produces all the subsets of a list. The code that produces all the subsets of a list is

subsets :: [a] -> [[a]]
subsets [] = [[]]
subsets (x:xs) = map (x:) (subsets xs) ++ subsets xs

after all. Look closely at your last line. Does mapping the function (cons x) to the results of (seg xs) produce continuous segments? I'd think you'd only want to prepend x to the segments that begin at the beginning of the list xs. I recommend using a helper function for this.

As you have it, seg [1,2,3] results in (map (cons 1) (seg [2,3])) being called, and since [3] is a segment of [2,3], this results in [1,3] being given as a segment.

Can you please email optimak@gmail.com to let me know, or do …

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I read this complicated theory before. I downloaded Perl from their Web site and Java from Sun and Apache. I written and ran few examples also. Please explain.

Perl is the name of a programming language. Java is the name of a programming language.

"Java" is also the common name of an interpreter distributed by Sun that runs compiled programs written in the Java programming language.

Programs written in the Perl programming language are interpreted by "perl," which is a Perl interpreter. This is not the only Perl interpreter, though. There's a Perl 6 interpreter known as "Pugs."

[Edit: Ack, sorry for the double post.]

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I thought Perl is CGI? I can run a Perl script and rename it with .pl or .cgi extension; it doesn't matter! Do, I rename my C++ program as .cgi? How can it run online .. :!:

Please help me: I'm very much confused .. (I knew now .. I remained confused all the time, in the college also ..)

CGI stands for Common Gateway Interface. It's not a programming language; it's a way by which web servers (such as Apache) communicate with server-side programs. These programs can be written in any language, such as Perl, Python, C++, and Lisp, and they can be interpreted or compiled. The web server sets some environment variables and starts up the program, possibly sending some information through standard input, and the program writes the HTTP response, with HTML or maybe an image, to standard output.

For example, here's a tutorial called Getting Started with CGI Programming in C, though I wouldn't recommend using C or C++ as a first choice for CGI programming.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Back when I had no clue what "object oriented" meant, I looked at C# and was able to make reasonable applications with it. It's a comfortable language.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Pretend you're the computer, and keep track of the values of money and moneyspent given some arbitrary input values to the program. You'll see your problem.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Ah! I was wondering if I was reading that wrong :)

Rashakil Fol 978 Super Senior Demiposter Team Colleague

In my high school, a referral meant that the kid got in trouble. This does not necessarily mean he did anything wrong.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

byt the way, why douse RAND_MAX exist if it cant be set? is there another reason?

RAND_MAX doesn't 'exist', for some definitions of the word. It just happens to be a fact that rand() will return a value that is less than or equal to whatever value RAND_MAX denotes. It's not a variable in memory; it gets replaced with a regular old number by the compiler. For example, my compiler replaces it with the value 2147483647. The value you get depends on the random number generator your version of rand() uses.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Interestingly enough, your link brings this page back as a result! I like the other Daniweb match a bit more, though.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

That happens if they don't teach it in the first year, if you've switched your major. And when searching on Google, you get three companies calling themselves Big-O Tires, a site Big-O dot com, a Wikipedia article incohesively written by fifty people with their heads up some mathematical rectum, some small government page with a poor explanation, a fan page of a televesion show, and two books -- one about orgasms, the other about basketball.

Then on the second page, we've got a movie, a birding festival, a magazine, some boats, ....

Why are you posting hateful things?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

If you go that route, make it real-time with "AJAX." (Otherwise the project could take less than 10 lines of code.) Then write a tetris in Python, and run it over the Javascript console. :-)

Rashakil Fol 978 Super Senior Demiposter Team Colleague

True. For added fun, consider the Saturn processor in the HP48, with a 4 bit bus size, 4 bit word size, 3-5 word relative and absolute memory addresses (with nibble-addressable memory), 64-bit registers, 20-bit registers, a 16-bit register, a 12-bit register........

Now let's see you predict the values for various sizeofs :-)

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I would feel more comfortable trusting sizeof(void*) than sizeof(int).

I'm tempted to trust sizeof(size_t) too, but you never know...

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Do you know what it means for two functions to grow at the same speed and for one function to grow faster than another?

The notation O(f) denotes the set of all functions that grow at the same speed as or slower than f. E.g. if the amount of time your program takes to run is 20n*n + 2n + 5, it turns out that your program runs in O(n*n) time, because the function (20n*n + 2n + 5) grows at the same rate as the function (n*n). It is also true that your program runs in O(n*n*n) time, because (20n*n + 2n + 5) grows slower than the cube of n. But saying O(n*n) is more informative. Generally, when people want to know the algorithm time complexity of a program or subroutine, they want to know how long it runs, with respect to some input value. You could give them an exact equation down to the microsecond, but that's not very useful, considering that it'd only be determined for one computer. So it's better to say "the running time grows quadratically with respect to the input size" than "the running time is about 20n^2 + 5n + 2 microseconds." And to say the former, you'd usually use "the running time is O(n^2)."

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Sophisticated approach: add hyphenation. <-- may take years to get right!

Heh. If I ever see hyphenation like quantifier-
s again, well, I guess nothing bad will happen, but we'll see :)

Rashakil Fol 978 Super Senior Demiposter Team Colleague

There are various text justification algorithms, some better than others. For example, one simply asks, "How many words can I fit on the first line?" and then spreads those words evenly on the first line. Then it looks at the rest of the words.

A smart text justification algorithm does more to prevent abnormally poorly spaced lines, using a dynamic programming algorithm. I have never looked at the algorithm; I just know that's what it uses.

TeX uses the 'smart' kind of algorithm, so take a look at http://tex.loria.fr/tex-source/tex-source.html

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Suppose you have the scrambled string, "urcoppnei".

You want to be able to quickly go from scrambled string to unscrambled. How?

Sort the letters of the string in increasing order. That gives us "ceinoppru".

Now take every word in the dictionary, and sort their letters in increasing order. Put this in a hash, where the sorted form is the key and a list of words is the value. (Use a list, not a single word, because anagrams have the same sorted form. For example, the key "dgino" would have as its value a list containing both "doing" and "dingo".)

Once you do that, look up "ceinoppru" in the hash. You'll probably find that the key "ceinoppru" maps to a list containing one element, "porcupine".

Of course, it would be better to have your dictionary file in the format

...
aaardkrv aardvark
...
dgino doing dingo
...

It wouldn't hurt to sort it by the letter-sorted key.

So, you would unscramble by sorting the letters of the word in ascending order, by looking for this result in the text file (or hash, or map, or whatever).

I don't really understand your file format -- it looks like it's listing words with subwords. Why?

And here's a second edit. What you are asking and your sample input and output seem to be on completely different topics! You leave me baffled...

Rashakil Fol 978 Super Senior Demiposter Team Colleague

myIter - myVec.begin() would be a start.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

When Python is installed correctly, Python files should execute just like any other file -- it's just a matter of registering the file extension. It's the same situation as Java.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Think about how the bit operations work.

Thanks.
I know how bit operations work, but I didn't want to let common sense get in the way of correctly divining the way of the C(++) standards.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Are you still a student? If not, how long have you been programming? Swapping integers (and other data types) is a common thing in sorting algorithms.

I am a student, and I've written most common sorting algorithms. Them being generic, I never end up swapping "integers", just some type named "T", via a third variable.

Swapping integers that are known to be integers (or unsigned integers, if signed integers actually do have problems) is just something I have not run into.

probably implemented like this

void swap(std::string& s1, std::string& s2)
{
   std::string temp = s1;
   s1 = s2;
   s2 = temp;
}

I know of no other way to do it with std::strings.

When implemented sanely, the std::string and maybe other datatypes' swap member function if they exist (used via x.swap(y)) simply swaps private pointers and length values if they exist. So swapping two million-character strings takes the same amount of time as swapping two zero-character strings.

As for xor producing overflow: I do not see how xor produces overflow problems. Which is what my question was about (it wasn't about sorting): Does xor have problems when a negative number is involved that causes x ^= y; y ^= x; x ^= y; to not swap the values of x and y when x and y are not the same variable? That is, is there a hypothetical case of internal binary number representation and xor operation where a C or C++-compliant compiler would produce machine code that does …

Rashakil Fol 978 Super Senior Demiposter Team Colleague

How is x ^= y; y ^= x; x ^= y; unsafe when x and y are equally sized integers? Is there a problem with using xor for signed integers? Well, I wouldn't really use it, because I've never swapped integers in my life.

As for swapping strings, there is a member function named 'swap' which tends to achieve the task in constant time.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

And as for #4:

y = x + (x << 1) + (x << 2);

also works.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

the answer to number 3 (assuming the number is an integer) is to use the modulous operator, %.

if(!(numbername%2))
   cout<<numbername<<" is a power of 2."<<endl;

Um, no. This only tells if the number is a multiple of 2. For power of 2, that'd be (!(x & (x - 1))).

As for #1:

First of all, "if" is not a loop. I don't know what got this idea into your head. But let's not use 'if' anyway.

#include <iostream>

void cout_nums_and_back(int low, int high) {
    (high < low)  ||  (
        std::cout << low << std::endl,
        cout_nums_and_back(low + 1, high),
        std::cout << low << std::endl
    );
    return;
}

int main() {
	cout_nums_and_back(1, 100);
	return 0;
}
Rashakil Fol 978 Super Senior Demiposter Team Colleague

Can anyone pl. mail turbo c++ setup as attachment to

I would recommend free software that exists and you can use for free, but you don't deserve it.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Good. The makers of software should get paid for their work if that's what they want. If I met you in person, I'd steal your clothes.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Bah, just use clean, erm, XSLT.

<xsl:template name="blah">
    <xsl:param name="x" select="2"/>
    <xsl:param name="y" select="5"/>
    <xsl:param name="swapped" select="0"/>

    ...

    <xsl:choose>
        <xsl:when test="$swapped = 0">
            <!-- First we run this code. -->

            <!-- And say we want to swap x and y! -->

            <!-- Oh no, we can't change their values! Curse!  Recurse!!-->
            <xsl:call-template name="blah">
                <xsl:with-param name="x" select="$y"/>
                <xsl:with-param name="y" select="$x"/>
                <xsl:with-param name="swapped" select="1"/>
            </xsl:call-template>
        </xsl:when>

        <!-- In the spirit of XML, they picked the most verbose name
        out of the choices 'else', 'default', and 'otherwise.' -->
        <xsl:otherwise>
            <!-- Now x and y are swapped! -->

            ...
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
Rashakil Fol 978 Super Senior Demiposter Team Colleague

Definitely way less than 1/2 gram. A cubic centimeter of water is one gram.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I really don't. I use large integers frequently enough.