raptr_dflo 48 Posting Pro

Since you are new, suquan629, I'll offer a couple of pointers (no pun intended):

  1. You don't need to memset the array to 0 since you've allocated it to be exactly as long as you need
  2. Since this is a learning exercise, don't use strcpy(), instead use a loop (which is what strcpy() does internally anyway)
  3. Please don't solve users' problems for them. There are always people posting essentially "do my homework for me" in the guise of a question. Instead, provide hints that allow them to solve their problems themselves.
raptr_dflo 48 Posting Pro

I'm not going to go into the code you "found" that does some of what you want. The purpose of the assignment is to write your own, starting with an understanding of what you are trying to accomplish (or what your friend is trying to accomplish, as the case may be).

Starting with terminology: you've got "sum of natural numbers" down, leaving unordered (1+1+4 is different from 1+4+1 is different from 4+1+1 -- ordered would choose one of those as a preferred ordering, and the others would be considered identical), and as you determined lexicographic means, essentially, "as it would be sorted in a dictionary," though even that is somewhat arbitrary if N is greater than 9, as you have to decide whether "10" should be sorted between "1" and "2", or after "9".

As for the rest of the problem, if you note that a sum of natural numbers adding to N is either N itself, or the sum of (a) some number T1 between 1 and N-1 (inclusive) and (b) the sum of some other natural numbers adding up to (N - T1), you can probably deduce the rest of the algorithm. Recursion is well-suited to this problem, but not strictly necessary. If you choose to use it, you will have a function that at some point calls itself (in a way which is guaranteed to terminate!):

void nameThisSomethingUseful(int *terms_so_far, int num_terms_so_far, int remaining_sum_to_achieve)
{
    if (remaining_sum_to_achieve == 0) {
        /* this is a special case, what …
raptr_dflo 48 Posting Pro

Each variable has both an address and a value.
After line 3 above executes, you have:

  • a (address = 0xFF2A, value = 32.5)
  • b (address = 0xFF2E [since each float takes 4 bytes], value = unknown [*])

after line 4 executes, you have:

  • a (address = 0xFF2A, value = 32.5)
  • b (address = 0xFF2E, value = unknown [*])
  • c (address = 0xFF32, value = 5)
  • d (address = 0xFF36 [assuming each int also takes 4 bytes], value = 4 [do you know why, or can you guess?])
  • x (address = 0xFF3A, value = unknown [*])

And so on...

(*) Depending on your compiler, it might be 0.0 (0 for ints, NULL for pointers) or the memory might be full of garbage, use whatever answer your teacher says is right for your case ... or type in the lines and then print out the values afterwards, and see for yourself what happens when you don't initialize variables! Still generally better (and more readable) to explicitly initialize variables before using them, rather than relying on potentially-compiler-specific behavior.

raptr_dflo 48 Posting Pro

Sorry to take so long getting back to you.

I think you're ready for this assignment, just take it one step at a time, and break larger steps into multiple smaller steps until each step is something you can do in a line or two of code.

For this assignment, you need to print out a certain number of rows of text, and for each row, you need to print out a certain number of asterisks ('*'), possibly with a space between successive ones, and preceded by enough spaces to get the alignment you need. You're already off to a good start, but since I don't have your actual assignment in front of me, all I can do is help you with the more general stuff. There are several ways to do almost anything, so unless your assignment requires you to use a specific approach (presumably because that's what the instructor is trying to teach at the moment), feel free to use whatever makes the most sense to you.

Suppose you need to produce the following output (a wine-glass, not an hour-glass):

* * * * *
 * * * *
  * * *
   * *
    *
    *
    *
    *
   * *
* * * * *

How many lines of text is that? (10) How many asterisks are on each line? (It varies...) Are there spaces between asterisks? (Yes, 1, allowing odd and even numbers of asterisks to be centered with respect to each other)

I would …

raptr_dflo 48 Posting Pro

I'd like to start with your looping structure. At line 18 above, if (baris == 1), since this is after the loop of baris over the range [0, bintang) is done, baris can only be 1 if bintang was also 1. And bintang == 1, looking at the outer loop, means this is the last time through the outer loop. Since the only thing you do at this point is loop over bintang and baris again (also making the final break; statement irrelevant), those loops can be performed after the initial loop completes, so you have a structure more like the following:

for(bintang=4; bintang>0; bintang--) {
    for(baris=0; baris<bintang; baris++) {
        // print something
    }
    cout << "\n";
}
for(bintang=0; bintang<3; bintang++) {
    for(baris=-2; baris<bintang; baris++) {
        // print something
    }
    cout << "\n";
}

(Also, consistent use of indentation will make it much easier people, yourself included, to read and understand the flow of your code!)

As far as centering your output, rather than having it left-aligned, consider how many leading spaces would be needed on each line, to position the asterisks where you want them. Then for each line (inside the for(bintang...) loops, but before the existing for(baris...) loops, add additional code to print the spaces (with no newlines, since you want the asterisks to print immediately after the spaces).

raptr_dflo 48 Posting Pro

I'm not overly-familiar with the .bmp image format, but I suspect that any compression used is lossless, since I use it all the time to make stupid little 100x100 image-tiles with just a couple of colors, and they always look good. (Try making a small image with solid-color areas using just a few colors, for example in Microsoft MSPaint, and save it as a JPEG, then view the results -- note the artifacts introduced into various 8x8 blocks of pixels.)

As far as DCT, there's nothing special about 8x8 regions, except that that's how the JPEG image file format is defined. The DCT is converting data from amplitude-per-pixel-location (spatial/temporal domain) to amplitude-per-frequency (frequency domain). Since your data starts out as 2D (pixels in an image), the DCT is also 2D, meaning each value corresponds to a pair of frequencies, one in each direction. One of the values, probably at (0,0), corresponds to the information with no frequency contribution in either direction -- the mean of all values in the region. Other values in the same row/column correspond to other frequencies which exist in only one direction. Remaining values correspond to products of frequencies in each direction. See wikipedia for more insight.

As far as watermarking an image, you need to apply the DCT to get to the frequency-domain (in 8x8 pixel chunks, if you so desire), add your watermarking wherever you want, then apply the inverse DCT to get back to the spatial-domain. Now you have a modified …

raptr_dflo 48 Posting Pro

I want somebody to do all my work for me too. But that's not how it works here on DaniWeb. Here, you write the code, and if there's something you don't understand, or if you're stuck on a particular point, you post the code you've written so far, along with a clear statement of what you don't understand, what you do understand, and what resulting question(s) you have.

Here's a sample to get you started, but feel free to edit it so it meets your needs:
I have an assignment to implement a magic square in C++. I have defined a MagicSquare class with a member variable of a 4x4 array of integers, a couple of different constructors, and a method to determine whether the values in the array form a magic square. Where I'm stuck is filling the array with random values. Here's my code so far:

class MagicSquare {
private:
    // 4x4 array of values
public:
    MagicSquare(int v00, int v01, int v02, int v03,
                int v10, int v11, int v12, int v13,
                int v20, int v21, int v22, int v23,
                int v30, int v31, int v32, int v33);
    MagicSquare();  // default constructor

    bool isMagicSquare();  // method to determine whether the values form a magic-square
};

[...]

I'm assuming you won't make me (or anyone else here) do this much work for you again next time....

raptr_dflo 48 Posting Pro
    int num_rows = 10, num_cols = 2;
    int row, col;

    // allocate: a set of rows, then the set of columns for each row
    int **vals = new int * [num_rows];
    for (row = 0; row < num_rows; row++)
        vals[row] = new int [num_cols];

    // delete what you allocated, in reverse order: one "delete" for each "new"
    for (row = 0; row < num_rows; row++)
        delete [] vals[row];
    delete [] vals;
raptr_dflo 48 Posting Pro

atol(first.c_str())

raptr_dflo 48 Posting Pro

I suspect your error is a "Segmentation Fault", which typically results from trying to access an uninitialized (or already deallocated) pointer. With any luck your "some processor fault error" message actually includes a specific error code number, and maybe even the line of your program where the error occurred. That would be a big help.

raptr_dflo 48 Posting Pro

Base from what I read so far
1. the image is divided into 8x8 sub-blocks
2. then DCT is applied to each of the sub-blocks. I'm stuck here what happens next?

What happens next is specific to the image-file-format. For instance, for lossy compression in the JPEG format, the resulting DCT values are quantized in some way (each is adjusted to fall onto one of a small fixed set of values, and presumably values sufficiently close to zero are thrown out completely). Once quantization has occurred, the original pixel values can no longer be exactly recovered, thus the "lossy" nature of the compression. On the flip side, for most natural photographs, 90% compression still results in an acceptable reconstructed image.

For your purposes, you need to determine:
1. which are the "middle band coefficients" (note that coefficients are 2D in nature, there isn't just one middle-band coefficient)
2. how to modify those values to include your watermark
3. how to determine, for your use-case of copyright protection, whether a given image contains your watermark.

raptr_dflo 48 Posting Pro

// I have no idea what goes in the constructor

Do you have some idea what the members of the class will be? So far, you haven't specified any. Also, your constructor and set() methods should not be private, otherwise there's no way for any code outside of the class to call them. The data members should be private, once you include them, as specified in the assignment. If you aren't clear on the difference between members and methods, go back to your notes from the very first course session. The following questions should get you going a bit more:

  • What is a date?
  • What does a date include? (these will become members of the class)
  • What does it mean?
  • How is it represented?
  • What can you do to/with a date? (these will beomce methods of the class, and friend functions)
  • How do you "increment" a date to the next date? In particular, how do you increment "January 31, 2012"?

You may also wish to implement additional getter and setter methods that allow you to retrieve / modify individual pieces of a date.

raptr_dflo 48 Posting Pro

At line 232 above, you're always reading into the 1000th position of the array, which doesn't even exist (valid indices are from 0 to 999). I think you meant &customer[track].

Then at line 255, you're trashing your value of track by assigning to it the value of getche(). Use a temporary variable there or just ignore the return value completely.

raptr_dflo 48 Posting Pro

Looks like you might need to write your own, if you need full RTF support. See wikipedia, especially the "Implementations" section for an idea of where to look for help.

raptr_dflo 48 Posting Pro

Ignoring the fact that you define, but don't call, enter_password() and enter_name() functions ... at line 25, you get some input and assign it to variable pwrd, but at line 26, you're trying to check the value of variable input which you haven't assigned at all. And the way you test whether the user typed "hello" is to test whether the variable is equal to the string, not whether it's the same object as another undefined variable:

if pwrd == 'hello':

And at line 28, you're checking whether loop is equal to 2, not assigning the value to 2.

Hope this gets you started....

raptr_dflo 48 Posting Pro

In at least two places, your for() loop looks like this:

for(int location = 0; location > tableSize; location++){

I think you mean location < tableSize;.

raptr_dflo 48 Posting Pro

When you copy the elements of list1 into list2, you're copying the pointers to the FileInfo objects, so that list1[i] and list2[i] both point to the same allocated FileInfo instance.

Either create a copy-constructor

FileInfo(const FileInfo &other):
    a(other.a), b(other.b), ...
{}

or make your lists of <FileInfo> instead of <FileInfo *>.

raptr_dflo 48 Posting Pro

Please write complete words. Your txting shorthand makes my brain hurt.

The first thing I see is within your main() in main.cpp, you're recursively calling main(). Don't ever do that; a number of compilers won't even compile it. main() is the entry point from the operating system into your program. Instead, simply move the printing of the menu into the top of the do { ... } while(); loop.

When you declare your static AR::stdcount variable in AR.cpp, assign it an initial value at the same time. E.g. int AR::stdcount = 0;

Avoid using system() calls in your code. There are usually ways to do what you want via function call into a library without executing a separate shell. And specifically avoid coding system("cls"); since the cls command is not portable across shells or operating systems, and even if the user is interacting with the program in a shell/console/terminal, the program should not assume it is the only thing running in, or that it has any control over, the shell/console/terminal. Same goes for system("pause"); -- instead, prompt the user to press a key or enter a value to continue.

In AR::showAll(), why are you incrementing i in the loop-expression, and decrementing t in the loop-body? You're only going to get half the items that way!

At line 15 in GS.cpp, remove the int declaration, qmarks2 is already declared as an int in GS.h. With the extra int, you're creating a temporary local variable which masks the instance member. The temporary …

raptr_dflo 48 Posting Pro

In test2, where it fails to find the value of 40 in the node after 30, print out what it did find (or "no next node" if is_item() fails). Same for other tests.

A useful debug method might be printEntireList(), which can avoid using the other methods (so as not to upset cursor, just start a temporary pointer at head, and move it along until it's NULL) and just print the value at each node, and if the node is the one cursor is pointed at, maybe put the value in square-brackets or something.

raptr_dflo 48 Posting Pro

Let's start simple. Do you understand Part 1 of the assignment? Can you code that much up and see if it will compile?
Then can you use create an instance of the class, use the setters to populate the instance, and the getters to verify the values? Third, add a print() method to your class which addresses part 4 (and the last item in part 2), and verify that it correctly prints the instance values. Then we'll go from there!

Or if this is still a mystery, we can back up. It's probably best not to try to map your understanding of C++ onto the world of databases. Instead think of a class-instance as an abstraction of a real-world object, as much as a row in a database table might represent the same object. The class itself is the genotype (to borrow from biology): a Person class specifies what info is necessary to represent a specific person, and the methods on that person (what a person is capable of doing or telling you about itself). An instance of person specifies the specific values of the info that differentiate that person from all the others.

raptr_dflo 48 Posting Pro

Instead of if (inputFile), try if (inputFile.is_open()).

And when posting your code, please select all of it and click the Code button at the top of the editor, or just hit the tab-key to do the same thing. Then all of your code will get line-numbered and formatted together, instead of starting at the first indent.

raptr_dflo 48 Posting Pro

This should get you started:

template<class Datatype>
class DListNode
{
public:
    //********Member Variables********
    Datatype m_data;
    DListNode<Datatype>* m_prev;
    DListNode<Datatype>* m_next;
    //*********Methods********
    ...
};
raptr_dflo 48 Posting Pro

Usefulness, like beauty, is in the eye of the beholder. The most useful program you can write, to practice the basics, is one that would be useful to you. Write your own address-book / contact-list program, that lets you store and find the info you want your way. Own a lot of books, or CDs or DVDs, or something else? Write a catalog program. Lend them to your friends? Extend your program to keep track of who currently has which item, so you remember to get them back. I love computer-generated images (not that they're particularly useful, or that I spend much time on it), so I have a slew of partially-written programs that make different kinds of images programmatically.

I suspect that many successful entrepeneurs start out with an idea they want for their own purposes, and then realize that other people would find a more-general version of the same thing useful for a wider range of applications!

Another approach for practicing, regardless of usefulness, is read the posts here on the DaniWeb forum, and try to program other people's assignments that sound like an interesting programming challenge to you (as opposed to sounding like an interesting finished project) without referring to their existing code. Then if you get sutck, go back to the thread and see if there's any more help there, or post your code in your own thread.

raptr_dflo 48 Posting Pro

Currently, your order class has mod, ite & cost members. These are attributes of a product, not of an order. An order, conceptually, consists of a set of desired products. You have a method-function called add(), but it takes and/or returns outside arrays of products and orders. What does an array of orders even mean? Rethink your 'order' class as set of products and functions which allow you to operate on that set. (The items that the customer wishes to purchase should be an array of products, which should be a member of the 'order' class.

Does this help? If not, I'll try to remember to check on you again tomorrow! :)

raptr_dflo 48 Posting Pro

This is almost certainly a visual indication that the checkbox (or radio-button) now has keyboard focus (meaning that the space-bar will toggle the state of the checkbox, or select an unselected radio button -- hitting the tab key to move the focus among widgets should confirm this). If you don't want keyboard control, using setFocusPolicy() on the parent dialog might make the dashed box disappear.

raptr_dflo 48 Posting Pro

At line 102, you're resetting y1 in terms of j, regardless of the value of i. You can simplify a great deal of your code by changing where you update values, and noticing something about how the squares alternate:

for (i=1; i<=8; i++) {
  // adjust y2 to match y1
  y2 = y1 + 20;
  // reset x1 before starting row
  x1 = 0;
  for (j=1; j<=8; j++) {
    // adjust x2 to match x1
    x2 = x1 + 20;
    // pick color
    if ((i+j)%2 == 0)
      glColor3f(0.6, 0.6, 0.6);
    else
      glColor3f(0.0, 0.0, 0.0);
    // draw square
    glRecti(x1, y1, x2, y2);
    // update x1 for next square
    x1 = x1 + 20;
  }
  // update y1 for next row
  y1 = y1 + 20;
}

Good luck!

raptr_dflo 48 Posting Pro

The same thing happens on the stack with recursion as with any other function call. In this case, when you first call node * root = t.create(), a frame is added to the stack with space for the returned node* and the address of the following instruction to return to, any arguments to be passed (in this case, none), and local variables (int x, and node *t). Execution then jumps to the beginning of the create() method. When the code reaches t->lt = create();, it adds another frame to the stack and repeats the process. At whatever point the user types -1, the NULL pointer is copied into the returned node* space on the stack frame, control drops back to the saved execution point for the previous level, the return-value is saved into the appropriate variable, and the stack-frame is removed. Then execution proceeds by creating a new stack frame for the right-hand subtree.

Again, this is exactly the same as for any other function call, except that the contents of the stack-frame relate to a new invocation of the same function instead of a different function. And as a result a number of otherwise-potential compiler efficiencies (such as simply inlining the code instead of creating and utilizing an additional stack-frame) often cannot be used. But from the standpoint of an unoptimized "dumb" compiler, there's no difference at all.

raptr_dflo 48 Posting Pro

Looks like you're off to a good start. I believe operator==() is generally expected to return type bool, rather than int, so you could just do:

return this->from == other.from && this->to == other.to && this->weight == other.weight;

But I think it'll work as-is.

raptr_dflo 48 Posting Pro

I'm not entirely sure, but if you're working in Visual Studio, it gets very fussy about the definition of main(). I'd recommend creating a new project of the desired type ("Console Application" is probably best), and then including "Planet.h" and any other additional includes at the top, and pasting the body of your existing main() into whatever version of main() it provides for you. Make sure you re-add your Planet.cpp file to the project as well.

raptr_dflo 48 Posting Pro

Instead of having your order class look a lot like an individual product (but with different names for the members), have it encapsulate the array of desired product instances selected by the user. Using the same idea, you could wrap your arrayp from main() in a catalog class that encapsulates the number of different products and an array of unique product instances.