Duoas 1,025 Postaholic Featured Poster

I have no clue about VC++. You should have started a "Windows Application" project, and AFAIK that should have done it for you...

Duoas 1,025 Postaholic Featured Poster

If you are on linux, check out Jeff Tranter's eject.

Duoas 1,025 Postaholic Featured Poster

In Delphi, I like the FormatFloat function. If you look at the docs for it, you can also check out the "See Also" stuff.

Duoas 1,025 Postaholic Featured Poster

You can, but why would you want to if you can avoid it?

Duoas 1,025 Postaholic Featured Poster

Your procedure should be named something like FormShow.

Then, either in the IDE using the Object Inspector (or whatever M$ calls it) or in the FormCreate function set the OnShow property to the FormShow procedure.

Duoas 1,025 Postaholic Featured Poster

With what I've given you already you should be able to do it yourself. I know it is tough at first but the functions are all so similar that you can do it.

Duoas 1,025 Postaholic Featured Poster

Typically, your window isn't actually destroyed, it is only hidden. Hence, when you ask to show it again nothing has changed. You will need to add an OnShow event handler to reload your combobox whenever the form is displayed.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Yes, essentially.

I'm surprised your IDE doesn't do this for you already. What are you using? VC++? BC++Builder?

Duoas 1,025 Postaholic Featured Poster

Wait a second or two before pressing ENTER again. If you want milliseconds, take a look at the DecodeTime procedure. (Please read the thread I posted.)

Duoas 1,025 Postaholic Featured Poster

This should get you started.

Please note that I've never used Borland C++ Builder, I don't have it, and I have not tested this code.

I only translated the EBitmapError class and the RotateScanline90 function set.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

The typical way to handle this is to create a hidden parent window for the whole application. All other top-level windows are children of this parent window, so no extra taskbar buttons are created for them.

To quote the MS docs under Visibility of Taskbar Buttons

A taskbar button is placed on the taskbar whenever an application creates a unowned primary window. To ensure that the window button is placed on the taskbar, create the window by calling CreateWindowEx and include the WS_EX_APPWINDOW style. To prevent the window button from being placed on the taskbar, create the window by calling CreateWindowEx and include the WS_EX_TOOLWINDOW style. As an alternative, you can create a hidden window and make it the owner of your primary window.

The window button typically contains the application icon and title. However, if the application does not contain a window menu, the window button is created without the icon.

If you want your application to display a message to the user while its window is not active, use the FlashWindow function to let the user know that a message is waiting. This function flashes the window button. Once the user clicks the window button to activate the window, your application can display the message.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You might want to tell your compiler to produce MIPS assembly output for your code. If you are using GCC you can use the -S option. If you are compiling on a machine other than a MIPS processor, you will have to use a GCC that has cross-compiler capabilities and use the -march and -b options.

This would give you a good idea of how such a routine would normally look in assembly.

You might also just want to code it yourself. Have you ever programmed in assembly before?

Duoas 1,025 Postaholic Featured Poster

Yes, but you need to know something about how to create components and interfaces.

I think this page on About.com should get you started.

It is possible someone already wrote a Delphi interface unit for the COM object you want to use. I would spend a little time on Google before writing my own stuff.

Good Luck.

Duoas 1,025 Postaholic Featured Poster

My apologies, I use D5 which has all the date functions in the System unit. The correct unit you need is DateUtils. (You could have learned this by placing the cursor on the timeToStr function and pressing F1.) The compile errors are also very specific about exactly where the error occurs. Click on the error in the Message Window and press F1 for more detailed information.

You might also want to take a look at this thread: Tutorial: Handling Dates and Time in Delphi.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Sorry to say, no one here is going to give you code.

Frankly, if you plan to write a report on how to improve code, you need to have a pretty good idea of how the code is generally implemented to begin with. You should be able to write it in your sleep.

I recommend spending some time on Google and finding at a bare minimum two different methods of doing a non-recursive binary search. Study them (if they are not in MIPS, pick your favorite one and convert it to MIPS) and figure out their strengths and flaws.

You might also want to spend some time over at the Wikipedia. The article there is very complete.

Be sure to list everything you find in your references.

Good luck.

Duoas 1,025 Postaholic Featured Poster

I still have no idea why you are having the operand size conflicts. This is what Microsoft has to say about it.

The AX is implied in MUL operands, so the third instruction should read mul num2 Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Usually you will have yourself a little function that takes a specific number of bits (let's say just one bit at a time for each branch in the tree).

The function will modify a static "bits" variable (say, one byte) by shifting in the new bit, and incrementing another static "count" variable that keeps track of the number of bits stored in the byte. Once the counter hits eight (for one byte == eight bits), the byte is written to the output stream, and the "bits" and "count" variables are reset to zero.

You will also need a "final" function that flushes bits remaining when your huffman stream doesn't produce a multiple of eight bits (since the last byte won't be completely filled, but it must still be output).

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Both are variations on the same thing.

First off, each time you [B]readln([/B]key[B]);[/B] you change the value of key. So if you ask for it three times, it will only be whatever you entered the third time.

I would recommend just forgetting the key and asking the user to press ENTER for each thing.

{$apptype console}
uses SysUtils, DateTime;
begin
writeln( 'Petrol Pumper' );

write( 'Press ENTER to start fueling ' );
readln;
start_time := time;

write( 'Press ENTER to stop fueling ' );
readln;
stop_time := time;

write( 'The total time you spent fueling is ' );
write( timeToStr( stop_time -start_time ) );
writeln( '.' );

end.

You will probably want to convert the time spent fueling into the amount of fuel dispensed, and then calculate a price?

Hope this makes things clearer for you.

Don't clear the screen for this type of console program. It isn't worth the trouble.

Duoas 1,025 Postaholic Featured Poster

No, shinchan, we won't do your homework for you. If your professor has asked you to do something with tools he has not taught you, go see the department chair or the ombudsman. Otherwise, if you haven't paid enough attention in class to pass the assignment then you are going to fail it. Sorry.

If you try to do it, and post here with what you have got, and where it goes wrong, etc. we will help you.

Duoas 1,025 Postaholic Featured Poster

It sounds like your teacher wants you to use a brute-force method. Just loop an integer from 1 to n and check to see if it divides evenly into your number. If it does, then it is a factor.

Your choice of n can be interesting.

Duoas 1,025 Postaholic Featured Poster

The best way to learn actually is to try to do it yourself.

A good reference is always a very useful help. I refer to these two often:
C/C++ Reference (short and sweet)
cplusplus.com (all the gory details)

Start small, add on details as you go, and you'll be able to do much more complicated things in short order.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You should be using unsigned long, not double.

In either case, VC++ could have a problem correctly identifying the size of the operand inside the __asm block. I don't know enough about VC++ __asm to be sure, though...

It might be worth pointing your professor to MASM32.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Yes. AH and AL are 8-bits. AX is 16-bits. EAX is 32 bits.

Duoas 1,025 Postaholic Featured Poster

Nand isn't a single operation. How is nand defined? That will give you your answer.

If you are using x86 assembly, look at the and and not instructions. If you are using MIPS, you'll have to think just a little harder: and and xor.

Good luck.

Duoas 1,025 Postaholic Featured Poster

A begin is implied in the body of a lambda.

The problem is that you have to be extra careful to keep data and code separate in scheme. You are mixing the two.

For example, the following is not a valid program: (1 2 3 4) but it is valid data: '(1 2 3 4) Essentially, your update function body at some point evaluates to ('() '()) ...which is not a valid program.

Again, I have yet to re-install PLT so I can't be sure (it has been a few years since I've used scheme much), but you might fix it by simply changing your letrecs to use the following if inside: (if (not (null? lst)) That way, the result is nothing, rather than an empty list.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I believe the largest value that your code can generate is 499 :D

Yoinks! Half asleep math again!

Sorry :$

Duoas 1,025 Postaholic Featured Poster

No, Qt is most decidedly a C++ toolkit. You cannot use it with C.

Duoas 1,025 Postaholic Featured Poster

Glad to hear you've got it working for you.

Don't feel bad when people don't reply. A lot of times it is just that no one knows how to answer your question...

Duoas 1,025 Postaholic Featured Poster

The same problem?

I see nothing wrong with your code... (I can't test it myself ATM, as I'm just recovering from a system wipe and have yet to reinstall scheme.)

Do you think it might be barfing because upgraph evaluates to '() ?

Duoas 1,025 Postaholic Featured Poster

That's because of the way the STL works. The Predicate object must either be a pointer to a static function or an object with an appropriate operator() overload.

Hence, you can do it one of three ways (well, two, but it looks like three):

#include <algorithm>
#include <iostream>
#include <vector>

struct fooey {
  int x;
  fooey(): x( 0 ) { }
  fooey( int _x ): x( _x ) { }

  // method 1: class operator overload
  bool operator () ( fooey x ) { return x.x == 0; }

  // method 2: static function (version 1)
  static bool pred( fooey x ) { return x.x == 1; }
  };

// method 2: static function (version 2)
bool pred( fooey x ) { return x.x == 2; }

int main() {
  using namespace std;

  // Fill our vector with 0 1 2 3 0 1 2 3 0 1 2 3 ...
  vector<fooey> xs;
  for (int i = 0; i < 20; i++) xs.push_back( fooey( i %4 ) );

  // Display the vector
  for (int i = 0; i < xs.size(); i++) cout << xs[i].x << ' ';
  cout << endl;

  // Remove all zeroes and display
  xs.erase(
    remove_if( xs.begin(), xs.end(), fooey() ),
    xs.end()
    );
  for (int i = 0; i < xs.size(); i++) cout << xs[i].x << ' ';
  cout << endl;

  // Remove all ones and display
  xs.erase(
    remove_if( xs.begin(), xs.end(), fooey::pred ),
    xs.end()
    );
  for (int i = 0; i < xs.size(); i++) cout << xs[i].x …
Duoas 1,025 Postaholic Featured Poster

Remember, of course, that in C++ everything is zero-based. So Value[1][10] is the second row and the eleventh column.

A vector, as Jennifer84 demonstrates, is a superior construct, since you get all the benefits of an array without any of the drawbacks.

[EDIT] Oh yeah, almost forgot to answer your Q. A vector is a "container class" in the STL. Read what the C++ FAQ has to say about it here.

Duoas 1,025 Postaholic Featured Poster

Since no one else has responded, I'll throw in my $0.02, which isn't worth much when dealing with MFC.

How are you allocating the data? Is it all at once (in one big chunk)? The computer can't handle that. Make sure you allocate in fragments.

Personally, I don't think you should need to allocate all the information at one time. Allocate a small chunk (say, 10..30 rows, or whatever), fill them in, send them to output, rinse and repeat.

If I understand you correctly, your program produces an HTML file that is displayed to the user, right? If it is an issue of using more than one table to display the data or not, don't worry about it. The user will have no clue if you use more than one table. Just make sure to place them all in a single DIV or something so that they are consecutively selectable...

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

At the top of your main program (the .hsx file) you should have something like:

module MyProg where

import Char

In this example I named my .hsx file "MyProg.hsx" but you can name it whatever you like. Make sure to import every library you need. The isDigit function is in the Char module of the Prelude.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

That shouldn't work at all. Both upgraph and downgraph are defined to take a single argument, but you are passing multiple...

That could be the problem. Make sure also that you aren't calling bitset with '().

Sorry I can't be of more help.

Duoas 1,025 Postaholic Featured Poster

I also hear rave reviews about FLTK, though I've never used it myself. I like Qt, but you can't sell anything you develop with it... (unless you can afford to purchase a developer license, that is).

Duoas 1,025 Postaholic Featured Poster

rand() returns a value between 0 and RAND_MAX.

You need to apply some math to bound that value. In C++, the remainder operator is %. int value = (rand() % 499) +1;

Duoas 1,025 Postaholic Featured Poster

A better approach might be to create a package installer (such as a .deb or .rpm) which lists python as a dependency.

If you plan to support more linux variants than just RedHat and Debian and those that work with their package systems (which are quite a few!), you can roll your own using a program like makeself.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Since no one else is responding, I'll offer my meager bone.

How is Delphi involved here? Did you use Delphi to do the FTPing? Or are you using Delphi to try to start the jpg, exe, etc.? What filesystem is the file sitting on (NTFS, FAT, EXT2/3, Reiser FS, IBM JFS)?

Duoas 1,025 Postaholic Featured Poster

In particular, both Gnome and KDE are able to be used as application frameworks.

GTK+ is a very common, very complete toolkit with C API bindings.

Most others I know of are C++...

You can also take a gander through The GUI Toolkit, Framework Page.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Your description to us is so vague that we can't really help.

How exactly does your professor expect you to display a bmp? Did he provide the bmps to display? Are you using the Windows API or some other GUI framework?

What sort of calculations are you doing? What does the input text file look like?

Duoas 1,025 Postaholic Featured Poster
Duoas 1,025 Postaholic Featured Poster

It keeps the program from crashing on bad input.

Read up on exceptions. The first two links here on google are very good.

Whenever you use a function like strToInt or strToFloat (conversion routines), or any kind of I/O routine, put your cursor on the name of the procedure and press F1, then read what exceptions may be raised when the conversion or I/O or whatever fails. Then use a try..except block so to catch the exception and do something more intelligent than simply terminate the program.

You never know what a user will type when given the chance, so it is always best to make sure the program can continue even if the user types something really idiotic. The example I gave you catches bad input by complaining with a message dialog, focusing the input box, and exiting the routine to wait for the user to try again.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Sorry, I've no idea what else to try.

Duoas 1,025 Postaholic Featured Poster

Try entering a price per litre of "abc" and pressing the button. Without the try...except block, your program would crash.

Duoas 1,025 Postaholic Featured Poster
Duoas 1,025 Postaholic Featured Poster

Since PriceLitre is in pounds sterling (but displayed in pence), I just adjusted the math in the program to convert behind the scenes.

try
    // convert to pence (string) to pounds (real)
    PriceLitre := StrToFloat( PriceLitreedt.text ) /100;
  except on EConvertError do
    ...  // (stuff you already have is omitted here)
  end;

  ... // (stuff you already have is omitted here)

  // Convert the validated pounds sterling to a string
  // representing pence and tenths-pence
  PriceLitreStr := FormatFloat( '000.0', PriceLitre *100 );

  // Load the images
  Img15.picture.loadfromfile( PriceLitreStr[1] +'.bmp' );
  ...

A case statement is just a selector returning a single item. There is no iteration involved...

Your program produces the animation by changing all the numbers once per timer timeout.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Yeah, we've already discussed this. I've already replaced his big case statements with a single line of code each...

The best fix is to have an array of bitmaps (obtained either from hidden images on the form, or from resource, or by using a TImageList), and assigning the image as appropriate.

Duoas 1,025 Postaholic Featured Poster

So wait, did you get the "undeclared" error fixed (by typing isZero as) bool isZero( term t ) ?

Glad to have been of help.

orangejuice2005 commented: Thanks a lot Duoas! Good looking out +1
Duoas 1,025 Postaholic Featured Poster

Ah, I get it. So the price is listed in pence, not pounds sterling.

Yes, they use the same daft trick here in the USA. You get 104.9 (in pence) and we get 1.049 (in dollars). The decimal point is just put in a different spot since the units differ.

You'll have to update your code to obtain and display the price per litre in pence, then divide by 100 to get the price per litre in pounds. If it gives you trouble let me know.

(Take your time in thinking about what units each of your variables represents: Litres, ThisSale, and PriceLitre.)

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Alas, I've never played with MFC.

I wonder if you wanted a vector of System::String? std::vector<[B]S[/B]tring> Value(10); (Case matters.)