Duoas 1,025 Postaholic Featured Poster

There's no need for the angry attitude or to get all defensive. I have far more experience than you and, whether you believe it or not, a greater understanding of your problem than you do.

At no point have I given you incorrect code --all the code I supplied works fine. The problem lies in your understanding.

May I ask how it is that you have written so much code that it would take an enormous amount of time to switch to a TListBox (which, you will note, I have not required you to do), without understanding the basic concepts central to programming? At no point have I written anything in any post of mine which does not directly apply to your efforts. Don't just skip over stuff you don't understand because you think it has no bearing.

You are perfectly capable of working with what I have given you. It is neither over your head nor is it smarter than you. You must, if you intend to continue working with Delphi, learn how to lookup information about the VCL with the Delphi help system, and you must understand how to create and use procedures and functions, and you must understand how the type of a thing affects the code used to manipulate it. Failing these things you will remain stuck.

It is time now to put a little effort into learning something about these things instead of demanding that I or anyone else simply give …

Duoas 1,025 Postaholic Featured Poster

Personally, my preference agrees with yours.

However, when the pascal specification says that identifiers are not case-sensitive I feel that the word always is correct and justifiable. If you ever find a pascal compiler that complains about case-sensitivity then it is not valid (i.e. standard) pascal.

Duoas 1,025 Postaholic Featured Poster

I'd like to help more but at this point you aren't paying attention. I've given you all the code you need --which is much more than I usually do. You have to use your brain now and use the code I've given you correctly.

Duoas 1,025 Postaholic Featured Poster

No Pascal compiler is case-sensitive. Pascal is explicitly case-insensitive.

Duoas 1,025 Postaholic Featured Poster

Alright. Here's a SaveNLines that takes a TListItems.

procedure saveNLines(
  filename:  string;
  var items: tListItems;
  startAt:   integer;
  numLines:  integer
  );
  var
    sl:   tStringList;
    b, e: integer;
  begin
  // Our temporary string list
  sl := tStringList.create;
  // indices of lines to copy, inclusive
  b  := startAt;
  e  := startAt + numLines -1;
  if e >= items.count then e := items.count -1;
  // copy the indexed lines into our temporary string list
  for b := b to e do
    sl.append( items.item[ b ].caption );
  // save the lines to file
  sl.saveToFile( filename );
  // cleanup
  sl.free
  end;

Notice that nothing other than each item's caption is saved to file.

Sorry for the confusion. P.S. I haven't tested this code. It might need a tweak here or there.

squidd commented: a great help to me +1
Duoas 1,025 Postaholic Featured Poster

In OSX just open a command-line window and type gcc or g++ to use the compiler.

For example, if you have a program source file "palindrome.cpp" then type g++ palindrome.cpp -o palindrome to compile the program. Type palindrome to run the program. You must, of course, be in the same directory as the source file.

Your professor won't be interested in the binary. He only wants to see your source code, so you are fine just sending the cpp file over.

Good luck.

Duoas 1,025 Postaholic Featured Poster

That will not work in Linux.

The getpass() function is borrowed directly from <unistd.h>, and is outdated and unreliable.

Use curses.

[EDIT] Heh, too slow again...

Duoas 1,025 Postaholic Featured Poster

I'm not sure...

You should receive an empty message if the server terminates.

Glad to be of help.

Duoas 1,025 Postaholic Featured Poster

(Thanks Ancient Dragon).

In order to check whether an ASCII number is uppercase or lowercase you must decide whether it is greater-than (for lowercase) or less-than (for uppercase) a specific number. You must figure out what that number is. Pay attention on line 22: you test for equality when you should be testing for an inequality (greater-than or less-than). Also pay attention to where you are branching.

Lines 27 and 32: If you want to unconditionally branch you could just say BR Test .

Lines 34,35: It isn't particularly clear, but I think that COMP is supposed to be the number you use to test upper/lower case, and OFFSET is supposed to be the number you add to a lowercase letter to get an uppercase letter. Like your professor noted, be careful of the sign for each one.

Lines 30..32: converting to lowercase. In your main loop, you should be obtaining a letter from the string using LDR. If you change the letter, you should save it back using an instruction like LDR but that works in the opposite direction (register to memory instead of memory to register).

Lines 36..39: You could just say .FILL 't' instead of .FILL #116 . The assembler is at least that smart...

I haven't assembled and tested this myself, but that should cover everything...

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

ithelp
Cheating never helps anyone learn anything. That, and the code output by the GCC won't be as obvious to read as just doing it right to begin with.

eyehategod
You've got the right idea. Just be careful which jump condition you use. All you need to do now is get x and y into registers.

;somehow set ax = x
;somehow set bx = y
cmp ax, bx
jne somewhere_else
  ;do stuff here if ax==bx
somewhere_else:  ;all done

(Yeah! I got assembly highlighting!)

Duoas 1,025 Postaholic Featured Poster

Why are you using getline( cin, ... ); ?
Don't.

Also, your output doesn't quite match the required output... but otherwise everything works fine.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Step by step.

1. Don't fflush(). There is no need and you shouldn't be mixing C and C++ I/O anyway.

2. You are mis-indexing the string: 01234 7+i3 Hence, line[1] == '+' and line[4] == '\0'. BTW, i never reaches 4 if your input is only four characters long.

3. You are not converting your numbers. The ASCII value of '+' is 43.

4. Your constructor should look like this: Complex( int _a=0, int _b=0 ): a( _a ), b( _b ) {}; or Complex( int _a=0, int _b=0 ) { a = _a; b = _b; } The first way is preferred.
The reason num.b is some weird number is because your constructor never initializes the private fields a and b. Having arguments with the same name makes no difference.

PS. Complex numbers are normally written a + bi. If you do the same you will have an easier time collecting and verifying input.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Don't bang your head too hard... you don't want to break it.

Unsatisfied forward or external declaration
You can declare a thing and you can define a thing:

unit fooey;
interface
// Everything in this section is a DECLARATION
function hum( bark: string ): string;

implementation
// Everything this section is a DEFINITION
function hum( bark: string ): string;
  begin
  result := 'Baz says "' + bark + '"'
  end;

end.

An Object Pascal unit requires you to first declare your functions, etc. in the interface section. Then you must use the implementation section to define the thing things you declared. If you do not define it, but only declare it, then you are basically telling the compiler that some function exists when it does not.


The type of things matters
Recall that I previously recommended you to use something other than a TListView? (such as a TListBox)? That is because the items property is a TListItems, not a TStrings. The former is weird and hard to handle. The latter is convenient and easy to handle. Unless you are making a spreadsheet or something you should not be using a TListView.

The procedure I gave you takes a TStrings, not a TListItems. If you insist on using a TListView then you will have to convert your items property into a TStrings object before using the function I gave you. If you don't want to do that either then you will have to get every …

Duoas 1,025 Postaholic Featured Poster

OK, FP is very compatible with Delphi.

Add the Dialogs unit to your uses clause. The procedure that fits your requirement best is the first in this list:

procedure ShowMessage( const msg: string );
function MessageDlg( const msg: string; dlgType: tMsgDlgType; buttons: tMsgDlgButtons; helpctx: longint ): word;
function MessageDlgPos( ... x, y: integer ): word; //same args as MessageDlg
function InputBox( const aCaption, aPrompt, aDefault: string ): string;
function InputQuery( const aCaption, aPrompt: string; var value: string ): boolean;

The ShowMessage function just displays your message with a little OK button.
The MessageDlg displays a message with the desired icon and buttons.
The InputBox and InputQuery functions get a string from the user. The latter returns false if the user canceled.

type TMsgDlgType = (mtWarning, mtError, mtInformation, mtConfirmation, mtCustom);

type TMsgDlgBtn = (mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore, mbAll, mnNoToAll, mbYesToAll, mbHelp);

return values for MessageDlg:
mrNone mrAbort mrYes mrOk mrRetry mrNo mrCancel mrIgnore mrAll

If none of those work for you, create a new form that does what you want and set its border style to bsDialog. Display the form using the ShowModal function. Close the form and return a value by setting its ModalResult.

Good luck.

Duoas 1,025 Postaholic Featured Poster

Which Pascal are you using?

Duoas 1,025 Postaholic Featured Poster

You didn't define save250 the way I gave it to you. The one you defined takes a single argument: a TObject. The one I gave you takes entirely different arguments.

The procedure header should look like this: procedure SaveNLines( filename: string; var strs: tStrings; startAt, numLines: integer ); Please notice how I renamed the procedure from save250 to saveNLines.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Forget the stupid fread64() and fwrite64() functions! Use fread() and fwrite(). Once you have enabled 64-bit access all the usual functions will work with 64-bit files.

Good luck.

Duoas 1,025 Postaholic Featured Poster

That code will not work in unix. The idea to use a loop to get characters is fine, but you will still need to use curses to unbuffer your stdin.

(Besides wish, that code is old and non-standards compliant.)

Duoas 1,025 Postaholic Featured Poster

Yes, the GCC supports it. (It is the glibc that made it possible for most linux platforms.)

Compile with g++ -D_FILE_OFFSET_BITS=64 . See here. This changes all the file I/O to take 64-bit offsets instead of 32-bit.

Good luck.

Duoas 1,025 Postaholic Featured Poster

Ah, I get it. Google "flood fill algorithms".

To get ASCII art to look right just put it in [[I][/I]code[I][/I]] tags:

10x5
  0  1  2  3  4  5  6  7  8  9
0[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
1[ ][X][ ][ ][ ][ ][X][X][X][ ]
2[ ][X][X][ ][ ][ ][X][ ][X][ ]
3[ ][X][X][X][ ][ ][X][X][X][ ]
4[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]

Good luck.

Duoas 1,025 Postaholic Featured Poster

Agreed. If I remember correctly, the curses library actually has a function that does what you want...

Duoas 1,025 Postaholic Featured Poster

A lot of older compilers, particularly windows compilers, let you get away with a lot of stuff.

Before local scoping was put in the standard, what do compilers do with something like for (int i = ... ?

The most flexible answer was simply to pretend that the variable was declared at the beginning of the function.

So, to fix the code, just put int i; at the beginning of the function and change to loop to for (i = ... .

Enjoy... ;)

Duoas 1,025 Postaholic Featured Poster

I think he understands that. In use, however, there is no semantic difference.

Duoas 1,025 Postaholic Featured Poster

I suppose you could, but you really have no valid reason to go dinking around with the standard library. (You'll break all kinds of stuff.)

You still haven't told us what system you are using. Have you looked it up in your system/compiler's documentation?

You are doing non-standard stuff. Even so, that stuff was written to be used a certain way. Less grief comes from doing it the recommended (i.e. documented) way. That is, use the functions given you the way they are supposed to be used.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You are trying to do something like this:

for (int i = 0; i < 12; i++) {
  ...
  }
if (i < 12) ...

The variable i is only supposed to exist inside the for loop. The compiler is complaining about your using it outside the loop.

Salem commented: Exactly +12
Duoas 1,025 Postaholic Featured Poster

That depends. What I/O interface are you using?

Is it a console process? Are you using a GUI? What OS? What widget set?

Duoas 1,025 Postaholic Featured Poster

No compiler error is user error... not unless the 'user' is the person using the compiler. :$

Check that you spelled everything correctly, that everything is in the proper scope, and if you still can't get it to work post your code here and I'll take a look at it.

Duoas 1,025 Postaholic Featured Poster

MPLAB SIM is another proprietary, created for a textbook, simulated processor/language. I don't have access to it. Your best bet is to go get help from your professor.

I don't think the code tags here understand assembly. I've tried a lot of different variations and none work...

Good luck.

Duoas 1,025 Postaholic Featured Poster

Did you define a procedure named save250? It won't work unless you do...

Duoas 1,025 Postaholic Featured Poster

Er, you misunderstand. We think it is the GIF that is faulty, not your code.

Duoas 1,025 Postaholic Featured Poster

Ah.

Virtual functions are the core of Object Oriented Programming --you can't do it without them. (Otherwise you are just doing "object-based" programming --or playing with structs that have functions attached.)

I think your professor wants you to understand what it is that OOP offers (i.e. what the benefit is from using virtual functions).

Part of the Animal type is an enum indicating what animal it is. If you can't use virtual functions you will have to change your makeAllNoisesInZoo() to use a giant if..else or a giant switch statement to check what kind of animal you have, then call the appropriate animal's makeNoise() function. if (a->getAnimalType() == t_Horse) ((Horse *)a)->makeNoise(); I was thinking of multiple-inheritance when you said "polymorphism". Sorry.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You are trying to do something that windows is designed against permitting. So it will be a very technical problem.

If you want more information type "setwindowshookex" in the Delphi IDE, place the cursor on the word, and press F1.

You are going to have to learn how to use this stuff for yourself. (Sorry, I can't spare to write it for you.)

If you want help along the way, post back here.

Good luck.

Duoas 1,025 Postaholic Featured Poster

The -- and ++ operators are initially confusing. They are unique to C and C++.

What --a means is "make a = a - 1 before you do anything else." Same with ++a : a is modified first.

The a-- means "make a = a -1 after you do everything else." Likewise with a++ .

C and C++ like shorthand statements. So alpha = beta++ is the same as the two statements: alpha = beta; beta = beta + 1; Hope this helps.

[EDIT] Alas, too slow...

Duoas 1,025 Postaholic Featured Poster

You need to read up on virtual methods.

Currently, Animal.makeNoise() is statically bound. In "zoo.h" you must say: virtual void makeNoise() so that the derived classes can override the method with their own versions.

Next, in your addAnimalToZoo() method, you have a memory leak. Let's trace your code:
1. in main() you allocate a new Horse.
2. in addAnimalToZoo() you allocate a new Animal (and use the default copy constructor).
3. in addAnimalToZoo() you put the newly allocated Animal in your array of animals
4. you forget about the Horse
5. in makeAllNoisesInZoo() you ask the first animal (whose type is Animal, not Horse, due to step 2) to make a noise. Animals are abstract creatures so aren't supposed to actually exist: Horses exist, Snakes exist, Cows exist.

My recommendations are
1. make Animal.makeNoise() a purely virtual function: virtual void makeNoise() = 0; Now an Animal class can't actually be instantiated. The user must instead instantiate a derived class (Horse, Snake, or Cow).

2. use the new-ed Animal object passed into addAnimalToZoo() instead of creating another Animal (which you can't do now anyway after recommendation #1):

void Zoo::addAnimaltoZoo(Animal *a)
{
	if (animalCount < ZOO_SIZE)
	{
		animals[animalCount++] = a;
	}
}

Fix that, give it a compile and run, and see if you can't fix the output error.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Caption is not an AnsiString, it is a __property.

A property is a way of making a member field that looks like a regular variable but which actually uses functions to get and set the value. C++ doesn't have properties in the language, but it is not uncommon to write a little class which does the job.

The __property class overloads all the operators necessary to make it look like an AnsiString, but it is still a different class, so you cannot pass it directly to the function. Since you don't know anything about the string besides what the accessor function gives you, you must use a temporary. This is the achilles heel of properties.

AnsiString temp;
  temp = Button1->Caption;
  AnsiChange( &temp );
  Button1->Caption = temp;

Enjoy.

Duoas 1,025 Postaholic Featured Poster

You are going to have to write a global hook and use SetWindowsHookEx. The procedure that does it will need to be compiled into a DLL (a regular application process is not permitted to use global hooks). Your application can then use the DLL to install the hook and remove it when it terminates.

I'm not sure you can trap CTRL+ALT+DEL, but I don't remember for sure either way.

Good luck.

Duoas 1,025 Postaholic Featured Poster

None of this stuff is standard. You'll need to check your compiler's documentation. In some cases fread and fwrite work just fine once you've opened a file with fopen64. In other cases you'll need to use some special functions and/or variables. Sometimes the fseek and ftell functions are modified instead.

Alas, this is all I know about it (having never used it myself).

Good luck.

Duoas 1,025 Postaholic Featured Poster

Somewhere, either in your code or in some library you are using, there is a reference to a function or a variable named 'hasp_login'. The linker can't find it.

As for fixing it, can you give a little more information about where you are using it? If you didn't declare it, what libraries are you including?

Duoas 1,025 Postaholic Featured Poster

If you are using the GNU tools, you can say: gmake -n -p to print the internal database used to compile without actually compiling anything.

Also, you can get the GNU compiler to give you dependency information about a specific file: gcc -MM foo.c prints all the non-system files that "foo.c" depends on. To get the system files also, use one M.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

What shell are you using. If it is bash or csh or somesuch, you need to use backquotes: echo `expr 2+4` Hope this helps.

Duoas 1,025 Postaholic Featured Poster

"A" is a string.
'A' is a char.
code is a char.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

There is no such function as e(). You want to #include <cmath> and use exp(). See here for more.

You need to define some variables in main() and use them. Like Ancient Dragon said, you are not using your functions correctly. For example, getValidAltitude() returns a value. So you should have something like: double altitude; altitude = getValidAltitude(); Likewise, some functions take arguments as well.

You have a very good start.

Duoas 1,025 Postaholic Featured Poster

No. I think it is a Solaris-specific extension.

Do you think you will need to read or write files larger than 2GB?

Duoas 1,025 Postaholic Featured Poster

Sure it will. Pay attention to what is being made const: ZOO_SIZE is const. After the array is created, it has no other effect (since you can't change the size of an array after creating it anyway). Animal *animals[ ZOO_SIZE ] is not const. You can change elements of the array (for example: animals[ 2 ] = new Horse( 750.0, "George" ); ).

Each animal you create is not const.

When you write a function like: void do_something( const Animal &a ) what you are saying is that a is const. That is, your function gets an animal by reference, but is not allowed to change the animal in any way. When you use the function it does not matter whether the animal you give it is mutable or not.

Likewise, when you have a method like: void MyClass::MyMethod() const what that means is that the method is not allowed to change *this in any way.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Your limit is an int, which is too small to hold the number you have put in it. (Your compiler should have complained about this.) Try using a long long or somesuch.

Start runningcount at 2, not one.

Your primeChecker() function is fine, but it will be slow.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

The only possible reason I can think of off the top of my head is that Button1->Caption is not an AnsiString.

Duoas 1,025 Postaholic Featured Poster

Ah, that helps. You need to be more careful about reading the documentation when using various procedures (line writeln).

For what you want to do, the save250 procedure can almost do it. Just add another parameter for the number of lines to save and adjust line 10 to use the correct value.

Then you can save each n lines in a loop.

procedure TForm1.Button12Click( Sender: TObject );
  var
    lines_per_block: integer;
    line_index:      integer;
    file_number:     integer;
    file_extension:  string;
    base_filename:   string;
  begin
  lines_per_block := strToInt( edit6.text );  // number of lines to save per file
  if saveDialog1.execute then
    begin
    // get the file extension and everything except the extension in
    // separate strings so we can inject the 1, 2, 3, ... file number.
    file_extension := extractFileExt( saveDialog1.filename );
    base_filename := copy(
      saveDialog1.filename,
      1,
      length( saveDialog1.filename ) -length( file_extension )
      );
    // save each block of lines
    line_index  := 0;
    file_number := 1;
    while line_index < ListBox.items.count do
      begin
      save250(
        base_filename + intToStr( file_number ) + file_extension,
        ListBox.items,
        line_index,
        lines_per_block
        );
      inc( file_number );
      inc( line_index, lines_per_block )
      end
    end
  end;

I used the name save250 just because that is what I gave you before, but I imagine you will want to rename it. Also, you can make it a private member of the TForm if you like...

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I haven't looked over all your code, but the addAnimalToZoo() function looks fine to me.

Polymorphism just means that you can derive from more than one class at a time. So, for example, you could make a SnakeHorse.

Duoas 1,025 Postaholic Featured Poster

A handle is a number used by Microsoft Windows to keep track of resources (like windows and memory and files, etc.). It has nothing to do with C++.

So, if you know the handle of something you can call Win API functions that do something with the resource.

To execute a program, use system(). You can also use the CreateProcessEx() Win API function.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

An AnsiString is a class, just like any other type of data.

To modify it in a function, pass it by reference: void myFunction( AnsiString &s ) Hope this helps.