dougy83 74 Posting Whiz in Training

-

dougy83 74 Posting Whiz in Training

assuming str is of type 'string', str is of type 'char'. chars will be considered negative whenever the top bit is set. It's not an issue if you are bitwise ORing, as you will get the correct result.

If it annoys you, feel free to cast to unsigned char, as necessary.

dougy83 74 Posting Whiz in Training

object's new x,y position should display as (0.5,0.5) but everytime i run it with those values i get (0,1) and I am not sure what is wrong.

Not quite. Distance of 1 from (0,0) heading 45^ will be (0.707, 0.707)

if (heading > 0 && heading < 90)
{
xHeadingRatio = heading / 90;
yHeadingRatio = 1 - xHeadingRatio;
x2 = distance * xHeadingRatio;
y2 = distance * yHeadingRatio;
}

Where did you get this formulae? Travelled distance is not proportional to heading. try

dx = distance * cos(heading / 180. * M_PI);
dy = distance * sin(heading / 180. * M_PI);
dougy83 74 Posting Whiz in Training

When in doubt, write a program! It's faster and more accurate than research.

ummm....

google seems to quickly turn up a bunch of results for this question, e.g. http://www.cppreference.com/wiki/operator_precedence
You're right, division/multiplication/modulus all have equal precedence.

... It's one of the reasons I never liked "PEMDAS". If all you remember is the acronym, you always multiply before dividing, which is wrong, and you always add before subtracting, which is also wrong.

I agree, if you multiply before dividing, the answer may be wrong, as in e.g. 2 / 5 * 9
Likewise, if you add before subtracting, e.g. 2 - 5 + 9

However, reversing the above should result in correct answers always: PEDMSA (doesn't really roll off the tongue anymore though)

I'm pretty sure you'll have to use the left-to-right rule for operators where there is >2 operators having equal precedence (i.e. when you add modulus to the mix).

dougy83 74 Posting Whiz in Training

include the dll.h header, and not the project3.dll file.

Make an import library - the .lib file, should be an option in your compiler/linker

link the .lib file into your project. The program will know how to access the .dll file from the details stored in the .lib file.

dougy83 74 Posting Whiz in Training

If you're just displaying the reversed thing to the screen, there is no need to store any numbers in any arrays.

Each call to the function will print out a single digit (the digit of number in the units place). If the number is more than 9, the function will call itself with number/10 as the argument. This will recursively print out the number in reverse. When all digits have been printed, the function will stop, and return, due to the above stated call condition.

dougy83 74 Posting Whiz in Training

Line 20 should be moved to after line 24: you want to let the user enter the search value before you call the search function.

line 86: remove this line - the break statement would quit the loop; before you get to report the location

the seqOrderedSearch function should return a value if the item is not found, e.g. -1; generally you would check the return value to decide whether you would display "item x found at loc" or "item x not found", and remove the cout statement from the seqOrderedSearch function

dougy83 74 Posting Whiz in Training

setw works fine without the need for '\t'. Note that setw is required prior to each item to be formatted.

e.g. cout << left << setw(12) << "item1" << setw(12) << "item2" << endl;

dougy83 74 Posting Whiz in Training

Start at the right, increment it by 1, then scan to the left to see what else can be incremented.

You would only scan to the left if a more-right digit couldn't be incremented - in which case you would try to increment a digit to the left. When you find a digit that can be incremented, you would increment it then set all digits to the right of it equal to 1 more than the digit to their left.

Apparently English is my first language, but good luck understanding what I've just written; I'm sure it made sense when I wrote it.

dougy83 74 Posting Whiz in Training

Obviously recursion would enable a simpler/cleaner approach, if it were allowed.

There is no mention of need for speed/efficiency in the problem statement, so it may be perfectly valid to just use a dirty brute-force method:

#include <iostream>
#include <iomanip>
#include <sstream>
using namespace std;

bool numberValid(int v, int len){
   int oldd = 10;
   for(int i = 0; i < len; i++){
      int d = v % 10;
      v /= 10;

      if(d >= oldd)
         return false;     // non-increasing progression
      
      oldd = d;
      }
   
   return true;      // valid
   }
   
main(){
   int len;
   cout << "Enter len: ";
   cin >> len;
   cin.get();
   
   int maxVal = (int[]){9, 89, 789, 6789, 56789, 456789, 3456789, 23456789, 123456789, 123456789}[len-1];

   for(int i = 0; i <= maxVal; i++){
      if(numberValid(i, len)){
         cout << setw(len) << setfill('0') << i << endl;
         }
      }
   
   cin.get();
   }
dougy83 74 Posting Whiz in Training

just copy all the string data into a temporary buffer and pass it to the function. e.g.

main(){
   vector<string> st;
   
   st.push_back("test11g 1");
   st.push_back("tes22ng 2");
   st.push_back("test3ng 3");
   st.push_back("test44g 4");
   st.push_back("testi55 5");
   st.push_back("testin666");
   st.push_back("testi77 7");
   
   char *st2 = new char[st.size() * 133];
   for(int i = 0; i < st.size(); i++)
      strcpy(st2 + i*133, st[i].c_str());
      
   fn((char(*)[133])st2, st.size());
   
   delete[] st2;
   
   }
dougy83 74 Posting Whiz in Training

$(BIN): $(OBJ)

Those macros are defined elsewhere in the makefile, and that line shows very little information about your specific problem. Post the whole makefile.

dougy83 74 Posting Whiz in Training

If you want the ints to be read only, make them const also (requires the following casting):

const vector<const int*> &  getV() { return *(const vector<const int*>*)&myV; };
dougy83 74 Posting Whiz in Training

change the precision of the stringstream

stringstream c1;
   c1.precision(100);
   c1 << Total; 
   Replacing = c1.str();
dougy83 74 Posting Whiz in Training

I checked about SetSuspendState() in DaniWeb, and googled it, but came up with nothing.
Thanks in advance to the helpers!

Are you sure you googled it? There's about a billion relevant hits on 'setsupendstate'.

from the horses mouth:
http://msdn.microsoft.com/en-us/library/aa373201.aspx

BOOLEAN is true/false (1/0).

The linker error you got (couldn't find xxx) is because you haven't included the powerprof.a library in your project. Go to project options, parameters, add library or object, find libpowrprof.a. Will work after that.

dougy83 74 Posting Whiz in Training

What language are you using to call the dll?? You said VB above (I assumed vb6), are you sure it's not VB.net or Visual Basic 2005/6/7/8?? vb6 successors have different data types to vb6 - I think long is 64bits, so use Int32 instead of long for the declare statement.

dougy83 74 Posting Whiz in Training

how did you declare it in your vb program? what you posted appears to be correct. But you don't need both the *.def file and use of _dllspec(__export) -- all you need is one of them.

You do need both the *.def file and use of _dllspec(__export) if you want clean names exported from the dll (at least in MinGW and VC++2008). Without the def file, you will export a function something like "?sum@@YGHHH@Z"; with the .def file the function name exported is "sum"

dougy83 74 Posting Whiz in Training

The VB declare statement should be:

declare function sum lib "example1.dll" (byval x as long, byval y as long) as long

where example1.dll is the name of your dll file.

dougy83 74 Posting Whiz in Training

Please use code tags in future to make code more readable.

The error is due to top() returning a temporary reference, and you're trying to reference it as non-constant. You could use a const alumnos &al, and make sure all member functions called on al are const (inspector functions - that don't change anything in the class).

Or, The easiest way is to use a const_cast in the reference assignment:

alumnos &al = const_cast<alumnos &>(mypq.top());
dougy83 74 Posting Whiz in Training

I'll be more specific:
// check: for( int j = 0; j < Y; ++i ) or even what you've changed it to for( int j = 0; j < Y; i++ ) for that matter.


hint: (try incrementing j, not i in that statement)

dougy83 74 Posting Whiz in Training

okkkkay...so i tried... and failed. my code looks pretty fine to me (the numbering thing).
could someone please take a look? thanks!

// check:
    for( int i = 0; i < X; ++i ){
         for( int j = 0; j < Y; ++i )

You've got this sequence twice in your code - it's wrong both times. Also, you should check whether the map location exists before you access it - e.g. map[-1][-1] is not actually in the map[][] variable (you may overwrite data in another variable or segfault).

your code works otherwise; well done.

dougy83 74 Posting Whiz in Training

I have it at the following locations:

C:\Dev-Cpp\bin\dlltool.exe
C:\Dev-Cpp\mingw32\bin\dlltool.exe

But that's because I use dev-c++ (mingw) not VC++. You should be able to download it from the net. Try googling it.

dougy83 74 Posting Whiz in Training

Doesn't impdef extract the .def file for you?
so:
"e:\>bcf\bin\impdef lt360lib.dll > lt360lib.def"

will give you the .def file, then to make the import library (.a or .lib) use dlltool with the .def you just made, and the original .dll file:
(see http://mirrors.zoreil.com/webclub.kcom.ne.jp/ma/colinp/win32/tools/dlltool.html)

dougy83 74 Posting Whiz in Training

A related question - for int, is it the leftmost bit that holds the sign? And is it 0 for positive, 1 for negative, or the other way around?

Correct, 1 for negative. See http://en.wikipedia.org/wiki/Twos_complement for how it's done

dougy83 74 Posting Whiz in Training

Both the member function declaration and definition will require the const modifier. This tells the compiler that the function is an 'inspector' function and will not modify anything in the object (which is required when using a const object).

About your 'this' question, 'this' is a pointer to the instance of the object.

dougy83 74 Posting Whiz in Training
case 2:
               Cool.Square();
               break;
          default:
                cout << "Huh?\n";
                break;

I've never heard of that kind of triangle. Are you sure it's a valid form?

dougy83 74 Posting Whiz in Training

Make sure you store the number of rows & cols of each matrix. This may be easier if you put them in a matrix class or struct.

e.g.

struct Matrix{
   float *data;
   int rows, cols;

   float *operator[](int row){
      return &data[row*cols];
      }
   };



Matrix A;
// read maxRows/cols from file
A.data = new float[maxRows * maxCols];
A.rows = maxRows;
A.cols = maxCols;

// now you can reference the data using []
A[2][1] = 5.4;
A[3][3] = 44.9;
dougy83 74 Posting Whiz in Training

Just swap the pointers, as long as nothing else is referencing any elements in the arrays. If there are other references/pointers pointing into the array then do something else - like the temporary array thing (it'll be a bit trickier if the arrays are different sizes).

dougy83 74 Posting Whiz in Training

You can use stringstreams, itoa or sprintf to convert your int to a string of chars.

The problem is that i get errors that i cant convert a int into char. even when i use a cast..

The error would have been that you can't convert an int to a char _pointer_, not char. C++ doesn't automagically convert from integer types to string types.

dougy83 74 Posting Whiz in Training

put the srand(time(NULL)); in the main(), such that it is run only once.

As you have it, every time RandomNumber() is called, srand() is seeded with the same value - hence rand() returns the same value each time.

Salem commented: Good answer. +15