mahlerfive 23 Junior Poster in Training

Just tested it with the changes mentioned, and it works for me too.

mahlerfive 23 Junior Poster in Training

Here are another 2 options:

1) Make a copy of the array, and do only a partial selection sort. Use the variation of selection sort that puts the largest element at the end. Since you only want the top n elements, only run the outer loop of selection sort n times, then your top n elements should all be at the end of your copied array.

2) Instead of making a copy of the array, search for the largest number in the array, then store the index of that number in a list or vector of some sort. Search again for the largest number in the array, but ignoring any indexes that are in your list of indexes, repeat n times.

mahlerfive 23 Junior Poster in Training

If your SoapPair class has any member variables, all of them have to be of a type that is serializable.

mahlerfive 23 Junior Poster in Training

Your instructor's feedback is extremely straight forward...
Also he did miss some things:
- The US dollar to English pound conversion in your code is incorrect, take a closer look at the conversion list to see why..
- Your output module only outputs the currency type... are you sure that's all you're supposed to output?
- You do not end the output module in pseudocode

mahlerfive 23 Junior Poster in Training

1. recv() will NOT necessarily receive all the bytes sent in one call. You will have to loop it. Since recv() returns the number of bytes received, what you can do is have the sender always put an integer at the start of each message specifying the length of the message so that the receiver knows when to stop looping for that message. In addition, the same problem exists for the sender - send() is not guaranteed to send all the bytes requested in one call to send(), so you must loop that as well. It is probably best to make functions like recv_all() and send_all() that do this for you automatically so that you don't have to keep writing loops and checking sizes every time you want to send or receive a message.

2. If the client has called recv() and the server closes the socket, the client's recv() will return -1 signifying this. If the server closes the socket and the client tries to send() it will also receive an error. So either way the server can just close the connection and you can program the client to deal with this. You should program the client to handle this situation anyway in the case that the server crashes or something, so that the client doesn't crash as a result.

mahlerfive 23 Junior Poster in Training

The panel class needs a reference to your frame class. Assuming your frame class creates the panels, the frame should send a reference to itself (this) as an argument to the panel constructor. You will need to change the panel constructor to accept this argument and store it. Now when the panel wants to call a method in the frame class you can use that reference.

EDIT: one more thing, you should generally not make the variable in panel public, that's what the public get method is for. Make the variable private and the get method public.

mahlerfive 23 Junior Poster in Training

I would argue that the majority of code people write is iterative rather than recursive. Because recursion has more overhead in terms of memory and speed, iterative approaches are generally preferred unless the recursive version is much simpler to understand and implement. I'd say the biggest downside to recursion is that function calls require stack space which is usually very limited, and if you try to recurse too deeply you will stack overflow and crash your program (try recursing a million times and you'll see).

I find recursion simpler to understand when it's applied to some sorting algorithms (mergesort, quicksort), and tree structures (you will see these in a data structures course). Of course, when you first start learning recursion, almost every problem will seem easier to understand iteratively. Once you gain more experience with recursion it will become easier to understand.

mahlerfive 23 Junior Poster in Training

Instead of: int board[4][4];
Replace with: int** board;
Now we can dynamically allocate space for the 2D board array.

In set_board(), we need to do the dynamic allocation like so:

// First allocate for the first dimension
board = new int*[height];

// Now allocate for the second dimension
for( int i = 0; i < height; i++ ) {
   board[i] = new int[width];
}
mahlerfive 23 Junior Poster in Training

The lowercase part you have actually won't work for all cases...

What I would do is just have a boolean variable for each condition, and each check will set the appropriate variable to true or false. Then at the end just 'and' them all together to get whether it is valid.

So for lowercase, have the isLowercase variable set to false, then loop through and once you find a lowercase character, set it to true. Same goes for uppercase and digit.

mahlerfive 23 Junior Poster in Training

Also try to keep your indentation a standard width - usually 3 or 4 spaces is good.

As for the non-standard includes as mentioned above, I'm guessing you are using something old like borland or turbo C... I would recommend you start using either VC++ or Code::Blocks.

mahlerfive 23 Junior Poster in Training

Not really sure what you are asking... but if you're asking what sum = sum + 5; does, then the answer is that it increases the value stored in sum by 5.

mahlerfive 23 Junior Poster in Training

The other option is to just sort both arrays which will make traversing the arrays and finding non-duplicates much easier.

mahlerfive 23 Junior Poster in Training

Well if the output is always zero, then either 5/9 is 0 or F-32 is 0. Try and write a small program that just prints the result of 5/9 and one that prints the results of F-32 after the user enters F. That might help you narrow down the problem.

mahlerfive 23 Junior Poster in Training

And your question is?

mahlerfive 23 Junior Poster in Training

Not sure where to start on this one... You haven't really followed the instructions. The instructions state that EACH student data record should be dynamically allocated. Instead your student list creates a static sized array of 100 records. What you need to do is make a StudentRecord class which stores info about one student. Your StudentList class should have add/remove/search methods. The add method should create a new instance of a StudentRecord object (dynamic allocation) and add it to the list. The code to ask for student details should NOT be in the StudentList class, but in the main and then passed to the add method.

Also, a menu-driven system should have a loop, otherwise you can only do one operation.

mahlerfive 23 Junior Poster in Training

Have you learned about classes in your course yet? If so then you should be using them. If not, you should at least break your functions up into smaller, more manageable functions. Also you should learn how and when to use header files and multiple cpp files rather than having everything in one big file.

mahlerfive 23 Junior Poster in Training

Hmm not exactly sure what that would be happening, but there are still a couple things you need to change. At the top you should declare gRow and gCol as const int - I'm not sure how this even compiles with no type given. Also you should make a loop for getting input rather than an if statement in case the player tries to place a piece in an invalid spot more than once. Another thing to consider is making sure the player enters a valid row and column (between 1 and 3).

mahlerfive 23 Junior Poster in Training

You are getting mixed up about what should be in your main() and what should be in your class methods.

As the problem specifies, input for a TMoney should be done in the inputdata() method, and output should be done in the outputdata() method. The main should only declare an array of 3 TMoney, loop to call inputdata() three times, then call outputdata() on the 2nd TMoney.

Your inputdata method needs braces to surround the code that belongs in the method like this:

void getinputdata() {
   
    cout << "Enter the number of tdollars you own:";
    cin >> tdollars;
    cout << "Enter the number of twons you own:";
    cin >> twons;
    cout << "Enter the number of tpennies you own:";
    cin >> tpennies;
}

The outputdata() method should be written similarily.

Also, when calling outputdata you are missing the parentheses.

mahlerfive 23 Junior Poster in Training

When adding the node at the end (as you are now doing), you should have the new node point to NULL instead of head. The reason you get it infinitely repeating is because when your end node points to the head (the start) it is basically a giant loop.

mahlerfive 23 Junior Poster in Training

What exactly are the requirements? Are you supposed to be adding new nodes to the beginning of the list or the end of the list? Are you sure you are not supposed to get the result you got?

In the case that you are supposed to append to the END of the list instead of the beginning as you have done, then you will need to loop through the entire list and put the new node at the end when adding a node. This is clearly inefficient, but if the requirements state that you should be adding to the end of the list then that's what you have to do.

If the requirements say that you should be getting '2' as the output for your example, but specifies that you should be adding new nodes to the start of the list, then that's messed up.... The only real way to fix that case is if you keep track of the length of the list as you insert/remove nodes and then subtract the actual found location from the length of the list (and then -1 since it is 0 indexed). So in your example you would do 3 - 0 - 1 = 2.

mahlerfive 23 Junior Poster in Training

Since you are adding nodes to the head (start) of the list, the last node you add will be in position 0. The output is correct for the example you gave. I'm assuming the list isn't supposed to be sorted - if so then you need to change your add function.

mahlerfive 23 Junior Poster in Training

Did I say I don't know how to build a GUI from scratch? What is wrong with using a tool that makes the GUI design process quicker?

mahlerfive 23 Junior Poster in Training

I usually use Eclipse, but switch over to Netbeans when I do any sort of GUI.

mahlerfive 23 Junior Poster in Training

The Java API is your friend: http://java.sun.com/javase/6/docs/api/
Look up FileWriter, look at the constructor and the write methods.

mahlerfive 23 Junior Poster in Training

To add two times as you have listed, first add the seconds together. If the seconds > 59 you will have to use modulus (%) to find the remainder of the seconds. You can then use this information to figure out what the actual seconds are and that a minute carries over. Now repeat with minutes and days.

mahlerfive 23 Junior Poster in Training

You will need nested loops. The inner loop will print one line of numbers, while the outer loop controls how the pattern changes for the inner loop.

If you're still stuck, try solving the problem in steps. First create a loop that will print just one line of the pattern. Then make it repeat that same line many times. Then finally make the pattern change from line to line.

Also - should the first line not be 0 1 2 3 4 5?

mahlerfive 23 Junior Poster in Training

Just 71C15 alone is over 914 trillion combinations. A normal computer can do about 1 billion/sec. This means it will take about 10 days to compute just 71C15.

You might be able to do 71C7 or 71C8 in a reasonable amount of time.

mahlerfive 23 Junior Poster in Training

Generally when you are doing recursion on any kind of collection of items (lists, arrays, even strings) you want to solve the problem for the first element of the collection, then recurse on the remaining part of the collection.

For this example you can look at the first element of the list, check if that is the object you are looking for. If it is, then you are done. If it's not, you recurse on the rest of the list (without that first element).

Now, because your function is only taking the list and search object as a parameter, you have no way of sending a portion of a list to recurse on. What you will have to do is create a second recursive function (often called the auxiliary recursive function) that takes an additional parameter of the location in the list to start searching from. When someone calls your original function, you just call the auxiliary function with the location as 0.

Try coding that up and if you have problems, post both functions.

mahlerfive 23 Junior Poster in Training

I think you're going to need to give more information about what you need to do.

mahlerfive 23 Junior Poster in Training

You are right that the array name is the address of the first element of that array. This works exactly the same for arrays of char as well.

In C, there is no "string" type, so we are forced to use arrays of char. There is one special difference between a string (array of char) and other arrays, and that is that the last element of a string MUST be the null terminating character '\0'. This signifies the end of the string.

The puts() function will take a char*, assume it is a string ( an array of char), and output all the chars in the array up to the null terminating character.

By using printf in the way you are using it, you are telling it to output one character (%c) and giving it the first character of the string (since you dereference the array, giving you the first element). If you want to print the whole string, use %s and don't dereference the array. You could also print any single character within a string by just giving the index of the character. For example:

printf( "%c\n", message2[3] ); // this will print 't'
mahlerfive 23 Junior Poster in Training

Also try to reduce the amount of code you post. Just post the relevant parts. Add the exact error messages or example output to show us the problem.

mahlerfive 23 Junior Poster in Training

What protocol do you want to simulate? At what layer? You should be able to code a simulation up depending on which protocol you want to simulate.

You might also want to do a search into network simulation tools. I haven't used any, but I've heard of omnet and ns-2 being fairly common.

mahlerfive 23 Junior Poster in Training

You're off to a good start, here are some little tips/observations that might help you:

1/ Your header file should contain the structure definition as well as the function prototypes for functions related to that structure. So basically you should move the function prototypes into your header. Remove the last line of the header, you do not need/want it there.

2/ You will need some variable that keeps track of how many people are currently in the address book. You need this so that you know where in the array to add a person.

3/ In you addPerson(), you do not need to loop, and you should not redeclare the array. Instead you should copy the contents of the given person to the index of the array that you are currently on (as mentioned in #2).

4/ getPerson() should not loop either. You should have a variable somewhere that keeps track of what index you have looked at last so that the next time you call this function, you can get the next person after that (and increase the index).

mahlerfive 23 Junior Poster in Training

It depends on the platform. Since a pointer is an address, it must be big enough to store the largest address. I'm fairly sure that in windows addresses are 32bits (4 bytes). In linux/unix it may be different.

mahlerfive 23 Junior Poster in Training

Sorting by hand generally means the teacher wants you to show the array after each step of the sort from start to finish.

mahlerfive 23 Junior Poster in Training

You shouldn't ever be returning the operators though, only the result of operations or the number value in the node.

In the first branch, after you apply the operator to the two children, you should get back a double then return that.

In the second branch you should be returning the value (which is a double).

efus commented: thank you +1
mahlerfive 23 Junior Poster in Training

Since you want to return a string, just save the string returned from each recursive call, plus the string of the data in the node you are looking at and add them all together:

public void inorder() {
    if(leftChild != null )
        String s1 = leftChild.inorder();

    String s2 = " " + data;
        
    if(rightChild != null )
        String s3 = rightChild.inorder();

    return s1 + s2 + s3;
}
mahlerfive 23 Junior Poster in Training

You have allocated space for all of the studentInfo pointers here (except the last one, you should not be subtracting 1):

struct studentInfo *students[numOfStudents-1];

But, you have not allocated space for the actual studentInfo structures that each pointer will point to. To do that you will have to make a loop that allocates a studentInfo for each pointer using malloc().

Something like:

students[i] = (studentInfo*) malloc( sizeof(studentInfo) );
mahlerfive 23 Junior Poster in Training

The above poster is not exactly correct.

When you call scanf(), if the function fails (which will happen when you try to read an integer but it is given a character), it will not actually consume the input character from the input. This means the next time you call scanf() it will end up trying to read the same character again!

To catch this, you can check the return value from scanf(). It tells you the number of inputs read successfully. When there is an error it should return less than the number of variables you wanted to read in (in this case, less than 1). If this happens, you need to flush the input stream. The easiest way to do this is just by calling fflush(stdin).

Apparently fflush() is a "bad practice", but in small programs it should be fine. There are other "better" ways to deal with this.

mahlerfive 23 Junior Poster in Training

Let's look at a simple example of how you might do this. Imagine you were give the number 72061.

The first thing you should do is determine how many digits there are - in this case 5. Now, you can divide by 10^4 (10 to the power 4, 4 because it is one less than the number of digits) and you will get 7 as the answer. Now you know that 7 is the first digit, and because you used 4 as the power, you know that this is the ten thousands digit. So you can store "Seventy". Now subtract off 10^4 * 7 and you will have the leftover amount of 2061.

Now you simply repeat the process after decrementing the power. Divide by 10^3 and you get 2. Since we used the power 3, we know this is the thousands digit, so we can store "Two Thousand". Then, subtract off 10^3 * 2 leaving 61.

Repeat again, divide by 10^2 to find the hundreds digit. Here the answer will be 0, so we don't need to store anything. Note that in some cases you will still need to (if for example the thousands digit was 0 but the ten thousands digit was 7, you need to still store "Thousand").

Repeat again, divide by 10^1 and get the digit 6 which is the tens digit. Store "Sixty" and subtract 10^1 * 6 to get 1.

Repeat again, dividing by 10^0 (if u really want …

mahlerfive 23 Junior Poster in Training

I want to write a javascript

Then why are you posting this in the C++ forum?

mahlerfive 23 Junior Poster in Training

It should be

readfile >> sample;

since you are getting input, not outputting.

mahlerfive 23 Junior Poster in Training

There is no real point in writing a "bug-fix class". Essentially the derived class will have to overload all the methods of the base class anyway - so none of the parts of the base class will be used. Either make a new class with the functionality you want, or rewrite the old class.

As already mentioned, you probably want to use a vector or something of that sort.

mahlerfive 23 Junior Poster in Training

I just learned some MPI recently and I have a PDF with some basics about how to use it with C (and possibly fortran, i forget). Just PM me your email address and I'll send it over.

mahlerfive 23 Junior Poster in Training

The line

if (argv[1] == "/e")

is invalid since you are compairing a char pointer to a string. To compare strings, use strcmp().

Also, if the user doesn't enter the easteregg argument, you don't want to check argv[1], so first check argc to check the number of arguments.

mahlerfive 23 Junior Poster in Training

You can use the built in STL sort algorithm - http://www.cplusplus.com/reference/algorithm/sort.html

Just follow the example at the bottom where they overload the lessthan operator for the class.

mahlerfive 23 Junior Poster in Training

I have not used them, but I believe the boost library has threads and you can try pthreads as well.

mahlerfive 23 Junior Poster in Training

The only problem with this method is that if you actually want to send a \n, you are out of luck. The approach I use is to tack on an integer on the front of each message to tell the receiver how many characters to expect. The receiver can then keep looping recv() until it has read that many characters. Similary, the sender can keep looping send() until it has actually sent that many characters.

mahlerfive 23 Junior Poster in Training

I can guarantee you the problem is not winsock, it is something you are doing.

Can you post a little code where you are having the problem, tell us what you are trying to send and what you are receiving?

mahlerfive 23 Junior Poster in Training

The reason people are discouraging you is because the very basics of this topic might be material for a senior undergrad course or a graduate course, and considering you said you were a semi-beginner programmer, you probably aren't quite ready for something of this magnitude.

Before even starting to code anything you will have to learn quite a lot of theory. As Ezzaral said, you need to study audio signal processing to begin with. If your goal is to recognize single words through training, then you will probably need to learn about neural networks as well.

I would say that if you are trying to recognize speech in sentences - trying to do this with a decent accuracy would make for a good graduate thesis... if it was a fairly trivial problem, we would already have near perfect speech recognition, but instead the best we have is some fairly clunky speech recognition that only works somewhat well when it is trained a lot, and even then it will only work with that one person and with little to no background noise.