Duoas 1,025 Postaholic Featured Poster

What medium do you want to draw it on...

Duoas 1,025 Postaholic Featured Poster

As this is C++, why don't you use C++?

Also, never use gets().

The reason you are failing is that charname will never == chartryname, since both are pointers and both point to different locations. If you use the std::string class, the == operators are overloaded so that you can use == the way you think it ought to be working...

#include <iostream>
#include <string>

#include <cstdlib>  // for system(), alas.

using namespace std;

int main()
{
  string name, password, tryname, trypassword;
  int numtrys;

  cout << "Please enter a user name to setup ";
  getline( cin, name );

  cout << "Pleae enter a password to setup ";
  getline( cin, password );

  system( "cls" );  // there are better ways to do this...

  for (numtrys = 0; numtrys < 3; numtrys++)
  {
    cout<<"You have 3 attempts"<<endl;
    cout<<"This is attempt number "<<numtrys<<endl;

    cout<<"Please enter your user name ";
    getline( tryname );

    cout << "Please enter your password ";
    getline( trypassword );

    if ((tryname == name) and (trypassword == password))
    {
      cout<<"\t The details you entered are correct "<<endl;
      break;
    }
    else
      cout<<"\t The details you entered are incorrect "<<endl;
  }

  if (numtrys < 3) cout << "yeah!" << endl;

  cout << "Press ENTER to continue...";
  cin.ignore( numeric_limits<streamsize>::max(), '\n' );

  return EXIT_SUCCESS;
}

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

It isn't complaining about the std::vector class, but the string class, which doesn't exist.

Make sure you say: std::vector<std::string> Value(10); Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Perhaps we should ask: what do you mean by a "table for matrix"? And on what medium do you want to draw it (console, gui window, printer paper)?

Duoas 1,025 Postaholic Featured Poster

OK, I've looked it over and made some fixes.

Your first problem was that you had the timer interval set to 1 millisecond. That's too fast. I bumped it up to a half-second.

You should avoid using more than one timer for the same event. I removed the second timer and combined the timer1timer and timer2timer procedures.

The second problem has to do with handling your data and converting between string and number. Check out the code for commentary on that.

I would recommend that you fix the TfrmPump.Litres to be a real value... or rename it to match its value (like TenthsOfLitre).

I fixed your forms to center themselves on the screen, and adjusted the text layout a little on the main form (so that it centers itself automatically). Oh yeah, I also changed text color to white so I could read it...

Lastly, your main form uses a non-standard font. My XP just recently crashed and I restored it from a backup image, so at the moment I don't have any fonts other than Microsoft defaults. Generally, if you must use a non-standard font for titles, use an image instead.

Some suggestions:

Don't use globals if you can avoid it. I notice you've got buttons to lift and seat the pump handle. Make yourself a boolean variable and stick it in the class definition (where I moved your Litres and ThisSale variables). Then, in the timer1timer procedure start off with: …

Duoas 1,025 Postaholic Featured Poster

Got it. Check back in a short bit.

Duoas 1,025 Postaholic Featured Poster

An access violation occurs when you try to access memory that doesn't belong to you.

You need to think a little more carefully about what you are doing with all those variables.

For starters, only mess with one linked list at a time. Also, make sure to get out a piece of paper, draw yourself some variable names and draw little arrows over to little boxes for each node (each node should also have a couple variable names in it: one for the char and one for the next pointer).

Use pencil so you can erase arrows and add and remove things.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

It isn't C++ that's buffered, it is the device you are reading. C++ doesn't care either way. When the standard input is from the keyboard, it is buffered. If it is redirected from, say, a file, it is not buffered. (By "buffered" of course I mean "line-buffered".) Either way it should not affect the functioning of your program (that is, this thread's specific program, as well as most other C++ homework style programs.)

I am an advocate of the "get everything from the user using getline()" way of thinking.
Interactively (that is, when line-buffered), the user enters everything one line at a time.
Non-interactively (that is, when piping from a file or other stream device), the input is still read one line at a time. Therefore, since all input is expected one line at a time no matter what, just read input one line at a time.

Once you have a line from the user, you can test/convert/whatever it and more gracefully recover from input errors. However, this involves a little bit of overhead. You could also just test the fail and bad bits after trying to read input, and pay attention to those unread characters that Lerner talked about.

cin >> sex;
cin.ignore( numeric_limits<streamsize>::max(), '\n' );

This code assumes that the user entered correct input for at least the first non-whitespace character on the line, removes anything else on the line and continues happily.

Argh.

Duoas 1,025 Postaholic Featured Poster

Are you using a global or local hook?

If global, it is possible that IE installs a global hook on "https://" pages that blocks the rest of the hook chain. The only way around that would be to install your hook after IE opens the https page, and I don't know how you'd query to know every time IE installs/uninstalls said hook.

Duoas 1,025 Postaholic Featured Poster

I can't do anything with that. Go into your project directory. Delete all the binary files (exe and dcu), then zip up everything else and attach it to an email. At the very least I need the dfm files for unit2 and unit3.

Duoas 1,025 Postaholic Featured Poster

I don't know that any one toolkit is "easy". GUI stuff is fairly involved --there is a distinct learning curve.

I would recommend finding an IDE that can setup a basic GUI project for you and help you out.

The GUI Toolkit, Framework Page.

Duoas 1,025 Postaholic Featured Poster

The problem is essentially this:

vector<term>::iterator p5Current = result.poly.begin();
result.poly.erase( p5Current );
p5Current++;  // <-- this throws an error

Once you erase an element, you cannot operate on it. Since *p5Current no longer exists, it makes no sense to increment to the next one...

You'll have to think a little bit about how to solve this. (If you feel comfortable with the <algorithm> template functions, you might want to take a look at remove_if. However, you can easily do it without using the algorithms remove_if() template function...)

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

That's a nice catch. (I thought I tested for that...)

I fixed it by using a temporary. I replaced the line

if (stream.peek() != 'x') stream >> t.co;

with

if (stream.peek() != 'x')
{
	int sign = t.co; // save the current sign (1 or -1)
	stream >> t.co;  // get the coefficent absolute value
	t.co *= sign;    // restore the sign
}

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Post your operator>> code, and which line is giving you trouble.

Duoas 1,025 Postaholic Featured Poster

So your card is actually a separate window?

If it is just the problem of dragging the card across different components on a single form, you can use a TPaintBox (found in the System tab of the components palette) to draw on the form directly. Then you could avoid using a separate window and window regions...

Duoas 1,025 Postaholic Featured Poster

My PM is magically filled with 2701 messages. I stopped trying to clear them a while ago (it only lets you delete 25 at a time), and I can't seem to raise Dani from normal email...

Send it to me at michael.thomas.greer at google mail.

Duoas 1,025 Postaholic Featured Poster

I'm afraid not. I'm still in the dark ages...

Explain your problem in terms of what you would like to see and what you are actually seeing, and give a specific example.

For example:
Each time the price changes it should say
000.00
001.99
003.98
etc. but what I am seeing is
000.00
999.99
784.32
...

Duoas 1,025 Postaholic Featured Poster

Look, I'm sorry I didn't go back and re-read your posts before preaching to the choir. All you have to say is "I understand ^ and ** and polys."

What you are failing to grasp is sprawled all over pages 1 through 4 of this thread. It is fine if you want to jump in late but if you are then told "you've missed something" then you have probably missed something.

The purpose of using a programming language is to deal with abstractions. There is nothing magical about it. The last three or four posts OP and I made dealt explicitly with the "special function" of turning adjacent like terms into a single term, for every term in the list. Notation has absolutely no effect on the operation.

I can just give the OP code. But I won't. I want him to write it himself. (He can do it just fine and he'll be happier with the result.) What he is struggling with is how to arrange his data to do the reduction. This requires abstract thought over what is happening to the terms of the polynomial.

What you are struggling with is already a solved point. (Check out the operator>> and the Polynomial class's data structure.)

Sorry if I upset you.

Duoas 1,025 Postaholic Featured Poster

You can't use the ++ operator like that.

You can, however, use it like this:

...iterator i1, i2;

  for (i1 = result.poly.begin(); i1 != result.poly.end(); i1++)
  {
    i2 = i1 +1;  // the next term, if any

    if (i2 == result.poly.end()) break;  // if there isn't any next term, you are done anyway...

    if (i1->expo == i2->expo)
    {
      i1->co += i2->co;  // add the terms
      result.poly.erase( i2 ); // erase the next term
    }
  }

I think that should work.
You could also just use integer indices, as in result.poly[i].expo and the like.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Ah, you're beyond me there. It is a feature of the microchip. The x86 Protected Mode is used to protect programs from accessing things they shouldn't. Earlier chips didn't have this feature, and that's why DOS programs could do whatever they wanted.

In other words, it is built into the hardware.

I know nothing more than that. Sorry.

Duoas 1,025 Postaholic Featured Poster

Hah hah hah.... whew...

lazy punks at M$

Another reason why I won't switch to vista...

Duoas 1,025 Postaholic Featured Poster

Yes, you are confused because you are mixing C++ and the OP's syntax for a polynomial. They are distinct things.

In textual representations, both x^y and x**y are common to mean "raise x to the power of y". This has absolutely nothing to do with C++.

A term is a multiplicative value. Hence, 4x is "4 times whatever 'x' is". You can add like terms (that is, terms with the same power of x) easily: 4x + 2x = 6x But unlike powers cannot be added: x**2 + x = ??? Three oranges and two oranges are five oranges, but three oranges and two apples are still three oranges and two apples no matter how you look at it.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Well, as no one else is responding...

I'm not going to spend a lot of time looking through the Indy 10 documentation (which is fairly massive) and I don't know that much about FTP.

Are you transferring in binary mode?

You should try to catch the exact exceptions raised on errors.

The ftp.disconnect; should be after the except..end block, so that you are sure to disconnect even if an exception does occur. (It is OK to call disconnect if you are not connected.)

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Why are you dividing the number of liters by 10?

Don't say string[5]. Just use string.

You haven't yet explained exactly what is wrong, so I don't know what better to say... Does this help?

Duoas 1,025 Postaholic Featured Poster

Regions are for windows. Not for painting.

You should be able to set the transparent and transparentColor properties of the bitmap before drawing it in your paint procedure.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

It depends. In MAL and TAL: no, it is not legal (the second item must also be a register). In SAL, sure.

Duoas 1,025 Postaholic Featured Poster

You only need to traverse the list once. Set your "current max" to the first element in the list. For the remaining elements of the list, test each one against the "current max". If greater, set the "current max" to the current element.

[edit] Removed. I was still on x86 opcodes from the last question... [/edit]

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

It has nothing to do with Intel. Every OS must allocate and initialize memory for programs, no matter what chipset you are using. When the OS places your program into memory, it places the various parts in the proper places: Code goes in one place, Data goes in another, and the Stack in another. The OS then sets the computer's IP (code pointer), DP (data pointer), and SP (stack pointer) registers to address the proper memory locations.

On Intel x86, the stack grows towards low memory, and the SP points to the last used element.

So, to push a value (say, in ax) on the stack would be akin to dec esp mov [sp], ax (this is what push ax does internally)

Then to pop a value: mov ax, [sp] inc sp (this is what pop ax does internally)

This arrangement is not universal. Other architectures vary.
Hope this helps.

Duoas 1,025 Postaholic Featured Poster

No, I mean ntvdm.

Notwithstanding, I don't have Vista and after reading some more on the internet it seems that Vista 32 does still have a working 16-bit emulator... (I think!) but Vista 64 does not.

In either case, Vista will be very hostile towards your 16-bit fullscreen application, so it is a good idea to get a good VM like DOSbox.

[EDIT] Re-reading the OP's original post, do you mean to say that pressing Alt-Enter in the command prompt doesn't switch you to a pure text-mode on the monitor?

Duoas 1,025 Postaholic Featured Poster

JRM, please take the time to read the whole thread before jumping to conclusions. His polynomial is expressed as a vector of terms. Each term is composed of a coefficient and an exponent.

orangejuice2005
Why don't you use your sort() method? p3.sort(); Then, all the terms with the same exponent will be adjacent. For example, 4x^2 -3x -6 +9x^3 -2x^2 +7 becomes 9x^3 +4x^2 -2x^2 -3x -6 +7 Terms with like exponents: 9x^3 + (4x^2 -2x^2) -3x +(-6 +7) Combining them is just addition and subtraction of the coefficients: 9x^3 +2x^2 -3x +1 1. After the sorting, just loop through the terms.
2. Inside that loop, check to see if the next term (if any) has the same exponent. If so,
combine (add) the terms. Loop until the next term has a different exponent or you reach the end.
3. Continue with the outer loop until all done.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I don't know how to use COM in VB... Sorry.

I think that you can go to the installed components dialogue and requisition it... (but again, I haven't seen VB in years).

Duoas 1,025 Postaholic Featured Poster

WaltP, why the vitrol? I've already make my opinion known that I think Narue's was fine to begin with...

By "all" I mean the number of bits required in the domain. Narue's assumes every bit possible in a machine word, and relies upon the compiler to properly handle conversion to other integer types. My original version only considered bits terminated by 1 Either interpretation may be correct depending on the problem domain.

A "perfect" solution would take the bit-domain as argument, and work against that.

Whenever you (or anyone) find yourself spouting off about the one true way of looking at things you almost always make yourself automatically wrong. The closest thing the OP said about his operational domain was to refer to MSB and LSB... So where, exactly, is MSB? It makes a significant difference!

Duoas 1,025 Postaholic Featured Poster

Coding is the process whereby you take a complicated task and break it down into simpler tasks. If you can't make it so simple you feel a two-year-old could have written it, then you are thinking too hard.

Personally, I would have my operator+ just concatenate the addend to the augend, then use the sort() method to arrange things in order and then join like powers...

Duoas 1,025 Postaholic Featured Poster

Vista no longer supports the DOS subsystem. You'll have to find another VM (like DOSbox) to run 16-bit programs.

Duoas 1,025 Postaholic Featured Poster

That's because you didn't replace lines 17..18 with lines 20..25, as I indicated.

That should fix it. As a note, however, separating line 38 from 34 introduces the possibility to read incorrect input. Here's my take:

istream& operator>> (istream& stream, Polynomial& pnomial)
{
	term t;
	pnomial.poly.clear();
	while (stream)
	{
		stream >> ws;

		if (stream.peek() == ';')
		{
			stream.get();
			break;
		}

		t.co = 1;
		if (stream.peek() == '+') stream.get();
		else if (stream.peek() == '-') {
			t.co = -1;
			stream.get();
		}
		stream >> ws;

		if (stream.peek() != 'x') stream >> t.co;

		if (stream.peek() == 'x')
		{
			stream >> t.var;
			stream >> ws;

			if (stream.peek() == '^')
			{
				stream.get();
				stream >> t.expo;
			}
			else t.expo = 1;
		}
		else t.expo = 0;

		pnomial.poly.push_back( t );
	}
}

Notice how I get to line 30 only if there is an 'x' read. (That way, you can't have "12^3" as a term.)

Keep in mind that neither of our codes are perfect (and could use some significant work) but they do the job on correct input. Which is probably good enough for your professor.

Don't just copy my code into your project. Make sure you know what you are doing (I think you do have a pretty good idea, though).

The next trick is to fix your output to display a polynomial correctly. Just as you did with the input (which I feel justified having helped you so much, since input is tricky) you should start by making an output …

Duoas 1,025 Postaholic Featured Poster

> As my case in point, your function is woefully broken in that it completely fails to do what it's supposed to do, which is reverse all of the bits. (emphasis added)

Well, that depends entirely on what you mean by "all".

> It doesn't work because in your quest for simplicity, you fail to take leading unset bits into account, when in the reversal they become critical.

Yes, of course, you are right. So then:

unsigned long reverse_bits( unsigned long value )
{
  unsigned long result = 0;
  size_t n = NBITS( value );

  while (value)
  {
    result <<= 1;
    result += value & 1;
    value >>= 1;
    n--;
    }

  return result << n;
  }

Before complaining too loudly you should have noticed that my algorithm and yours are nearly identical.


[EDIT] BTW. I almost just told everyone to read your algorithm again... I should have, instead of hacking in that "forgets the leading zeros" one.[/EDIT]

Duoas 1,025 Postaholic Featured Poster

That's because commands in the cwd are not in the PATH by default on Linux/Unix.

Type ./a.out Enjoy!

Duoas 1,025 Postaholic Featured Poster

It's a DLL. ;) %SystemRoot%\system32\shimgvw.dll Check out this thread I googled.

Duoas 1,025 Postaholic Featured Poster

Yoinks people! Always the hard way!

unsigned long reverse_bits( unsigned long value )
{
  unsigned long result = 0;

  while (value)
  {
    result <<= 1;
    result += value & 1;
    value >>= 1;
  }

  return result;
}
Duoas 1,025 Postaholic Featured Poster

You could also use the StrOfChar function in the SysUtils unit.

function make_filename( i: integer ): string;
  begin
  result := '';
  if (i < 0) or (i > 999) then exit;

  result := intToStr( i );
  result := 'image' +strOfChar( '0', 3 -length( result ) ) +result
  end;

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Well, seeing as we've lost the OP anyway, I hope you are laughing and not suggesting you have a firmer grasp of English grammar than I...

Because if you are just laughing you know already that the word "and" is only used to conjoin similar clauses and does not have any effect upon the exact, technical relationship (if any) between those clauses...

But again, seeing as this thread has permanently disintegrated into silly answers, I accept your joke.

Duoas 1,025 Postaholic Featured Poster

Actually, your program has a few I/O errors that I'm sorry to say I didn't catch earlier. I'll list them all here for you though.

Polymain.cpp: line 15
Just as a personal stylistic preference, I'd add a single space after the prompt, as: cout<<"Enter selection> "; This isn't a bug, though. Just style. :)

1. Polymain.cpp: lines 44, 47
User input should generally be done on a line-by-line basis (that is, input an entire line as a string, then parse the string) but C++ lends itself to professors having you learn UI with the >> and << operators of the cin and cout streams. These operators do what they are supposed to do, but a one-sided education in their use produces some very bad and buggy I/O programs.

On the line indicated, you have the user input an integer. That's fine (unless the user inputs, say 'a'). I'll defer lecturing to the optional part at the end of my post and just fix egregious errors here.

After inputting the integer there remains a newline sitting in the input stream. The user had to press ENTER to send the number to the program, so we really do need to remove the newline before continuing. (That way the newline doesn't contaminate more input --which it does in your program, btw.) Best to avoid the possibility of error either way. Change line 44 to read:

cin>>choice;
	  cin.ignore( numeric_limits<streamsize>::max(), '\n' );

The same problem occurs on what …

John A commented: Good work. I'm too lazy to do that much correction. :) +13
Duoas 1,025 Postaholic Featured Poster

Yes, but not all numbers divisible by two or three are divisible by six.

Duoas 1,025 Postaholic Featured Poster

When you are using an IDE, the options are usually (as they are in your case) to create either a DLL or an EXE. You can't create both in the same project.

Start a DLL project to make your DLL. Make the DLL.

Then start an normal application project. #include the .h from the DLL project. Make and run the EXE.

A DLL is not designed to be executed like an EXE --the entry point (if any) is different and different operating constraints apply. I think you need to read up a little more on the difference between a DLL and an EXE.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Arg, I don't know anything about Dev-C++ and it's auto-generated makefiles.

If you compile the program from the command prompt using the commands I gave you, it should work fine.

Once you do that, go back and figure out how to make the IDE do it.

Duoas 1,025 Postaholic Featured Poster

The answer is no.

Not even Tcl is installed by default on all flavors of linux. About the only thing you can guarantee is that either /usr/bin/sh or /bin/sh is available. (And on most linuxes it is actually bash.)

You can, of course, make your install and/or start script(s) test for python and complain with a user-friendly "please install python" message if not found.

Duoas 1,025 Postaholic Featured Poster

The only GUI toolkit built-in to Python is Tk. (And Tcl/Tk most definitely does work on the iPod!)

I know next to nothing about the iPod. Is it an embedded OS?

In any case, it is certainly possible to make a single program that does python/tk, but you will likely have to hack python yourself to do it. Since you've got both libraries, I'm not sure what the problem is. Distribution, maybe?

(Oh, yeah, I'd say go with Tcl, but I don't think the footprint would be prohibitive to go with Python. But then again, I know next to nothing about the iPod...)

Duoas 1,025 Postaholic Featured Poster

You've compiled the code, but you still haven't linked it into DLL and lib files.
Make them with g++ -shared -o dlltest.dll dlltest.o -Wl,--out-implib,libdlltest.a This creates both the DLL and an import library. If all you want is the DLL, ignore the stuff that isn't in red. (That's a -W and lower-case L.)

See this link for more.

Good luck.

Duoas 1,025 Postaholic Featured Poster

Make sure to check the GraphResult variable after calling InitGraph.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You have to use the InitGraph procedure before you can use anything else in the Graph unit.