Rashakil Fol 978 Super Senior Demiposter Team Colleague

Oh, I'm sorry, I didn't see the for loop when considering the behavior of that break statement.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Your problem is that break; has a special meaning inside a switch. The general way a switch is written is with

switch (n) {
 case 1:
    // do stuff
    break;
 case 2:
    // do other stuff
    break;
 // etc
}

You need to put a break after every case, or else execution will just roll right into the next case. C++ is a weird language.

Also, your break statement that you currently have therefore only breaks from the switch, not from the while loop.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Please edit your post to put your code in [code][/code] tags.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Definitely iamthwee.

iamthwee commented: Terrible suggestion. -4
Rashakil Fol 978 Super Senior Demiposter Team Colleague

No, it says you have non-exhaustive patterns!

In particular, you defined the function binadd for non-empty lists with:

binadd (x:xs) (y:ys) n = ...

But you didn't define the function for empty lists! What is the value of binadd ([True]) [] True ? Your function's behavior is not defined, because the empty list [] doesn't match the pattern (y:ys) . You need new cases below to handle empty lists, probably something like

binadd xs [] n = ...
binadd [] ys n = ...

But whatever you do, make sure your function can handle all the cases. I'm pretty sure there is some warning you can turn on that will tell you about functions that don't handle all the conceivable cases.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

It makes a copy of the string. For it not to do so would be counter-intuitive -- if it wanted a pointer to a string, it would ask for one.

In particular, you'll note that the constructor takes a const string. Which means that there's no way in heck that the stringstream could use the string it receives for its internal buffer.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

The idea is to learn about Lists, not to learn the different ways to iterate. I doubt that the above example would have helped in understanding how to add and get elements from lists.

Yeah, I know, and you're right. Please regard my comment as a nonsequitor.

Rashakil Fol 978 Super Senior Demiposter Team Colleague
for (int i=0;i<list.size();i++) {
  String s = list.get(i); //you do not need to cast it to String like the previous example because of the way you defined the list above
  System.out.println(s);
}

Leave it to a Javacoder to write code in the most obtuse manner possible. (Yes, I'm being unfair :))

for (String s : list)
    System.out.println(s);

my question is, is it true that there is no need to write a LinkedList class in java?

There's no need to write one in C++, either. #include <list>

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Pretty much, yes. Well, the exception could also be thrown in a method called by the called method, or in a method called by the method called by the called method, or....

Or the exception could be thrown directly from the try block itself.

Also, finally blocks exist too.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

What happens if it WAS static method? And what is the thing that is put on the heap that identifies which method the delegate calls on the object?

I don't know or care, but for all intents and purposes it could be a string containing the name of the method (and implicitly through the delegate type, the types of its arguments). I mean, that's all the information it needs to work. But probably in reality it's a function pointer.

We're ignoring anonymous delegates, though, for which there is no method name and more than just an object -- there are variables captured in the delegate's scope.

But how they're actually implemented is an implementation detail. An anonymous delegate type is basically equivalent to an abstract class with one abstract method and nothing else.

I've got Visual C# 2008 Express version 9.0.30729.1 SP. I don't know how to get it to tell me what version of the compiler it has. Would you happen to know what version it has or how to make it tell me what version it has?

Yours supports C# 3.0 and .NET 3.5, the latest versions.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Well, for example, install Perl, xargs, and some version of find on your computer, or just install cygwin, and run the example I gave you.

But that's DUMB. Most IDEs and many text editors have this functionality built in.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

What the fuck? You asked this in the C++ forum and didn't even need to write it in C++, and got answers. Why are you asking it in the Java forum?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Your view of delegates and the mechanics of using them is very accurate.

Steps to create and prepare to use a delegate reference:

1 Define a delegate type: specify the signature (including return type) of methods that delegates of this type can point to. This is called "declaring" the delegate; which I think is kind of confusing, since "declaring an object" means to create a reference variable to hold the reference (address) of an object (see step #2 above for objects), but in my opinion "declaring" the delegate is really much more analogous to defining a class (see step #1 above for objects).

You are absolutely right. "Declaring a delegate" is exactly analogous to defining a class. If anything, I would object to the terminology of "declaring a delegate," and instead, when I need to speak uberprecisely, use the term "defining a delegate type." Whatever you call it, it's exactly analogous to defining a class.

3 Instantiate a delegate: allocate space for a delegate in the heap. [BTW, what actually goes in the heap here - the reference (address) of a method, or a copy of the method?]

What does the term "a copy of the method" mean? How does one "copy" a method? In any case, no copy of any method is made.

What goes on the heap are two things: a reference to the object you took the method from (unless it was a static method), and some way of identifying which method the delegate …

Rashakil Fol 978 Super Senior Demiposter Team Colleague

d2b2 evaluates to something of type [Int] , right? Which means the expression (d2b2(n / 2):1) is trying to pass an [Int] as the left-hand argument of the (:) function. Since the (:) function is of type a -> [a] -> [a] , that means it expects on the right-hand side a list of whatever was on the left hand side. That means it expects a list of [Int] , i.e. something whose type is [[Int]] . Instead of an expression of type [[Int]] , you're supplying 1, or 0, something of type Int . That's the reason your error message is the way it is.

The function (:) is for appending elements to the left end of a list. If you want to append an element to the right end, wrap the element in a list an use a (++) operator. For example: [1,2,3] ++ [x] => [1,2,3,x] .

You have a number of other problems with your code. One of them has to do with this question: What do you expect 'return' to do?

chunalt787 commented: Great responses very informative and patient, thanks so much +1
Rashakil Fol 978 Super Senior Demiposter Team Colleague

So add some debugging statements so that you can see what's happening.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I don't either, but why can't you just select the elements equal to 7, select the elements equal to 9, and union these two sets?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I think we can safely conclude that MosaicFuneral has no idea what he's talking about.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I am talking about using commands like perl, xargs, and find, from the command line. You might need to install software if you want to use these on Windows.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

don't type else part of if statements!just write two if statements!this would save you some time when you want to later view the program!

What the fuck are you talking about?

Comatose commented: Fully Agree +10
Rashakil Fol 978 Super Senior Demiposter Team Colleague

You'll probably get a dumb generic answer, asking a question like that in this forum. Here is mine:

C# is a fine general-purpose programming language. You might not have the same access to numerical libraries as you do with, say, Matlab or C++. If you want to write code for embedded systems, well, it really depends on what kind of embedded systems. C# is really best for Windows programming.

As far as visualization goes, I'm sure Matlab and R have much, much, much better visualization libraries for numerical data. (You haven't mentioned R -- have you looked at R? Just wondering.)

For this kind of question, ask somebody who does signal processing or machine learning. That way, you'll get an informed answer.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Where you wrote ostream &Month::operator<<(ostream &strm, const Month &obj) , you should be writing ostream &operator<<(ostream &strm, const Month &obj) . The function you're defining is not declared as a member function of the Month class.

Edit: (The same goes for your operator>>.)

Rashakil Fol 978 Super Senior Demiposter Team Colleague

The reason is that blah = 1 sets the lvalue blah to 1. You want blah == 1 , which evaluates to true if blah is 1. It's generally a good idea in C++ to get in the habit of putting constants like 1 on the left-hand side of equality comparisons. That reduces the probability of making this kind of error.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Aren't those manuals normally reserved for teachers and educational instutions???

No.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I want to use these two terms appropriately.

Why?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

What is the purpose of this post?

For instance, although c# is a powerful language for developing many types of applications, it is impossible to create an operating system using c# because the language is not close the hardware. For such needs C is the language of choice as it is really close to hardware.

Reality disagrees with you.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

As far as the C# language's prettiness goes, dudeserius's post gives a poor example. Lots of well-written C# is much prettier and much more readable than that. He's working with a particularly poor API in that example.

It is always good not to be tied to just the Microsoft platform. Rather than C# I would rather pick up Java. Once you are familiar with Java, C# will be easy to add.

Your post is extremely stupid for several reasons. First, nobody got hurt because they are good at a language which works on the Microsoft platform. Microsoft will die much slower than it takes to learn some other language, and that doesn't mean the .NET platform would die too.

Second, Java doesn't even have closures, and therefore Java programmers generally hate their lives more than equivalent C# programmers.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

With Javascript and a few simple images for things like integral signs, you can arrange pieces into arbitrary shapes using div positioning. A lot of mathematical symbols are in the Unicode character set, maybe even integral signs.

Some browsers support MathML, so you might want to look into that.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I would recommend the book "Accelerated C++", by Koenig & Moo.

You'll note that the Daniweb rules state some prohibitions, including "do not post anything warez related or related to other illegal acts."

This means that, for example, if there existed tools out in the world that made it trivial for you to download any popular textbook you wanted, I wouldn't be allowed to tell you what those tools were. If they existed. And I'm not saying that they do.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I was planning on taking a program regarding haskell, but I don't know if its the good thing.. I mean... some said its like out of style ...

That's mistaken. Haskell is more "in style" than it has ever been.

Edit: I'm not saying it's popular, but it's more popular than it ever has been.

I am still searching and trying to know if I need it ... or if I need to learn more about functional programing, since I already know OOP ...

I thought I "knew" OOP, but having learned Haskell caused a change in my opinion.

It is definitely worth learning. After learning Haskell well, you will have a better sense of how to take advantage of other language's type systems. Also, you'll have a better sense of how other language's type systems limit you. Also, you'll get a better sense of program design and well-engineered, user-friendly data structure design.

You should not go with F# in place of Haskell. F# is a compromise between the goals of making a good functional programming language and running on the .NET platform. If you came here saying "I'm looking for a good language to use for writing .NET programs," I would recommend F#. It's a good language. But since you came here asking about learning functional programming, you should go with Haskell. Type classes (a Haskell feature) are worth learning.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

A char* points to an array of characters (or maybe a single character, of course, but typically an array). You know how arrays work, I presume.

The function 'read' will fill the array with some number of characters (that have been read off the input stream).

Suppose your array contains the following before the read operation:

0   1   2   3   4   5   6   7   8   9   10  11  12  13  14  15
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
'#' '$' '%' 'T' '2' '5' '9' '&' 'H' 't' '_' '^'  0  'k' 'l' 'a'

These are just arbitrary characters, but in particular you'll see a nul character at position 12. It's not the character '0', which has value 48 -- it's the character with value 0. C-style strings are character arrays with a 0 at the end. For example, if you wanted to find the length of a C-style string, you might use a function written as follows:

int strlen(char* s) {
    int i = 0;
    while (s[i] != 0)
        i++;
    return i;
}

If you passed the address of the array I drew to this function, you would get 12.

Now let's look at how 'read' works. Suppose 'read' detects 7 characters, the word "Helllo!", at the input stream. So it returns 7 and writes those characters to the array whose address was passed as a parameter.

Our array (if we passed it to 'read') now looks like this:

0   1   2   3   4   5   6   7 …
Rashakil Fol 978 Super Senior Demiposter Team Colleague

Nobody could help you unless you listed specific books for which you wanted solutions manuals. And since nobody here would know how to find them off the top of their heads, you might as well do the googling yourself.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Wikipedia seems to have the bit-level details.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

What are you expecting this to do, and why? Please explain line by line. There is something wrong with the way you think Java works.

public class PairSimulator
{
    public static void main(String[] args)
    {

        Scanner in = new Scanner(System.in);
        Pair pair1 = new Pair() ;
        String number1 = "Enter first number:";
        double P1 = in.nextDouble();

        String number2 = "Enter second number:";
        double P2 = in.nextDouble();

       System.out.println("The sum is: " + pair1.getSum());
       System.out.println( "The difference is: " + pair1.getDifference());
       System.out.println( "The product is: " + pair1.getProduct());
       System.out.println( "The average is: " + pair1.getAverage());
       System.out.println( "The distance is: " + pair1.getDistance());
       System.out.println( "The maximum is: " + pair1.getMaximum());
       System.out.println( "The minimum is: " + pair1.getMinimum());
    }
}
Rashakil Fol 978 Super Senior Demiposter Team Colleague

The most obvious direct answer is to make a quadtree that keeps track of which quadrants contain 3s and which don't. Then zoom in on a given point from above, continuing to enter regions that contain 3s and are still candidates for the closest 3 to your given point.

You could also use some "fake" distance metric. For example, the distance from a heat source could be one plus the least distance from a heat source of one of your four or eight neighbors. (With one, heat propagates in squares, with the other, in diamonds, so I would just go with the former which is cheaper to compute.) A better "fake" distance metric would be to let each square be either 1 plus or sqrt(2) plus a neighbor's square's distance -- using sqrt(2) if the neighbor is diagonal. Pick the neighbor that minimizes your computed distance. With the latter method, areas of equal distance will form octagons around heat sources.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

If you look at

if ((length = read(STDIN_FILENO, buffer, sizeof(buffer))) < 0) {
							perror("read"); 
							continue;
						}					

					cmd = getCommand(buffer).c_str();
					cout<<"cmd: "<<cmd<<endl;
					strcpy( buffer, cmd.c_str());
					cout<<"buffer: "<<buffer<<endl;
					buffer[length]='\0';

You're reading characters into a buffer and then converting that to a string, and then _later_ putting a null character to mark the end of the inputted characters. Think about what that means.

You might have similar problems in other locations in your code.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Could you post the contents of client.h? It might be needed just to sanity-check things.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Well post what you tried, because you aren't being very clear about what you tried

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Why do you have a class named Swap?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

You may want to implement your own Double Class (which will hold data as a string internally)

Or how about a better representation.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Looks like somebody clicked on the wrong forum. And it would be a nonsensical, wrong answer even if it was in the right forum.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

That's not enough information to solve your problem.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Write a compiler.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Well from what I see, it walks through the permutations but eventually overwrites the array with 3 3 3 3. There is no way anything will be able to see the array in a different state.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

So how are aFirst and aSecond in scope then? PairSimulator is not defined as a subclass of Pair, given the code you're showing.

Regardless, the reason your program ignores the user-inputted numbers is because your code doesn't use the numbers. Just look at your code.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

But what if that child has children, and it's children have children? See my problem?

Read my function (now functions) again, you'll see that it deletes the children.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

In PHP, I would have just set up parentID as a foreign key referencing the CatID on delete cascade; however I've found that in C#, I'm not allowed to set up a foreign key constraint that self-references a column in the same table (lame!).

This doesn't make any sense. Constraints aren't specified in C#. What database are you using?

Edit: oh, I see. More reply pending.

Edit 2: One option: write a function that does what you say, deleting the children first.

void DeleteCategoryTree(int catID) {
    int[] children = GetChildIDs(catID);
    foreach(int child in children)
        DeleteCategoryTree(child);
    DeleteCategoryRow(catID);
}

Edit 3: And if you think there can be children so deep as to cause a stack overflow, use a Stack.

void DeleteCategoryTree(int catID) {
    var stack = new Stack<int>();
    var deletionStack = new Stack<int>();
    stack.Push(catID);
    while (stack.Count != 0) {
        int id = stack.Pop();
        deletionStack.Push(id);
        foreach (int child in GetChildIDs(id));
            stack.Push(child);
    }
    while (deletionStack.Count != 0) {
        DeleteCategoryRow(deletionStack.Pop());
    }
}
Rashakil Fol 978 Super Senior Demiposter Team Colleague

The site would be ours another words we would host the site ourselves. The key thing that I am not sure about is how to allow users to view their mathematical notation within the confines of the browser ? In your example you have used a bitmap for the mathematical notation. How can this be done dynamically ?

You can write code that generates a bitmap. Using programming. And maybe an API that lets you write text and sprites onto an image. But Daniweb just uses LaTeX.

You don't need to make a bitmap though -- if you have a javascript UI, use javascript to reposition elements around in the shape of a formula.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

The code you're showing here won't even compile -- in the function main, aFirst and aSecond are not in scope.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

You're not describing what you expect the code to do. I would expect the code to fill the array with threes.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I'm not sure which is worse. Having students use throws clauses or having so-called professionals write

try
{
    ...
}
catch (Exception e)
{
    e.printStackTrace();  // or whatever it is
}

For that reason, I think encouraging people to mindlessly catch exceptions is worse than having them mindlessly throw exceptions.