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.

raptr_dflo 48 Posting Pro

Funny, to me, it looks like very clearly written instruction in how to use the markdown language for minimal in-line formatting. Or, for the more GUI oriented, you could just select all your code lines using the mouse, and click the Code button along the top of the editor, it works just as well as it did previously.

raptr_dflo 48 Posting Pro

Your sorting code in main() looks close, but as doomilator suggests, move it into the Sort() routine.
Then initialize j = i->NEXT and loop while j != NULL (otherwise you're needlessly comparing i to itself the first time, and never checking the last element in the list). Also, your comparison direction might be wrong at line 38. And you're swapping the first out-of-order element you find, but there might be a better one further on, so you have to check all of the j's before advancing i. Then double check that the right thing happens if you're swapping adjacent nodes (where before_j == i), though it might already be ok, just double-check. Finally, make sure you handle the degenerate cases where there are zero or one nodes in your list.

Good luck, and post back just your sort routine (if that's all that's broken) if you get stuck again. :)

raptr_dflo 48 Posting Pro

You haven't failed. You just haven't gotten to the answer yet. I don't think the project is necessarily beyond what you've learned so far. If you have categories, then each category contains an array of words. If the number of words is up to 7, then each category must also keep track of how many words it actually has. If you know how to generate a random number, then you can use that as an index into an array to pick the corresponding word. I don't think it matters how long any one word is: from that point the program is the same, the user guesses whether a letter is present until all letters are accounted for. Don't forget that if a letter appears more than once in a word (for example the 'n' or 'o' in London), if the user guesses that letter, you need to show all occurrences at the same time.

Start: _ _ _ _ _ _
User guesses 'o': _ o _ _ o _
User guesses 'd': _ o _ d o _
And so on.

So, you need to keep track of (1) the original word, (2) which correct letters the user has tried, and what partial word to display, (3) which incorrect letters the user has tried, and how many (the user loses if too many wrong guesses), and (4) whether the word is finished (and the user has won).

Start simple and work up. Start by making your …

raptr_dflo 48 Posting Pro

Please use the Code button above the editor to maintain formatting of and line-number your code.

The error is a missing * before Health in the first line of class Player.

That said, why do you want the inefficiency of all those pointers to integers for your class members? Just declare them int, instead of int *, and assign them directly instead of allocating, deallocating and dereferencing the pointers everywhere.

raptr_dflo 48 Posting Pro

For case 'e', how are you adding the new info into your list? For case 'l', how do you plan to iterate over your list and display each contact? And obviously case 'f' needs work.

Since I don't know specifically where you're stuck, I suspect the problem is that you're trying to brute-force your way through the assignment by thinking strictly in terms of the code. Your overall structure in main() is mostly fine, so you have thought through the highest level. Now just break down each step into what it needs to do. For example, adding a new contact includes prompting the user, accepting input (both of which you've done), creating a new contact object using that input, and adding the contact object into the list. Break each step into further sub-steps before you worry about writing the code.

You have a contact struct, so you don't also need an Entry class. Instead you need a class to manage your list of contacts, maybe you want to call it ContactList. What members does it need? What methods? (Hint: it doesn't need a name, number and notes fields.)

Once you have the code working, there are other optimizations you can make. For example, you could include getting the desired command from the user into your choice() function: char choice() { ...; return command; }. Or note that the only way to get to the line numbered 13 above, is if command is already 'q', so you don't need to check …

raptr_dflo 48 Posting Pro

I've been working extensively with Python and Qt via the PyQt bindings from Riverfront.

First of all, an "object" doesn't throw an exception, code associated with the object does. So what you may want to encapsulate in a try/catch block is any method call on the textEdit. The constructor almost certainly won't throw an exception, so no need to worry about it there.

For your second question, both forms are equivalent, and the layout becomes the owner of the widget. The widget is destroyed when the layout is destroyed, there shoud be no memory-leak as a result. Memory leaks in Qt come about when a widget for some reason needs to keep track of its parent, and then the grandparent releases the parent. Since the parent and child still refer to each other, they can get stranded. So just watch out for unintended cycles in your referencing.

raptr_dflo 48 Posting Pro

You need to determine whether the 1D version of the matrix is in row- or column- major order. Also, whether the matrices are designed to be applied in prefix or postfix order. These are more or less the same question. I prefer to think of matrices as I learned them in calculus, so they pre-multiply column vectors (instead of post-multiplying row vectors). In that case, a translation has the Tx, Ty, Tz values down the right-hand edge (as opposed to across the bottom). But regardless, printing out a translation matrix will probably give you all the information you need, regardless of which way you think of your matrices: the translation values will either be all adjacent in positions 12-14, or spread out in positions 3, 7 and 11.

Line 4 of Lerner's code above is incorrect. If they were 2D arrays, in row-major order, the result would be

fMat[i][j] += cMat[i][k] * gMat[k][j];

or in 1D-land (if still in row-major order):

fMat[i*4 + j] += cMat[i*4 + k] * gMat[k*4 + j];

And don't forget to initialize fMat[i*4 + j] = 0.0; before your loop over k!

All this should be enough to get you well on your way.

raptr_dflo 48 Posting Pro

Sounds like a take-home quiz. Good luck with that. Google is an amazing search tool.

raptr_dflo 48 Posting Pro

The code isn't even correct as written, but what the line in question says is:

  • take the argument ss, which is a const-reference to the passed object (meaning we're promising not to change the original object, even though we're looking at it)
  • use the & operator to create a pointer to it, so we now have an object of type strSet *
  • finally cast that to type extStrSet, which doesn't make sense since you can't sensibly cast a pointer-to-a-type back to just-that-type

Also, the input to the function has been declared const but the output hasn't, which probably won't compile since it's handing back, again, a reference to the original object. Once you want it const, you should definitely keep it const. :)

As you deduced, the problem with "down-casting" is that the subclass presumably adds more members (which aren't initialized in the casting process), so the resulting object may not behave as expected. I've seen some fascinating trickery accomplished with similar techniques, but it's very hard to guess what's going to be done with an object, and whether to expect it to work. Instead of "down-casting", you can replace that operation with a constructor for the derived class, which takes an instance of the parent class as an argument, and initializes all the members appropriately.

raptr_dflo 48 Posting Pro

Hi Nathaniel, excellent work over all. (Sorry to be jumping in here, but that's how it works some times!) Line 75 in your Delete() method is almost certainly not what you meant (though it looke like line 77 is good). What does it mean if Previous_ptr is NULL, and what do you really want to do in that case? Also, it doesn't hurt anything as-is, but if you're not returning anything of value from your Delete() method, consider declaring it as void Delete(...) instead of Student * Delete(...), and using an empty return statement (at line 81, the one at line 85 could be eliminated entirely). Otherwise, looking good! :)

raptr_dflo 48 Posting Pro

I'm not positive, but it sounds like you're unclear on classes, and "object-oriented-ness" in general. For a case as simple as yours, an Object can be thought of simply as an abstraction of a real world object. Specifically a "product". Objects contain their attributes ("members") and most basic actions ("methods"). I don't know why you'd want to have a separate class to display a product. It should encapsulate its member-attributes (product number, written description, and price) and its abilities (creating/destroying instance objects -- constructor/destructor, displaying an instance's attributes, possibly even entering values from a user or a static-class-method to create a list of objects from the data file.

The part of the program where the user chooses a product is not part of the product class, nor is it part of some parallel "product2" class. You will undoubtedly get into the Model/View/Controller paradigm for building interfaces at some point (and probably others as well), but that's well beyond this assignment. Instead, it can just be part of the "main" program.

So whether you include it in the product class or not, you need a function which can read your .dat file and create a list of Product instances, and you need a loop where the user can enter something, and then the proper product will be found in the list. You may want to wrap the list up in its own class called ProductList with methods like findProductWithNumber(int product_number) or you could even have a findUserSpecifiedProduct() method which includes prompting …

raptr_dflo 48 Posting Pro

A great place to start is the "Read Me: Read This Before Posting A Question" item at the top of the forum listing. Since we're not mind-readers, and can't see your screen from this far away, we don't know what you've attempted, nor what specific failures resulted. Can you prompt for user input? Can you accept the input from the user? Can you verify that you've accepted the input? From there, computing the volume and doing some simple comparison testing shouldn't be too hard.

raptr_dflo 48 Posting Pro

I'm not sure why you'd want your username and password in separate files, keeping them properly synchronized would seem nearly impossible.

ofstream userstream ( path, ios_base::app );
...
userstream << newuser << " " << encrypt(newpassword) << endl;

cplusplus.com is a great reference site!

Read up on encryption options in general (Wikipedia is probably a reasonable place to start), and Google "C++ encryption". You're not likely to want to "make" an encryption system. The systems are there and written for you, just hook them in and use them (download whatever you don't already have, include the correct header file(s), and link against the correct library(ies)).

raptr_dflo 48 Posting Pro

Ouch. My next theory (and here's hoping somebody more specifically knowledgeable will jump in) is that you need to pass pointers to straight-up functions (i.e., C-style, not class instance methods). Which makes sense if you think about it: once you've passed a pointer to just a method, how would the code inside that know which instance of the class it came from? Normally, you'd pass a pointer to the instance, which then has access to all of its members and methods.

I think you can get where you need to, by moving SbcCreateThread() and SbcThreadProc() out of your class, and passing an instance of your class into the former.

raptr_dflo 48 Posting Pro

I don't see where you implement the methods sepcified in Resistor.h. Instead, you've implemented two standalone functions, and then provided prototypes for them in ResistorMain.cpp.

Meanwhile, you have code that tries to create a new resistor object by passing what appears to be a nominal-resistance, a percentage tolerance, a name C-string, and a flag for whether to display the name. So Resistor.h needs a line (maybe after 17) that looks like:

CResistor(float nominal_resistance, float tolerance, const char *name, bool display);

and Resistor.cpp needs a method-body for it that starts with

CResistor::CResistor(float nominal_resistance, float tolerance, const char *name, bool display)
{
    // ininitialize members here
}

(and so on for each of the other methods specified).

raptr_dflo 48 Posting Pro

Also, you should be able to name your file whatever you want. Putting .txt at the end just allows "default programs" (like a text-editor in this case) to be started automatically when you double-click on it.

raptr_dflo 48 Posting Pro

As far as storing values in a file (or in a database on a server), it's a good idea to use an encryption scheme to store something like a password. You can't make the file otherwise readable to your program, but unreadable to everyone else. And if you could, you definitely shouldn't trust that you've done it right. There are reversible encryption schemes (so if the user forgets his password, you can decrypt the encrypted data and tell him what it is), though stronger schemes are one-way: if the user forgets his password, you can't recover it for him; instead, you assign him a new temporary password and tell him what that is, and hope he's smart enough to change it something he can remember (or else force him to do so before he can continue). In this way, if anyone gets hold of the file (or gets into the database), they theoretically can't determine what anybody's actual password is(*). With a one-way scheme, you verify the login by encrypting the password provided by the user and checking whether that matches the encrypted password stored in the file/database.

(*) There are plenty of exceptions to this, I won't go into them here....

For communicating with a remote server, further encryption (using something like SSL) is used to make sure anyone watching the data go back and forth can't get either the raw password or the encrypted password in a state where they could use it to access the …

raptr_dflo 48 Posting Pro

That number of collision-tests shouldn't be bad. Most of "efficiency" involves a priori knowledge of what's going on. For example, if the ground stays flat and your players start above the ground, and are supposed to stay there, then you can use a simpler collision: just make sure each player.y is above groundHeight ... you don't need to test if the player's head (player.y + player.h) is intersecting the bottom of the ground-rect!

Once you need to test a player against a huge number of objects, it starts to help if you group objects that are near each other into a single bounding box -- if the player doesn't intersect that box, then he can't be intersecting any of the items inside it. Again, for stationary objects or objects that move together nicely, determining the bounding box can be done once (or updated very simply). If all of your objects are flying around randomly with respect to each other, that's when it gets challenging!

raptr_dflo 48 Posting Pro

Oh, and at some point you should add some error checking, because even if you get your existing logic correct, "IC" isn't a valid roman numeral.

raptr_dflo 48 Posting Pro

Your problem is at line 31. Which order should number and beforeSum be, in order to perform the subtraction? Also, you have a problem with a number like "XIV", since when you determine you have "I" before "V", you throw out the previous sum -- which was probably "XI", so make extra sure you do everything you need to!