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

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

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

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

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

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!

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

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'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

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

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

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

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

Probably because of when you check for errors on your input stream:

do
{
    fil1.read((char*)&e,sizeof(e));
    e.display1();
 
    fil1.read((char*)&s,sizeof(s));
    s.display2();
} while (fil1);

After you've read the last e and s out of the file, the fil1 stream is still in a valid state, so you repeat your loop one more time. Each read fails, but since there's no data to replace the variable, it maintains the same values it had from the previous read, so prints the same line as previously.

One solution is to test the state of fil1 after reading e (but before printing it), and if it's at EOF or otherwise in an error-state, break; out of the loop at that point.

raptr_dflo 48 Posting Pro

Your code adds the 32-bit value to each 32-bit word of your instance. I doubt that's what you intended. Instead, if the returned carry is non-zero, you need to add that to the next 32-bit word of your instance, and repeat (in case that carry-addition overflows) until you get a zero-carry back.

This means I can just return a 1280bit(640*2) class, when multiplying with two 640bit classes plus an overflow occurs?

That's one approach. Or, you can make your existing class more generic by including its length and allocating the amount of space you need:

class Unfinitebits
{
private:
    int numBits;
    int numWords;
    unsigned long int *m_data;

public:
    Unfinitebits(int howBig) :
        numBits(0), numWords(0), m_DATA(NULL)
    {
        int words = (howBig + 31 / 32);
        m_DATA = new unsigned long int [ words ];
        if (m_DATA) {
            numBits = howBig;
            numWords = words;
        }
    }

    ...
};

Then you can either have numBits tell you the maximum bit-length of the value you can store, or have it tell your the actual bit-length of the value currently stored (rather than searching for the highest set-bit). Or include a maxBits member so you can have both.

Then if you know the actual bit-length of two 640-bit values, you can immediately determine the bit-length of the product and allocate a new Unfinitebits instance of the correct length.

Keep in mind that if you subtract two values, you may need to recompute numBits from scratch. Or else ensure that any approximation is …

raptr_dflo 48 Posting Pro

I can't tell you why fil1.write() and fil1.read() aren't working, without more information. What values are you entering for e1? What file gets generated when you write() it? What is in e1 after you read() it back?

I don't know what your professor meant by "write it via object." To me that means something more like:

class emp
{
...
    void write(ofstream & fil) const {
        fil << name << " " << num << " " << dep << " " age << endl;
    }
    void read(ifstream & fil) {
        fil >> name >> num >> dep >> age;
    }
...
};

so that later you can do:

e1.write(fil1);
    e2.read(fil2);

There's nothing wrong with your logic, if it addresses your assignment. However, what you specified is

question:-
Write a C++ program to merge the content of two files namely “Employee.txt”
and “Salary.txt” into “EmployeeDetails.txt”.

and what you've programmed does not do that, it generates all three files at the same time. I'm just trying to help.

As far as writing out binary files (using read() and write() the way you are so far), I think you need to open the files in "binary" mode. Include flag ios::binary when you open the file. And if the only operation you're performing on a file is writing (or reading), then don't specify the other flag, just ios::out (or ios::in), not both.

raptr_dflo 48 Posting Pro

Oh, and the sort involving swapping successive neighbors is "bubble sort", not "insertion sort" ... if you need to implement insertion sort, then the procedure is different: take an item out of a scrambled list, and add it into the correct place in a new list, moving items out of the way as needed. You can do this in-place using a single array by keeping track of how many items K you've inserted. The first K items should be in sorted order, and the remaining N-K items are the scrambled items remaining to sort.

Either way, hand-sorting N real-world objects (where N is big enough to eliminate trivial answers, and small enough that you can finish in a reasonable amount of time) will really drive home the logic involved.

raptr_dflo 48 Posting Pro

A couple ideas:
1) Your swapping code in lines 6-9 is broken. Watch the order of those lines.
2) If your swapping was correct, your inner loop would execute either once or not at all, so it should just be an if() statement
3) Once you've found two values to swap, you can't just blindly go on as if nothing happened -- instead of blindly hacking at it, do this with a real physical deck of playing cards (one suit is enough): shuffle them up, lay them out in a row, and start swapping neighboring cards as needed. Start at one end of the row and see what you need to do each time you find a pair to swap, until your row is sorted into order. Now write that logical process into code.

raptr_dflo 48 Posting Pro

Why do you expect:

fil1.write((char*)&e1,sizeof(e1));

to write a human-readable line like your sample indicates? That's one (non-portable) way to write a terse binary record. Instead, for text files, keep it simple:

fil1 << e.name << " " << e.num << " " << e.dep << " " << e.age << endl;

and reverse that to read it back in:

fil1 >> e.name >> e.num >> e.dep >> e.age;

(Note, whitespace (including endl) tells the istream::operator>>() where to find boundaries of "items" and isn't read into any item. Use getline(fil1, lineString) to read an entire line (including whitespace) into a std::string variable.)

Also, if you need to create the files as well as merge them, then make those operations separate. Open a file for writing, fill it, and close it. Open another file for writing, fill it, and close it. Then open both files for reading, and a new file for writing, and perform the merge.

raptr_dflo 48 Posting Pro

Please mark your thread as "solved" when you're finished with it. Thanks!

raptr_dflo 48 Posting Pro

OK, I'm going to start from the beginning. Assume I know nothing. I understand that you want to manipulate really big numbers. What values are you storing into your m_DATA array of unsigned ints? Single decimal digits [0-9]? Or arbitrary unsigned 32-bit values? Either way, your assignment to unsigned int help at line 7 (in the first code segment above) is questionable. For instance, if value is bigger than 2G (half the largest value you can store in a 32-bit unsigned val, not that it would be that big, but it -could- be, and it illustrates the problem), then any value of *iter greater than 1 will cause help to overflow.

If you know you're storing "reasonable" values in m_DATA , and passing "reasonable" values for value (and you may want to document this clearly in your code), then you should be OK, but then think about what happens when you multiply two "reasonable" values together, and make sure the result you're storing is also "reasonable", with an appropriate (iterative) carry-operation to move the rest of the result into higher-order positions.

If you're using m_DATA to store consecutive sequences of 32 bits, then you can -never- guarantee that your individual multiplication will work. Instead, note that the product of two 16-bit unsigned values will always fit into a 32-bit unsigned value. Either create your storage array to hold unsigned short int values, and promote each value to 32-bits before applying an operation (which now won't overflow), and then …

raptr_dflo 48 Posting Pro

For your own sanity (and that of others reading it), please indent your code, e.g.:

void functionName (type1 arg1, ...)
{
    some statements;
    while (condition) {
        more statements;
    }
}

Also, when your problem is simply that your code isn't opening the specified file, don't post 200 extra lines of irrelevant functions. Trim the source down to what demonstrates the problem, and post just that.

That said, I don't see anything obvious wrong with your code. Is the filename printed out correctly and completely in your else-block? In particular, if there is any white-space in your path, cin >> ... is going to break at that point, instead use getline(cin, fileName); .

Also, just because the file didn't open correctly doesn't mean the file wasn't found. What are you typing in for your filename? What is the error message printing back out?

raptr_dflo 48 Posting Pro

You are correct, you have a logic error (more than one) in your while() loop from lines 25-29. How do you start the loop if you haven't yet read a score? Once you -do- read a score, what happens if it's -1?

raptr_dflo 48 Posting Pro

I'm running Windows7 here, so the details might look a little different on your computer, but you should be able to get to the Add/Remove Programs dialog, and remove VS2010 from there, and it should correctly remove only what it installed that isn't also needed by something else (e.g. your VC++ installation). At worst, you'll have to go back and reinstall VC++, but that shouldn't be hard either.

Now here's what I have:
From the Windows "Start" menu in the lower-left corner of the screen, I choose "Control Panel" (over in the right-hand column of options).
My Control Panel is organized by topic, so I choose "Programs"
Under the first section, "Programs and Features", I choose "Uninstall a Program"
Then I wait because I have so much junk installed on this box.... :)
When I scroll down, I see 5 items specifically labeled "Microsoft Visual Studio 2010 ..."
A good one to start with, in my case, is "Microsoft Visual Studio 2010 Ultimate - ENU" ... that sounds like the main entry point.

Start by uninstalling that one (and the other 4, if they don't go by themselves). Since it's unlikely that I did any other installation work that day, I could go through and find other items that have the same installation date, and guess that they were installed as part of the same effort and uninstall them as well. With any luck, picking a good start-point will get rid of …

raptr_dflo 48 Posting Pro

I'll take a stab at this, but others please correct me if I'm confused. There are two potential paths to take when -creating- a library ... static vs. dynamic.

If you create a "static library", you end up with a large .lib file which contains all the compiled code for the functions in that library. If you then create an executable using that library, all of that code is copied into the executable at link-time (compile-time: when source code is analyzed and turned into compiled object code, link-time: when various object files and libraries are "linked together" to create the final executable). This makes a larger executable, but one that doesn't depend on a separate DLL file at run-time.

If you create a "dynamic library", you end up with a large .dll file and a small .lib, as previously described. All of the compiled code for the functions in the library is in the .dll file. Now your final executable is smaller, since the code is -not- copied into the executable at link-time, but the .dll file has to be sent along with the executable, unless you can rely on it already being correctly installed on the end-user's computer.

The advantage of dynamic/shared libraries is that many different programs which need the same set of functions can all get that code at excutable load-time, rather than having that compiled function code copied into each executable. In addition, this is mostly how "plugins" are handled -- except now …

raptr_dflo 48 Posting Pro

And you still have a local variable int size; declared near the top of your main(), which masks the global constant const int size = 1000; . Get rid of the one inside main(), it's not needed and it's causing problems.

raptr_dflo 48 Posting Pro

Sorry, I'm not sure what your question is. The "+" operator for strings is defined as "an external function" (instance methods require that the implicit first parameter be the "this" pointer to the current object instance, but don't worry about that detail right now). Here's some code, with comments (see this for more details):

std::string hello = "Hello";  // this uses std::string operator= (const char *txt)
std::string world = " world";  // this also
std::string ex1 = hello + world;       // OK:  uses std::string & operator+ (const std::string & one, const std::string & two)
std::string ex2 = hello + " world";    // OK: uses std::string & operator+ (const st::string & one, const char * two)
std::string ex3 = "hello" + world;     // OK: uses std::string & operator+ (const char * one, const std::string & two)
std::string ex4 = "hello" + " world";  // ERROR: since the "+" is evaluated before the "=", it has no idea that what you're trying to create is a std::string, so it can't do anything intelligent at all
raptr_dflo 48 Posting Pro

Command-line argument handling is certainly a challenge, especially if you want to respond properly to mal-formed entries like "-option=val=somethingextra" or "-option =val" (note the embedded space). To start, assume the user will at least use correct arguments and formatting, so all you need to do is get the name and value.

Since you don't know which optional arguments you will get, you need to loop over the arguments you have:

for (int arg = 2;  arg < argc;  arg++) {
   ...
}

Inside that, for each argument, you need to determine which one it is. A simple strncmp() call will do that:

if (strncmp(argv[arg], "-price=", 7)) {
    ...
}
else if (...)

Then you need to extract the integer-value from the correct position in the string:

price = strtol(argv[arg] + 7);

And finally, it's useful to keep track of whether you saw that argument at all:

gotPrice = true;

This is a very C-centric approach (you could instead make a temporary std::string from the argument, find() the substring of interest and verify it's found at the start, create a strstream from it, and use the stream-input >>-operator to get the value), but should work with a minimum of fuss.

The rest of the logic should be easy enough to work out. The number of optional arguments is argc-2, again assuming no errors, and the user hasn't done something silly and specified the same argument twice (whether with the same value or different values).

raptr_dflo 48 Posting Pro

Your code at line 3 is valid because the + operators associate left to right. The first thing it computes is, effectively const string tmpString1 = "*" + greet_space; which is valid because only the first argument is a string-literal. Then it does const string tmpString2 = tmpString1 + greeting; and so on, each of which works because the first paramater is always a std::string type. Then at the end it does const string greet_write = tmpStringN; to assign the "sum" (concatenation, really) to your variable.

Does that answer your question?

raptr_dflo 48 Posting Pro

Since you've been told to use pointers rather than array-indexing []-notation, don't think of it so much as "how can i ... put that character back into the string" as "once i've determined the character and replaced the %-sign with it, how do I get rid of the two hex-digits?" Hint: since your replacement will always be shorter than the original text (one character instead of a 3-character %XX hex pattern), if you maintain a read-pointer and a write-pointer, then you can keep copying the character at the read-pointer down to the position of the write-pointer until you hit the next %-sign and then evaluate another encoded character.

The first bit is: do you understand hex notation? If you know, e.g. that %d3 is 211 (in decimal), and why, then it should be reasonably easy to say something like: "if read-ptr points to '%' then val1 is the character after that converted to an integer in the range [0,15], and val2 is second character after that, converted the same way. The byte-value of the two hex-values is (... a number in the range [0,255] ...). And that, converted into a character is '...something...'. And that's what gets written to my write-pointer, and then I move each pointer forward by the correct amount."

What you need to fill in is:
how to convert a hex-digit character to an integer hex-value
how to combine the two hex-values into a single 8-bit integer
how to convert an 8-bit …

raptr_dflo 48 Posting Pro

The most obvious answer is, there isn't a function called "Assembler" in the DLL. Maybe there's a typo in how you built the DLL, or in what symbol-name you're expecting to find in it?

raptr_dflo 48 Posting Pro

Just mark the thread as "solved", they don't get deleted except in extraordinary cases. Thanks for trying to clean up though! :)

raptr_dflo 48 Posting Pro

I think you have many problems with your Resize method:

template<typename T>
T Lottery<T>::Resize(T* array, int i)
{
    T* arr3= new T [i];
    delete[] array;
    return array3;
}

You have (1) dynamically allocated a new array of i objects of type T, and done nothing with it, (2) deleted the array that you passed in, for no obvious reason, and without doing anything with it, and (3) returned a variable that isn't defined.

So I think that needs work before you get too far. Once you determine what you need to pass in to a Resize method, vs. what information the class instance already has, I think you'll find that the error message becomes a non-issue (though if you really want to know, it's because the first variable you're passing into the method is an integer, when it's expecting and array-of-integers).

raptr_dflo 48 Posting Pro

From Visual Studio, choose "Clean Solution" from the "Build" menu. This should delete all the intermediate build files and final targets, leaving only the source files. From there, it will -have- to rebuild all the files, so you should be OK after that.

raptr_dflo 48 Posting Pro

Or simply call print2(h, h); from print(), so that you don't skip the first node....

raptr_dflo 48 Posting Pro

Why are you looping over the number-of-trains, inside your loop to input Trains structs, at line 65? And without an opening "{" (and closing "}" some time later), the only line that will be looped-over is the prompt for the first intermediate station name.

I suspect that in adding the additonal struct, you may have misinterpreted the assignment. If there is only one track, then the station-names need to be provided in only one place. And the only values that need to be maintained on a per-train basis are the arrival and departure times from the origin, intermediate stations, and destination.

If you think about what information you need to maintain, then the data structures to help you organize that information may be more obvious, along with the coding necessary to input and display the information.

raptr_dflo 48 Posting Pro

Awesome! Please mark your thread as "solved" for us. Happy coding!

raptr_dflo 48 Posting Pro

Another thought on IsHappy(), while your code works fine (for r), the approach is brute-force, and becomes increasingly ugly for larger strings. What if you wanted to know if an 8-digit number is happy? What about text (say a "word") of near-arbitrary length? (Hint: have you learned about arrays yet?)

raptr_dflo 48 Posting Pro

Your code tests only the first number for happiness. Consider putting your happy-determining code in a function called IsHappy(), which you can separately call for r and q (assigning the values to bool variables r_happy and q_happy, respectively).

You can't have any 0 digits because you specifically disallow them in your tests of num1 through num4. If you want to allow them, fix your comparisons so that 0 is a valid value. Also if you check ahead of time that q and r are >= 0, then you don't have to check whether each digit is negative. N % 10 will always be in the range [0,9] for non-negative N. For fun, just tested negative values of N. My C++ compiler (g++ for MinGW) gives -523 % 10 = -3, while ActivePython 2.6.4 gives -523 % 10 = 7. :)

raptr_dflo 48 Posting Pro

A readability point about your code so far:
You are allowed to use variables longer than 1 or 2 characters. From "The Tao of Programming" (a small comedic book, not immediately at hand, so I can't cite the author, and am quoting from memory), "Though your program be but three lines long, it will eventually need to be maintained." I would recommend variable names like p_digit, p_digit_val, p_remaining_val, (and same for q), bulls and cows.

As far as making sure the inputs are "happy numbers", think about what the statement requires. Can you think of a way to keep track of which digits you've seen so far? If you had a variable called times_digit_has_been_seen (though you can shorten it a bit), what type would make that variable? How would you give it a value (or values)? How would you check it later to determine whether the input number is ok?

While we're on the subject of error-checking user input (which is ALWAYS a good idea), what happens if the user enters a short number like 17? What happens if they enter a long number like 32768?

Doing great!

raptr_dflo 48 Posting Pro

Yes, for P2 you need to input two values, P and Q. And since they're going to be 4-digit numbers (regardless of how you choose to represent them in your program), I think a for() loop is the more-readable way to program the solution.

int digit;
for (digit = 0; digit < 4; digit++) {
   ...
}