raptr_dflo 48 Posting Pro

Why do you have grow_size and num_elements members in your array-class, when you don't use them anywhere?

Your code mostly looks fine, just give some thought to what size means and whether you can trust it. Also, what does your Insert() method do if the array is already full?

raptr_dflo 48 Posting Pro

error C3867: 'cc_real::Form1::WaitForMessage': function call missing argument list; use '&cc_real::Form1::WaitForMessage' to create a pointer to member

So did you try what it says? At line 232 above, replace

SdbCreateThread(WaitForMessage, 0);

with

SdbCreateThread(&WaitForMessage, 0);

As far as I'm aware, each is equivalently "a pointer to the function", but apparently the compiler wants you to be explicit about it.

Looks like the same thing when you pass SdbThreadProc as an argument at line 289, put an explicit '&' in front of it.

raptr_dflo 48 Posting Pro

As ive said, my c++ is terrible, barely above beginning, so a lot of the above is way over my head tbh! but i have to say, i appreciate the selfless help you's all are giving me,regardless of my struggling, il go through the above more thoroughly later hopefully.
from the last code i posted, where would i go from there? thanks

No worries, that's why we're here.

As far as where to go from here, and being "terrible" at C++, do the work recommended by pheininger above. It will start improving your C++, and get you all the way to your solution. Nothing stated should be "over your head". Instead of being overwhelmed by how big it looks, just start at the first "Write a program ..." bullet. Just do that much, specifically: "Write a program that selects a uniformly randomly selected ("ums") song from S possible songs and displays it." It's less than 10 lines of code. Don't worry about what the next bullet says until you have the previous one done.

And as I said previously in this thread, and in others as well, programming is ALL about precise thinking. When the whole problem is too big to think about (and it will always be that way -- as you get better at programming, the problems you try to tackle will get harder), just break off bite-sized chunks and deal with those, and then put the pieces together when you're ready.

Good luck, …

raptr_dflo 48 Posting Pro

I went back and looked at your first posting, and it does indeed say "with shuffle", which I had neglected. If that is an accurate copy of the original problem-statement, then I think you're on the right track.

Your shuffle-based solution has a particularly nice behavior: repeats are spread very far apart. You are guaranteed to be able to play at least N songs before playing a song you've played before. What is that value of N? (It should be obvious, it has nothing to do with running your program to determine the average value of N.)

Given your approach outlined above, I don't know what average value I'd expect, maybe ~1038?

Allow me to re-state your algorithm above, does it match what you think you're doing?

// pseudocode!
shuffle songs
save this order into another list  // these are the songs you'll play through the first time with no repeats
shuffle songs again
determine the first time you get a repeat and save how many songs were between that song and its previous occurrence, and save that value

If I have that correct, you can optimize your efficiency a great deal. After you've shuffled the songs the second time, isn't the first song in the re-shuffled list guaranteed to have been played at some point in the run-through of the first-shuffled list? If that's the case, you don't need to reshuffle all the songs for the second list -- since you just need the first …

raptr_dflo 48 Posting Pro

I'm going to recommend a different approach here. You're programming blindly by incorporating code you've written (or been given) previously, that addresses a different problem. You're very clearly not learning anything that way. So here's what I recommend. Throw out all your code AGAIN, now. And start over, but not yet.

Instead, grab some paper and a pen or pencil (remember those?), and write down what your program needs to do. Not the problem you've been given, that's already written, but what steps need to be provided in the solution, in order to answer the question. If it helps, pretend you're the music player. What do you do? Divide that answer up into individual steps. Then divide those steps into more steps. Respond here with your steps. If you respond with code, I'll come to your house and beat you up. Just kidding about that last part, but don't go back to programming until you're clear about what you're going to program.

(Extra credit: As far as shuffling the list of songs ahead of time, what does that do for you? What does it guarantee? Why is that a good idea? Why is it not appropriate for this assignment?)

raptr_dflo 48 Posting Pro

No, it's not an infinite loop. You're not getting any output because your program is waiting for your input, at line 16 above.

And why are you back to creating a shuffled list of songs?

raptr_dflo 48 Posting Pro

Also, for what it's worth, I had coded up the Sieve of Eratosthenes algorithm for finding prime numbers. In Python. Took about 17 seconds to find the primes under 1 million. Then in response to somebody (on this forum) who wanted to accomplish the same thing in under 0.1 seconds, I coded it up in C++ in VS2010. It took about 70 seconds to do the same thing, and that's after I carefully re-selected my data structures to eliminate needless re-allocation of memory. Pulled my hair out for a while, then remembered to set up a Release configuration, instead of Debug. Then it ran in 2-3 seconds, which is what I'd expect, compared to Python. Now I understand that debug-compiled code is necessarily larger and slower than optimized release code. But a factor of 20-30x slower is just insane! Probably not related to your problem, but something I didn't know I had to watch out for!

raptr_dflo 48 Posting Pro

Works fine for me. Try printing the accountType immediately after you input it, to verify you got it.

Also, about 5 lines up from where you currently start your output, you have a typo which assigns 'C' to accountType instead of testing whether it's equal to 'C'.

In the future, please surround your code with code-tags, it preserves your formatting and numbers your lines so we can discuss your code more intelligently with you.

raptr_dflo 48 Posting Pro

The discrepancy might be caused by any number of factors. If your graphics card doesn't support VBOs (vertex-buffer objects), then your code is creating them but the OpenGL library is, in software, converting them to something the card -does- support and sending that. If you have a huge number of VBOs, they may not get usefully cached on the card (after the available memory for them is exhausted, every time you send a new one across, some old one has to be deleted to make room, by the time you circle back around to one you want, you have to send it again). If you're only rendering a single frame of animation, you have all the overhead of creating the VBOs and none of the performance gain of re-using them.

Also, while it wouldn't likely cause a reversal of efficiency, there tend to be smaller issues around individual object-size -- way back in the day of t-strips, there was anecdotal evidence that performance gains were minimal for strips longer than 12 triangles (on then-state-of-the-art SGI hardware), though the explanations for that tended to be feeble at best -- real explanations tended to involve things like "is the entire strip within the view frustum?" "is the strip devolving (in the distance) down to a trivial number of pixels?" In any case, longer strips still helped, just not by as much as one might hope.

In general, things that "are more efficient" in OpenGL almost always have some set of …

raptr_dflo 48 Posting Pro

Did you scroll down far enough to find the link to this? Somewhere in there is probably some help as far as how to use the library....

raptr_dflo 48 Posting Pro

Since it's been a day or so, I'll jump in!

The "x-1" you've seen is part of the process of shuffling an array, which isn't part of this assignment. The reason it exists, if you look back to your earlier code sample which shuffled the song list, is because by the time you get to the last song in the list, there's nothing left to shuffle it with.

Picking a random song is as simple as rand()%1000 (which gives you values in the range [0,999] with approximately equal probability).

Your code so far checks only whether any future song matches the first song. This is incorrect, and has already been discussed endlessly in this thread. Each time you pick a new song, you need to check whether it matches -any- of the previously selected songs. The good news is, none of the previous songs will match another previous song, or you would have quit the loop already.

I will reiterate, because it's important in general - programming anything is an exercise in precise thinking. If you can't think through the problem you're trying to solve, the program you're writing won't solve it (except maybe by accident). You need to be able to think through the process of solving the problem, in steps small enough that they correspond to lines of code. The "top down" approach breaks the solution of the problem from a single item ("the solution") into a few high level steps ("first do A", "then do B", "finally …

raptr_dflo 48 Posting Pro

As for binary, looks like you're building the string in reversed-order? In decToHex, you store your remainders in reversed-order, and then iterate through backwards to build the string in forward order. Try doing exactly the same thing for decToBinary (except, of course, in base-2).

raptr_dflo 48 Posting Pro

Try filling 8 of the 9 spaces on the board, in such a way that neither player has won already, and then call AlphaBeta() with ply=1?

raptr_dflo 48 Posting Pro

Hmmmm. In your call to AlphaBeta() from main(), in the while (!board.gameOver()) {} loop, do you want to pass 9 as the number of plays to test each time? Or do you want to start with 9, and then pass in successively smaller values while (each time) you commit the optimal next play? I don't know whether this solves your problem, i.e., if you're getting a NULL best-move back from the first call.

raptr_dflo 48 Posting Pro

BobS037,

Exactly. But on DaniWeb, we strive to have people fix up their own code, rather than just doing it for them. It might take a bit longer, but people learn more, and learn better, by "doing it themselves" with some help. Cheers!

raptr_dflo 48 Posting Pro

Actually, I think the problem is that n is too large (since you determine the number of base-10 digits you need to represent the integer, by repeatedly dividing by 10, rather than the smaller number of hex digits you need). You then fill most of the array r, correctly dividing by 16 each time. But you don't keep save the final number of values actually stored (the value of i, following the last assignment into r at line 28 of the correct block of code above). Then you reverse your values (correct idea!) but start at the end of the array. If you didn't store a value into position n-1, then it probably has a garbage value in there, and your seg_fault is because you try to append the hex-digit from the 42954383247'th (or whatever) element of your h array, but you have only 16 entries!

raptr_dflo 48 Posting Pro

I'm not going to take the time to download and read your Word-format document, since you didn't take the time to copy&paste the most minimal portion of it into your post.

That said, your logic is flawed in your inputVLI routine: you're inputting a "digit" and storing its integer value into the array (and breaking out of your loop on no basis whatsoever), before you check whether the input is OK. Talk through what needs to happen each time the user types a key, and then code that. And your test-expression ('0' <= digit <= '9') is invalid, you have to break it into two relational tests. How would you read that out loud? "zero is less-than-or-equal-to digit and digit is less-than-or-equal-to nine". Implement that.

Now try it yourself before looking carefully at the following!

No peeking!

OK, fine, peek. :) Try this:

void inputVLI(int vli[], int& size)
{
    cout << "Enter a lot of numbers but less than 100 times." << endl;
    size = 0;
    char digit;
    while (size < 100) {
        cin >> digit;
        if (digit < '0' || digit > '9')
            break;
        vli[size] = int(digit - '0');
        size++;
    }
}
raptr_dflo 48 Posting Pro

The variable isn't in scientific notation, it simply stores the value (the specifics of how it does so are irrelevant to your question). The issue of notation is how the value of that variable is displayed.

It sounds like your problem is actually "how do I parse a number in scientific notation into a value?" ... since I've commented heavily in your previous posts on calculator programs! Scientific notation is simply the use of an exponent to reduce the need for excessive zeros present in the "standard form" for very large or very small numbers with limited number of significant digits (e.g. 0.00000000345 or 3450000000.0). So assuming you have something like 3.45E-9 or 3.45E+9, you want to know (1) how to identify that that's a number, not a bizarre equation with a variable "E" in the middle of it, and (2) how to read that number into a float/double. The answer to the first question can be addressed using "regular expressions". Your compiler probably includes a header-file and library for this. Coming up with an expression to match your string against shouldn't be too hard: "an optional + or - sign, followed by a 1-9, optionally followed by a decimal point and zero or more decimal digits, followed by an E, an optional + or - sign, and 1 or more decimal digits". Once you know that entire chunk of string represents a floating-point number in scientific notation, cin can probably read it as-is:

double val;
cin >> …
raptr_dflo 48 Posting Pro

I've never been thrilled with the idea of complex data types as return values of functions. That may well just be personal preference, but I would either dynamically allocate an instance of the MoveScore structure, return the pointer to it, and free the allocated instance when done; or pass a reference to the structure as one of the arguments, so there's no local version of it at all in AlphaBeta().

Assuming that's not the problem, have you at least tried saving the return value of the function into a local variable, before trying to access one of the structure memebers? E.g.,

...
MoveScore ms = AlphaBeta(board, (isX?x:o), (isX?o:x), 9);
GameMove gm = ms.move;
board.execute(gm);
...
raptr_dflo 48 Posting Pro

Any header file ( foo.h ) provides the declarations/prototypes for variables, functions, and classes (and because of how they're handled by the compiler, implementation of templated objects, but that's another story). I have no idea what specifically might be declared/prototyped in cpu.h . Or cpuh.h , since that's what you're including, twice.

But now that I look more closely, you've copied the code from various files into one block for us (or that's how it's been code-tagged for you). So it looks like cpuh.h is in your own project, and declares the cpuschedule class, and then the implementation .cpp file and main .cpp file both include it.

If you've copied all the code into a single file, then you no longer need to #include the header file (its code is already in your file). But that's bad programming practice. Keep the files separate as originally intended, and learn how to use your development environment to manage the files.

raptr_dflo 48 Posting Pro

Commenting out the line where the compiler is complaining, internal to a huge header that works fine in another project, is not the correct approach. Instead try commenting out items preceding the #include for this library -- other #includes before this one? I suspect that a different header is declaring one of the variables used at/near the offending line, or worse, #define'ing a macro with that name, e.g. (a stupid example):

#define R Circumference/(2*3.1415926)

Then the definition in the lines immediately before your offending line become

template <class Circumference/(2*3.1415966), class A1, class A2, class A3>
...

which is clearly unusable. And would presumably cause a completely different error message. But something along those lines is entirely possible. Try including all the dependencies for your larger project-B into a new empty project-D that just has an empty main() that doesn't actually do anything. See if that compiles. If not, start removing one dependency at a time (and re-adding it as soon as you've tested), until you find the one causing the problem. (You can't do this in project-B because there's presumably code that requires each of the dependencies you're including.)

raptr_dflo 48 Posting Pro

Looks like you copied the table of contents from, e.g., here. The concept of a "locator" is given only maybe 8 pages of attention in that edition, according to the page-numbers given, ~4 of discussion and ~4 of implementation. Of course the content isn't available online, the publisher expects you to purchase the book.

I got this far from a Google search for the words: priority queue abstract data structure, to which I added locator and then clicked a link "no I didn't mean location, I wanted only locator. The results are pretty much universally either references to printed texts, or course syllabus/descriptions.

But from here, you should be able to get started enough to read up on priority queues on wikipedia (the link is in there), and get a sense of a "locator" to the extent that you can figure out how to combine the concepts. Or bite the bullet and go buy a good up-to-date text. Yes, they're expensive, but a lot cheaper than paying for a college course if you can learn from the book on your own.

Best of luck!

raptr_dflo 48 Posting Pro

Modular programming is good too. Rather than just a nearly-600-line start() method, and a 150-line main(). Break it up into meaningful chunks. It will be much easier to for others to follow, and more importantly, easier for you to maintain/improve later.

raptr_dflo 48 Posting Pro

At line 100, you return a score without first undoing the move. So instead, try something like:

int score = -1;
if (b.hasWon(player))
    score = 100;
b.undoMove(col);
if (score >= 0)
    return score;

or just:

if (b.hasWon(player)) {
    b.undoMove(move);
    return 100;
}
else
    b.undoMove(move);

Then above, at line 81 of evalAllMoves(), why are you just checking the first 4 positions of the board, instead of all 9? And you presumably need to check whether a position has previously been occupied by either player, before attempting to play there.

raptr_dflo 48 Posting Pro

Another way to say what Narue said is: programming is an exercise in precision. It's nearly impossible to program something until you can think about it (and thus speak about it) precisely. And once you can think about the problem precisely, the code virtually writes itself. Learning to program is, first and foremost, teaching yourself to think precisely. Start there, and work forwards: what is your input (integer or string of colon-separated hex characters) and what output do you expect to get as a result of your program? Is there some intermediate format you need, between the input and output? What format is that, what will it be used for, and above all, is it needed at all?

raptr_dflo 48 Posting Pro

Your deleteMatrix() function frees the nodes from each row, but not the rows or the matrix-structure itself. Make sure that everything you malloc() (or new ), you also later free() (or delete ). Simplify, simplify, simplify. Your buildRandomMatrix() function calls createMatrix(rows, cols); if the latter allocates the cols elements of each row (as I would expect from the name and calling convention), then your next line orphans each original row as it creates a new row with buildRandomList(cols).

raptr_dflo 48 Posting Pro

At line 13, you're also initializing min to the first (zero'th) element of the array before you've initialized the array. Instead, do the same thing, but immediately before the loop over the elements of the array where you're updating min (lines 29-34 above).

raptr_dflo 48 Posting Pro

For what it's worth, most commercial Windows software puts "hidden" data in %APPDATA%/<ProgramName>/whateverYouWant. User files, by default, are placed somewhere under "My Documents" (or "Documents and Settings/<user>" in XP). Search for SHGetSpecialFolderPath function on msdn.microsoft.com for more info on how to get the actual directory for constant-named conceptual folders.

I'm not a TurboC user, so I can't help with compiler-specific limitations.

raptr_dflo 48 Posting Pro

A couple of things.

If the desired version of TC doesn't provide the entire path to the executable in argv[0], you need to use one of the other methods suggested very early in this thread to get at it.

This won't help, since you only get the path in TC4.5, but just so you know:
+ in your for-loop at line 11, start with i=strlen(path)-1 (path[strlen(path)] is the terminating '\0' character, it's fine as-is, just something you typically don't want to look at)
+ also at line 11, check that i>=0, in case there's no slash mark in the string at all
+ elements of the string are chars, so compare chars (and assign them) to chars (use single-quotes instead of double)
+ both forward and backward slash characters are valid path separators in Windows, so check for both

I won't give you complete correct code for this at this point, since you need another approach to get the path anyway. Good luck.

raptr_dflo 48 Posting Pro

I gave you TWO ways of copying the directory path of the program into a string. If you don't understand what I said, I recommend you stop begging for handouts and actually re-read what I said until you -do- understand it. If you still can't understand, I recommend going WAY back to really basic beginning programming. You're not going to acquire programming skills if you just get other people to do it for you.

Meanwhile, just to get you to ask a different question, here is a complete working program that does what you asked, and proves that it did it by printing it out.

#include <iostream>
#include <string>

int main (int argc, char *argv[])
{
    if (argc < 1) {
        std::cerr << "ERROR: program has zero arguments, "
                  << "cannot extract program-name" << std::endl;
        return 1;
    }

    std::string program_name (argv[0]);
    std::cout << "Program name is: " << program_name << std::endl;
    return 0;
}
raptr_dflo 48 Posting Pro

argc is an integer, it's the number of arguments in argv , which is an array of C-style strings. Try:

for (int i = 0; i < argc; i++ )
    cout << "arg " << i << ": " << argv[i] << endl;

As far as type-mismatch, the type of argv is const char* [] , an array of constant C-style strings. The type of one of them, for example argv[0], is just const char * . To copy a C-style string conveniently, use char * copy = strdup(argv[0]); . To be more C++-ish, simply create a STL string from it: std::string copy(argv[0]); . Note in the second case that one form of the string constructor allows you to pass a C-style string. Awesome!

raptr_dflo 48 Posting Pro

Yeah, without digging too deeply into potential logic issues (and admittedly looking really fast, so forgive me if I missed something that should have been obvious), it looks like you loop over the entire set of tiles twice, once after updating your x position, and once after updating your y position. Instead, why don't you update x and y at the same time, then loop over the tiles once? Also, you may need a separate touchesFloor() from touchesWall() so you don't end up with weird false readings after adjusting x position.

As far as not falling, it looks like you set inTheAir = true only if you press space. So before checking for collisions, you should probably include

if (yVel > 0)
    inTheAir = true;

then if you determine you're at a tile you shouldn't fall through (or collided with one while falling), you set yVel = 0 and inTheAir = false (this part is already done, it's just the start part above that's missing).

raptr_dflo 48 Posting Pro

replace

void main()
{
    ...
}

with

int main(int argc, char *argv[])
{
    cout << "Program is called: " << argv[0] << endl;
    ...
    return 0;
}
raptr_dflo 48 Posting Pro

The way to determine which function is failing, is to split them out into separate steps, and print the results. You already have a recursive print() function, so call build(A, N) and call print() on the list it returns. If that looks OK, then call split(L, p, q), and call print() on p, and again on q. If that looks OK, then the problem is probably merge(). This is a -very- standard debugging technique, and works just as well for expert programmers as it does for beginners.

Your build() function looks OK, though since you have it embedded in your merge_sort() function, you are determining the amount of time it takes to build the linked list, along with the amount of time to sort it (using merge_sort). You may want to build the list first, and then pass the list into the sort-method of your choice, so you're timing just the sort....

Then, your split() function looks broken to me. Why are you allocating new cells in there? You should just be determining how to make two lists out of one. I said previously that there are several ways to do it. Pick a method that makes sense to you, then draw on paper how it should work: draw a short linked-list as boxes connected by arrows, with a number in each box. What has to change about that picture for there to be two linked lists instead of one? How do you code that change?

Also, …

raptr_dflo 48 Posting Pro

Also, 30.000 can be represented exactly as a float, so I'm concerned that your calcualateAvailableUnits() function may be doing something which unnecessarily introduces error into your value. While fractions of units may be necessary in your computation, it may be worthwhile to consider if there's an intelligent way to keep your computations in integers. For example, if you need to track tenths of units (e.g. 3.1, 5.7), then manipulate your values in tenths of units (e.g. 31, 57) until you're finished, and then convert to floating-point units only at the end.

For what it's worth:
0.1 = 1/10 = 0*1/2 + 0*1/4 + 0*1/8 + 1*1/16 + 1*1/32 + 0*1/64 + 0*1/128 + 1*1/256 + 1*1/512 + ...
= 0.0001100110011001100... in binary.
Such a simple value (in decimal) cannot be completely/accurately represented in binary!

raptr_dflo 48 Posting Pro

And you still can't store 2D coordinates of the form (x,y) into a list<int>. Perhaps you need a structure like:

struct PointWithDistanceFromKnownPoint {
    int x;
    int y;
    int manhattanDist;
};

And then form a list of those, and provide a "comparator" to the list.sort() function.

If we're all still confused about what you need, consider the possibility that you haven't expressed your problem clearly. Feel free to post the text of the assignment, if that will help clarify your needs.

raptr_dflo 48 Posting Pro

Kyle,
Your ptr variable is a pointer to a string, not a string itself. So if you assign it by allocating new space using the new operator, you need to dereference it back to a string (rather than a string-pointer) before indexing characters out of it:

...
var1[n]=(*ptr)[n];
...

That said, it looks like you're doing a lot of needless extra work that the std::string class does for you, such as passing a size value into your constructor. A string already knows its own length:

string s = "My string";
cout << "The length of '" << s << "' is " << s.length() << endl;

And you probably don't need a pointer at all. Instead, just add another string member called "reversedString", rename your copyString() method to reverseString() (since that's what it does), and inside it, just start out with:

reversedString = testString;

to make the reversedString the correct length. Or there's a cool constructor which makes an n-character string pre-filled with a designated character:

reversedString = string(testString.length(), '*');

and then proceed as before.

raptr_dflo 48 Posting Pro
#include <iostream>
#include <string>

using namespace std;

bool is_pal(string a)
{
     int b=a.length();
     for(int i=0;i<(b/2);++i)
             if(a[i]!=a[b-i-1])return false;
     return true;
}

int main()
{
    string s;
    cout<<"Please enter a string:\n";
    cin>>s;
    if(is_pal(s)) cout<<"This is a palindrome.\n";
    else cout<<"This is not a palindrome.\n";
    
    return 0;
}

frogboy, please don't post complete solutions to students' questions. Instead, in the rare cases like this where they ask a specific question, help them sort out the question rather than giving them a completely different solution from the one they're working on, especially without any explanation whatsoever why you're doing so.

raptr_dflo 48 Posting Pro

Please post the definition of your RecordArray variable. So far I can't tell why if the string found in one place (or its integer conversion) is greater than another, why you're swapping the last items between the two places.

Let's start with:
What data are you storing?
What does it mean to sort that data?

raptr_dflo 48 Posting Pro

What error message do you get? We can't see your screen from here....

Also, why do you call add() twice from your input case (once after inputting num, and again after inputting age)? Why do you declare your "node" to contain two integers and two strings, but provide two separate functions (add() and str()) each of which creates a new node with only two out of four values provided?

Slow down. Think logically about what you're doing. Say it out loud. Write code that corresponds to what you say. If you can't write a couple of lines of code corresponding to a verbal "step" in your process, you're not thinking clearly yet. Re-start this paragraph.

raptr_dflo 48 Posting Pro

Well max(numbers[m], numbers[m]) presumably returns the maximum of the same value provided twice. Which is obviously a silly thing to ask for. My recommendation: stop trying to do it "the cool way" and actually think about what you're trying to accomplish, and how to go about accomplishing it one step at a time:
1) Read a line of info.
2) Determine whether you should save it:
2a) If yes, save what you need.
2b) If no, then skip it.
3) Repeat.

What info do you -want- at the end? What info do you also need to save so you can tell whether the next line you read is "better" than whatever you have saved so far? What should you do to make sure you save the info from the first line? What should your program do if there are no lines at all?

raptr_dflo 48 Posting Pro

The problem is at the first line in your main: MyExaminerViewer a = new MyExaminerViewer(); The new keyword dynamically allocates an instance of the specified class and returns a pointer to it. The correct usage of the default constructor is either MyExaminerViewer a; // shorthand for MyExaminerViewer a(); or MyExaminerViewer *a = new MyExaminerViewer; // same as above, empty () are implicit

raptr_dflo 48 Posting Pro

As far as line 72 above, cout << "Test << " << pnomial.get() << endl; , Poly::get() returns a void. You can't "cout" a void.

You have the concepts scrambled between "have a void function that outputs the info to cout" and "implement a custom operator<<() that inlines the info in the specified output-stream, the same way a predefined type works."

The way Poly::get() is currently implemented, it does its own output to cout, so you could just call:

cout << "Test -- ";
pnomial.get();
cout << endl;

Or if you want to be able to output a Poly instance as though it's any other object, implement your friend function operator<<() to output the desired contents from the get() method. I've rather-thoroughly re-implemented it to print the polynomial in a "standard" form. Make sure you understand what each line does, in case your course instructor asks!

ostream& operator<< (ostream& stream, const Poly& pnomial)
{
    bool needs_preceding_plus = false;
    for (int i=pnomial.order; i>=0; i--)
    {
        if (pnomial.coeff[i] == 0.0)
            continue;
        if (needs_preceding_plus)
            stream << " + ";
        else
        {
            // will need it for the next term
            needs_preceding_plus = true;
        }
        if (i > 1)
            stream << pnomial.coeff[i] << " x^" << i;
        else if (i == 1)
            stream << pnomial.coeff[i] << " x";
        else
            stream << pnomial.coeff[i];
    }
    return stream;
}

Untested, so sorry if I've inadvertently introduced any compiler errors!

raptr_dflo 48 Posting Pro

Sigh. Why, oh why, do people not read the very-clearly-marked "Read This Before Posting A Question" sticky-thread at the top of the Forum?

Hi alexander1s, welcome to DaniWeb, and sorry to be such a grump, but this is probably the fifth post I've read in the past 15 minutes that doesn't follow the most basic instructions! The most commonly-violated directives are:

1) Don't post into ancient threads. (you didn't do this, so no worries.)
2) Surround your posted code with [ CODE ] tags. (you didn't do this either, but you should have.)

That said, there's no indication in your posted code as to where your problem is occurring. In fact, it looks like your only reference to cin is currently commented-out. Though I doubt that's what you meant when you say you're getting the wrong data.

raptr_dflo 48 Posting Pro

Welcome beginner,

There might be some errors.

Might? Did you run your own program and see what it outputs? (Hint: there are several errors in your get_pie() function involving data types.) Also, please use [ CODE ] tags (select your code after you paste it, and click the [ CODE ] button/icon at the top of the editor) so your program is more readable.

Did you have a specific question to ask? And in the future, please don't post into long-dead threads.

raptr_dflo 48 Posting Pro

Yes, but the question is "can -you- convert it to C?" ;)

Please don't post into old threads. The corrected code was posted well over a year ago. Instead, start a new thread, including your specific questions and your own code. You can provide a link to the old thread if that will help readers answer your question.

Also, DaniWeb is not a "do it for you" environment. We're here to help you become a better programmer, but you have to do the work. There's a C forum here, if that's the most appropriate place for your questions....

raptr_dflo 48 Posting Pro

[ignore me]

raptr_dflo 48 Posting Pro

stl has not hash map as I know, you can search some open source ,there are many excellent open source library for hash map

stl::map<> I think does pretty much exactly what anyone would need, with the exception of providing your own hashing function. There's a multimap<> container as well, which supports storing an arbitrary number of values per key (instead of the usual just-one-value).

raptr_dflo 48 Posting Pro

If you haven't learned stacks yet, then you should (probably) ignore the advice. Instead, just think through the problem in very small pieces:
1) Start with your input value. Is that part of the "bumpy" sequence? If so, count it.
2) Is your sequence finished? If so, you should already know how many items are in it. You're done.
3) Otherwise, compute the next value of the sequence, and count it also. Go back to step 2.

If you can can code a loop that addresses steps 2 and 3, then that's all that is required to code the assignment. (Hint: "Go back to step 2" is the problematic piece -- instead you really need a loop that keeps going until you discover that you're done.)

raptr_dflo 48 Posting Pro

argv[0] passed into your main is the path to the executable. It might be a fully-qualified path, or it might be relative to the directory the user was in when he/she started the program. If the latter, there should be a function call out to the OS to return the "current working directory" (might look something like cwd() or pwd()) or you may be able to get it from the set of environment variables managed by the shell, with a function like getenv().

As far as how to get the window text to stay where you want it to stay, and scroll (or whatever) where you want, you may have to code that yourself. I'm not a TC user at all, those functions are not part of the C++ standard.

Also, I appreciate how frustrating it can be when deadlines approach and the coding process isn't going as well as I'd like. However, your deadline is not an emergency for -us-, and with any luck, you'll learn from it how to schedule your own future programming efforts. That's a skill which comes, as far as I know, only from experience. And after 20+ years of professional software development experience, it -still- bites me once in a while.