GDICommander 54 Posting Whiz in Training

Use System.out.println("Your message") to print debugging messages about your input string and the value of every variable. First, ensure that the string is received from the scanner. After, look in the code of the stack.

GDICommander 54 Posting Whiz in Training

About the first post, it is a good programming practice to put the character code inside a const variable. Instead of hard-coding the ASCII code of the character, just put the constant. It is more elegant and is very useful if the character is not the wanted one (instead of changing all hard-coded values, just change the constant).

GDICommander 54 Posting Whiz in Training

Can you add a semicolon after MYVAR(DLLINFO, DllInfo), like

MYVAR(DLLINFO, DllInfo);

It may cause an error, if I assume that it is line 20 of vars.h.

GDICommander 54 Posting Whiz in Training

You should put the numbers at some place... and check every one of them...

That is an extremely easy solution.

GDICommander 54 Posting Whiz in Training

For the next tips, I will assume that you know object-oriented programming:

1) Think about how you will represent your tree. I suggest that you take a pencil and a paper and draw a binary tree.

2) What will you do on the tree? (Insertion, deletion, ...) How will the structure react? Again, draw it to see more clearly.

3) And now, the technical part. Will you use pointers, vectors, etc.? Will you use a BinaryTree class, a TreeLevel class, a Node class, a Leaf class? Your previous drawings and the operations will determine what the correct representation will be.

GDICommander 54 Posting Whiz in Training

I am not supposed to refer to a Java book in a C++ forum, but I suggest one of the books from Cay A. Hoffman. It is called: Big Java. There are nice chapters in this book that explain object-oriented programming. But be warned: this book is expensive.

The same author wrote an another book about C++. "Big C++" is the name.

cplusplus.com is a good reference for input and output operations with files.

It is good to have a book, but if you want my opinion, the best references are on the Internet. And again, Google is your friend!

GDICommander 54 Posting Whiz in Training

Yes, they exist. Go for online help on the menu bar (in help) and they will be here. I recommend you this site. It contains a lot of documentation.

http://www.scheme.com/tspl3/

GDICommander 54 Posting Whiz in Training

SRL (Shift Right Logical). This instruction shifts all the bits to the right from a given number of positions. For example, if I do SRL on 0011100 with 3 positions, the result will be 0000011.

You should see the documentation of the processor you use to know if the shifted bits are returned or other details like that.

GDICommander 54 Posting Whiz in Training

Yeah. Thanks for the help!

GDICommander 54 Posting Whiz in Training

As you wish...

GDICommander 54 Posting Whiz in Training

On which OS are you using?. It may not do a difference, but the "slash-backslash" complexity can cause this.

Otherwise, look at the renameTo method. Look for special permissions or existence of the source file.

GDICommander 54 Posting Whiz in Training

Use &type_of_gas instead of type_of_gas.

Without more code, I cannot help much further.

GDICommander 54 Posting Whiz in Training

This amount of code is impossible to read!

Test your stack before attempting to use it!

GDICommander 54 Posting Whiz in Training

If the file you want to copy is already used by an another process (if this is it), you cannot have access to it (except if you have special permissions).

This is very useful program for spotting file handles for every process: Process Explorer. Google it if you have a chance.

GDICommander 54 Posting Whiz in Training

This is what I suggest to you:

1) You will take your FileToArray() function and you will test it with all the possible limit cases (even if they are stupid). If there's no problem, then you will remove it from the post.

2) Do you know JUnit? I strongly suggest you to use it. It is a software testing environment. You will write your tests and use the limit cases for testing. Then, you will see your bug.

This is a common practice in software development to test EVERYTHING before doing something else. And yes, you can do it everytime.

GDICommander 54 Posting Whiz in Training

I remember my algorithm course at university. It was tough, at the beginning, but with determination and a little thinking, I found the graph chapter very easy.

What you need is a very graphical view of the situation and a little creativity. You must be capable of doing this, alone is the best. All I can do is to provide links to existing graph algorithms. If you really want to see the solution, take some paper, some pencils and some hours of hard work, and you will get it.

I hope that you are not beginning this homework late, because an algorithm can be long to find.

GDICommander 54 Posting Whiz in Training

Looks like an homework question. Look here.

http://www.cplusplus.com/reference/iostream/istream/

GDICommander 54 Posting Whiz in Training

This is a character-by-character copy of the source file to a destination file. This is what the code does.

GDICommander 54 Posting Whiz in Training

Hello, everyone.

Is there a program on Linux that displays all the processes that are holding a reference (or handle, I know that it is a Windows word) on a specific file? You know, like Process Explorer on Windows. That will be very useful for me.

Thanks for your answers.

GDICommander 54 Posting Whiz in Training

Creating a recursive function that returns the factorial will solve this problem.

if 0, then return 1
if 1, then return 1
else do n * fact (n - 1)

This is not a tail-recursive version (sorry for the programmming purists), but it will do for your needs.

GDICommander 54 Posting Whiz in Training

What I call a function is something that is not inside a int main(). If you do it with a int factorial() function, you will be able to use it more easily in an another program than a int main().

Putting all the treatment in a function will eliminate the problem of the same factorial for every run.

If you really want to not use function, just set fact to 1 after the computation, but I strongly suggest the use of a factorial() function.

GDICommander 54 Posting Whiz in Training

Maybe one of these algorithms will do the trick for you.

http://en.wikipedia.org/wiki/Category:Graph_algorithms

There are plenty of existing algorithms on the graph theory.

Good luck, you will need it.

GDICommander 54 Posting Whiz in Training

I will suggest you this:

Write a function that takes an integer and returns its factorial. (Use the power of recursion)

Test it (IMPORTANT!) and after, call it in your program. That will simply your code.

GDICommander 54 Posting Whiz in Training

So, it is a math problem. Go there:

http://en.wikipedia.org/wiki/Poisson_distribution

GDICommander 54 Posting Whiz in Training

First, indent your code. It is more readable in that way.

Second, how will you find the answer with a pencil and a paper? Answering this question will lead to the structure of your program. Understand the equation first and compute it after!

Don't hesitate to use functions to wrap complicated computations. And be careful with arithmetic operations with different types.

GDICommander 54 Posting Whiz in Training

Do a search on the Djikstra Algorithm for Graphs. Enter it on Google.

GDICommander 54 Posting Whiz in Training

The last << causes trouble.

cout << "Area is:" << a << "for radius of:" <<  r << ;

Remove it.

GDICommander 54 Posting Whiz in Training

This is not a C++ question. Just think about how you will represent it and if you have problems with C++, your post will be more likely to be solved.

For the update, do a search on the Observer design pattern. That will be a good start.

GDICommander 54 Posting Whiz in Training

One more tip, if you have no idea of how to implement the functions, just think of a picture of the list. Imagine how a list is represented in your head (a group of cells, an array). If you need it, just take a pen and a paper and draw the list state before, during and after an operation (one of the methods). This can help.

One way to implement a data structure is to put aside all thoughts of coding and draw the data structure when the operations are done on it. When you master COMPLETELY the structure, start coding. By doing this, you forgot all the complex things of a programming langage (C++ is good in that...) and you focus on the understanding of what you want to do.

It's good for you that some code has been provided. The code suggests that the list is represented by a primitive C++ array. But if, and only it, you thought of your list as a linked list, or anything else, change the representation, but consider this: will the methods be more efficient and more easy to code with that representation. For example, with an array, if I add an element and the array is full, what do I do? If I want to delete an element in the middle of the list, what are the consequences? (Move all elements at the right of the array by 1 position left...) Your representation must be choiced with the knowledge …

GDICommander 54 Posting Whiz in Training

With templates, you can also put the declaration and the implementation into one .h file. One of my teachers, an experienced one, said this to me.

GDICommander 54 Posting Whiz in Training

I think you can, but it's a bad practice. Declare your class in a .h file, implement it in a .cpp file, and use an another .cpp file for your main.

GDICommander 54 Posting Whiz in Training

And if you want to use templates (to do a list of int, of string, of any type), replace:

class List

by

template typename<TYPE> class List

In an another file (.cpp), implement your functions like this:

template typename <TYPE> void List::first()
{
}

And I hope for you that it's not an homework, because it's not by asking people for already written code that you will learn.

GDICommander 54 Posting Whiz in Training

From this code without using code tags for C++, I can't see the presence of spaces. Is (VectorA^VectorB) a Vector variable? It can be a quote (") problem. Make sure that there are spaces at each side of the << .

GDICommander 54 Posting Whiz in Training

It's simple. This is a method of the Wallet class that takes a Wallet as a parameter, takes its amount of money and adds it to the Wallet on which the method is invoked (this). The other wallet has its amount set to 0.

To find the error, create the class with the minimum requirements and try to compile it! You will see the error, but it's not so difficult to see. Then, this homework question will be completed.

GDICommander 54 Posting Whiz in Training

The best way to do this is with the modulo operator. (%). It returns the remainder of the quotient of 2 integer numbers.

GDICommander 54 Posting Whiz in Training

Add #include<iterator>. It may help.

GDICommander 54 Posting Whiz in Training

For appending a string with another, use the append() from the string type. Use this link for more info:

http://www.cplusplus.com/reference/string/string/append.html

For converting a string to an integer, use atoi() function from the C library.
For converting an integer to string, use itoa() function from the C library.

GDICommander 54 Posting Whiz in Training

It's ok. I have found ACE_OS::fsync() that takes an handle as a parameter.

GDICommander 54 Posting Whiz in Training

It looks correct.

GDICommander 54 Posting Whiz in Training

Do a good analysis. It is the purpose of this assignment to solve a complex problem. And for c_str, look at this page:

http://www.cplusplus.com/reference/string/string/c_str.html

GDICommander 54 Posting Whiz in Training

Check if you are accessing memory that you have not allocated. Are you using an invalid pointer? Are you using pointers?

Are you referencing an iterator on the end of a vector? (ex: it.end())

Without source code, I cannot give you more advice. I hope that this tips will help.

GDICommander 54 Posting Whiz in Training

Hi, everyone! If you have worked on ACE, this is the post for you.

I want to ensure that all the buffer contents of a file are on disk. So I want to use a fsync() or a fflush() function. I'm working with ACE_HANDLEs. Unfortunately, my searches concluded with this: only fflush() exists in ACE_OS and it takes a FILE* pointer as an argument. It will not work with an ACE_HANDLE. So, instead of replacing all my ACE_HANDLEs with FILE, do you have a solution for me?

If there is no solution with an ACE_HANDLE, can you tell me if ACE_OS::write() method ensures an immediate flush of buffer on disk?

GDICommander 54 Posting Whiz in Training

You will need cin, cout, printf(%s, "a std::string".c_str()). Read the documentation about it.

Looks like an assignment. Good luck. Design your program before attempting to code.

GDICommander 54 Posting Whiz in Training

The modulo operator (%) returns the remainder of integer division.

So, if you want a random number between A and B, you just call rand() and you do A + rand() % B. Note that this formula excludes B as a possible result.

GDICommander 54 Posting Whiz in Training

Use rand() function. If you want truly random values at each program execution, use srand() function and put time() (returns the time in seconds since a given start moment) as the parameter for srand().

Again, look for other references for more info about these functions.

GDICommander 54 Posting Whiz in Training

You can use gdb to debug your program. The following link can help:

http://www.cygwin.com/cygwin-ug-net/gdb.html

GDICommander 54 Posting Whiz in Training

I forgot one thing: you can use >> or << to shift the bits. It can be very useful.

GDICommander 54 Posting Whiz in Training

If you're using an int variable for keeping a decimal value and you want to convert it into a binary value, you should know how an int is represented.

An "int" uses 32 bits for representing the number. You can use binary operators in C++ to get the bytes. (OR / AND). I suggest that you do a search on what they are and how to use them. If you don't know the binary representation, do the same.

It's very easy to print all the bytes of an int. You can use a printf option of write a loop that will iterate 32 times to print every byte of the int.

GDICommander 54 Posting Whiz in Training

Use regular expressions. Here is the link:

http://www.troubleshooters.com/codecorn/littperl/perlreg.htm

GDICommander 54 Posting Whiz in Training

You can use Getopt. Here is the link:

http://perldoc.perl.org/Getopt/Long.html