Duoas 1,025 Postaholic Featured Poster

I think the original problem (causing the compiler error) is this: EventStream<complex<Lambda[B]>>[/B] evstrTrain( ... C++ compilers can't distinguish this from the right-shift operator. You need to have a space between them: EventStream<complex<Lambda[B]> >[/B] evstrTrain( ... Hope this helps.

iamthwee commented: good catch +13
Duoas 1,025 Postaholic Featured Poster

You're kidding, right? You demand us to help you in less than two hours? Go get a job and see how long people put up with you.

Since you fixed it yourself I won't bother giving you my answer.

Salem commented: Absolutely correct! +15
Duoas 1,025 Postaholic Featured Poster

Link.

Pay special attention to the section on "Reading and Writing Complex Data". You are interested in integers, but the same principles apply. Here's their example using int instead of Data.

#include <fstream.h>
    ...
    int x;
    int *y = new int[10];

    fstream myFile ("data.bin", ios::in | ios::out | ios::binary);
    myFile.seekp (location1);
    myFile.write ((char*)&x, sizeof (int));
    ...
    myFile.seekg (0);
    myFile.read ((char*)y, sizeof (int) * 10);

Good luck.

Sawamura commented: thx for the link and code +1
Duoas 1,025 Postaholic Featured Poster

Agreed, but when dealing with new programmers I have learned by experience (teaching and tutoring) that debugging works best once a firm concept of what should be happing is established. Anyway...

iamthwee commented: Well said +13
Duoas 1,025 Postaholic Featured Poster

Line 19 should read newp = (nameval_t *) malloc( sizeof( nameval_t ) ); This is why I recommend just always using parentheses with sizeof. It always works with parens, but makes a difference without...

n.aggel commented: thanks for your help!! :) +2
Duoas 1,025 Postaholic Featured Poster

I didn't understand this, Duoas. Please would you elaborate a bit? Terms like basic language interpreter and sandbox environment are completely new to me.

For example, you could embed a Tcl interpreter in your program (TCL or Tool Command Language is a script language). Or, you could link a Python interpreter into your application.

In either case, you can extend the interpreted language itself to provide functionality specific to your application. Once done, the end-users could write their AI scripts in the embedded language (e.g. Tcl or Python), and your program will execute the end-user's code as needed.

The end-user's code would be a simple text file (just like all code files).

However, executing code you didn't write is a security concern, so you will need to implement the interpreter such that the end-user's code cannot do anything it shouldn't (like access files, or create sockets, etc.) Such an interpreter is said to exist in a sandbox --basically a controlled environment. Sand stays in; foreign material stays out.

Fortunately, this is very easy to do in Tcl and Python (and Scheme :-).


Socket programming is a pain in C/C++. If you were to embed Tcl or Python, you could use the embedded language's facilities to open and manage the socket. Both Tcl and Python make handling sockets trivial.


Whether you choose to do this or not you've got a lot of homework ahead of you. Good …

Jishnu commented: Thanks, once again :) +2
Duoas 1,025 Postaholic Featured Poster

You could do it something like that, but it introduces more problems than it solves:

fork() doesn't work on Windows. Even if it did, you would still need to set up some IPC to make things work right (that is, keep state, avoid excessive process loads and task switching, and I/O buffering, response time, and message configuration).

The simplest, and most common way to do it is to use DLLs. That's what they were designed for.

Windows provides protected memory accesses, so one DLL cannot easily gain access to another's process. Further, doing so would require source-code knowledge of the target DLL. Finally, a game will not function well if subprocesses don't behave (and try to disrupt their bretheren).


Another option, if you intend to have a "end-user programmable" AI, is to provide a basic language interpreter (embed Tcl or Python or somesuch), and execute each AI's code in a sandbox environment.

Jishnu commented: Great help :) +2
Duoas 1,025 Postaholic Featured Poster

> I think you misunderstood the other poster.
> I don't think that word means what you think it means.
I amaze at the arrogance and rudeness some people possess. Do you really believe yourself superior to AD's intellect, and mine?

I don't really care much what you think. I know what the word inline means. Look it up yourself.

> The OP was using the way AD wasn't.
Thank you Captain Obvious.

sarehu commented: I think you misunderstood me, too. +1
Duoas 1,025 Postaholic Featured Poster

Actually, it might be possible to some degree. VB uses a lot of bytecode and, if I remember right, Microsoft and others have VB decompilers. You'll never get back the absolute original, but if you can find the right decompiler (and can front the cash for it), you should be able to get enough back that you can reconstruct the rest.

You might be better off just writing it over again...

Alas.

Dukane commented: thank you +2
Duoas 1,025 Postaholic Featured Poster

Further, depending on your choice of programming language, it is likely you can find free software libraries that will store all your configuration data in a structured text file format, for example: XML or even (gasp!) INI.

Salem commented: I like XML +12
Duoas 1,025 Postaholic Featured Poster

Yeah, I was thinking of Ultimate++ also.

If you don't mind writing "open source" there is also Trolltech's Qt, which I think still comes with a GUI designer. Version 3 had it at least.

And there is GNOME's Glade (GTK+) designer.

There is also the The GUI Toolkit, Framework Page.

Hope this helps.

Jishnu commented: Thanks :) +2
Duoas 1,025 Postaholic Featured Poster

Ah, yes, that works.

Still, I would repeat myself instead of calling FormCreate again.

procedure TForm1.RedoFunctionButton(Sender: TObject);
begin
memo1.Lines.Text :=  GetNicAddr;
end;

Have fun!

squidd commented: This man's patience with me is super-human. +1
Duoas 1,025 Postaholic Featured Poster
procedure TForm1.FormCreate( Sender: TObject );
  begin
  TrayIcon1.PopupMenu := PopupMenu1
  end;

This presumes you dropped a popup menu on your form and populated it with the menu designer.

Duoas 1,025 Postaholic Featured Poster

I'll get it to you shortly. I was in the middle of dinking with some stuff in it when I left-off and left it a mess. Once I've cleaned it up better (I should be done by tomorrow) I'll send it to you.

I'm not doing anything more to the syntax highlighter for the moment, and I discourage you using it for any serious stuff (as it is currently broken and slow), but everything else should work fine. (System Tray icon stuff, pop up menus, non-rectangular windows and pop up balloons, application mutex, and a few super-useful utilities I wrote years ago and never stopped using.)

Give me a day...

squidd commented: it wasnt mentioned here what was sent to me, thus the reputation point looks unwarranted, but I assure you it is! +1
Duoas 1,025 Postaholic Featured Poster

Not that I know of, but you could probably roll your own pretty easily. I know there are a lot of libraries people wrote on Google as well...

How complex is the INI file you want to read? (Does it stick to the simple [this is a section header] this=is a value format?)

I'm sure I came across a nice library about a year ago that is pretty advanced. If I can remember what it is I'll post back.

jaepi commented: Can foretell posibilities. Tsk tsk +2
Duoas 1,025 Postaholic Featured Poster

The #include "filename" directive effectively works by directly inserting the named file into the text.

// z.h
int i;
// z.cpp
#include "z.h"
// main.cpp
#include "z.h"

int main() {
  i = 42;
  return 0;
  }

Is the same as:

// z.cpp
int i;
// main.cpp
int i;

int main() {
  i = 42;
  return 0;
  }

So you have, in fact, declared the variable twice.

To get around that, declare it as extern.

// z.h

// declare the variable to exist, but don't cause it to exist
extern int i;
// z.cpp
#include "z.h"  // the variable is only declared as existing

// cause the variable to exist
int i;
// main.cpp
#include "z.h"  // the variable is declared as existing

int main() {
  // the variable is usable here, since main.ccp knows it exists...
  i = 42;
  return 0;
  }

Your code has one other problem. message is declared as a pointer to a thing, but no instance of that thing actually exists. You must either malloc() or statically declare the thing before using it.

Using malloc()

void initMsg() {
  message = malloc( sizeof( MsgStock ) );
  ...

Statically declaring it:

MsgStock _message;  // static variable

void initMsg() {
  message = &_message;  // now 'message' points to something
  ...

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

OK, according to your problem description I have a few comments to help...

But FIRST, please take the time to be careful about how you "format" your code. You've made some indentation errors (that is, because of the way you have indented your code you have made some errors!)

text file
OK, if the input file is a text file, why are you opening it in binary mode? Don't. std::ifstream in( "clients.txt" ); That's all you need.

Clearing the array should not be dependent on the file.

input
You cannot force input. According to the problem description, your input is guaranteed only to have the following form:

M|F 1 2 3 4 5 6 7 8 9 10 name ...

That is, the letter 'M' or 'F', followed by ten numbers, followed by one or more names. I would suggest that you don't need to care whether the client has both a first and last name, but you can always separate them later.

This input has a nice characteristic: all the fields at the beginning of the line are definite, while the last field is a free-form string. This means you can mix >> and getline() with impunity.

So input for each line (or client) might look something like this (needs more work):

// get the letter 'M' or 'F'.
std::cin >> sex;
// get the answers
for (i = 0; i < 10; i++) std::cin >> a[ i ];
// …
Killer_Typo commented: great post! +6
Duoas 1,025 Postaholic Featured Poster

Yes, good job. The only question is: how can you tell the difference between a node that contains a number and a node that contains an operator?

(Have you learned about variant records?)

Also, is it possible that the numbers in the equation will ever have fractional parts? (Say, what if it were "56 - 12/5 +1 * 5" ?)

Duoas 1,025 Postaholic Featured Poster

It is hard for a beginner, but not quite "way too hard".

Let me think a bit and post back later. My brain hurts and I'm tired of going around in circles with you.

Some quick things first:
1. Your last thoughts seem like a good plan.
2. Please get out some paper and draw how to accomplish each thing.
3. Please go talk to your prof.
4. See my post #7 for some big help. Just ignore the stuff about using records. Everything else applies.
5. temp_result := num1 causes them to both have the same value, which is not what I said. You don't need two variables with the same value. You need one variable that does what you are currently doing with two.

I'll post again in a day or after I've gotten some sleep.:yawn:

Duoas 1,025 Postaholic Featured Poster

Well, you know that the loop is reading the numbers correctly (because you before tested it by just reading and printing the numbers, and they printed the correct numbers).

But now that you are doing something to the numbers something is wrong.

May I suggest that num1 and temp_result should be the same variable?

Duoas 1,025 Postaholic Featured Poster

dubeyprateek
Don't be confusing, and don't give people gruff for nonsense.

A class is a type of thing. An object is an instance of that thing. A method is a function associated with a class (or type of thing), so objects of that type of thing (or class) can certainly be considered as "owning" a method. Remember, a class doesn't exist --but an object does.

Also, pay attention to the OP's question: she's not interested in calling methods "belonging to" the caller.

need_Direction
You call the method of any class by first specifying the object's name, then the method name. For example: myobject.dosomething(); This assumes that "myobject" has a parameterless method named "dosomething" associated with it. You can put such a statement anywhere that can see "myobject".

Often you can write a little program to test your hypothesis. Our hypothesis will be: object "B" can call a method of object "A".

#include <iostream>
using namespace std;

class myInt {
  public:
    char name;
    int i;
    myInt( char _name, int _i ): name( _name ), i( _i ) { }
    void print();
    void doSomething();
    void doMore( myInt &anInt );
  };

myInt A( 'A', 10 ), B( 'B', 42 );  // (1)

void myInt::print() {
  // Tell the world who I am and my value
  cout << name << ' ' << i << endl;
  }

void myInt::doSomething() {
  // Tell the world who A is (no matter who I am), and value
  A.print();
  }

void …
dubeyprateek commented: You really took time to explain this. +2
Duoas 1,025 Postaholic Featured Poster

Rather than a bunch of "if foo = x ... " statements, use a "case foo of" statement:

case oper of
  '+': begin
       ...
       end;
  '-': begin
       ...
       end;
  end;

You've already got a function that will read a number. (You used it to get num1.) Use it to get num2.

While you are moving along quite logically... your current line of thought is taking you toward that recursive descent algorithm that ExplainThat mentioned in joygqy's thread... there are no arrays in sight. If you are not to use records I'm at a loss as to how your professor expects you to use an array. You should take what you've got so far and go see him and ask how he wants you to put your equation into an array.

(Frankly, I think the assignment has a few points that are a little over the top. While simple, it is not trivial, and it is definitely not a beginner-level thing to properly handle mathematical expressions...)

Duoas 1,025 Postaholic Featured Poster

I get the following output: -201 -16 3.141 Did you compile with gcc -traditional-cpp ?


The printf statement just uses as few characters as needed to work. 4. floating point number * -F since F is negative, make it positive. (4.0 * (-F)) is a float. /OO float division (since numerator is float) /OO float division


Enjoy.

Jishnu commented: You've helped me a lot :) +2
Duoas 1,025 Postaholic Featured Poster

You can't initialize it inside the class definition.
Do this instead:

class Test
{
public:
    static const string MYARRAY[];
};

const string Test::MYARRAY[] = {"hello", "world"};

Have fun!

Duoas 1,025 Postaholic Featured Poster

Oy, after all that typing you beat me to the punch with another Q.

Second tutorial: scope.

Just as the functions and procedures above all belonged to tMatrix, so do the variables. Remember how you can do something like:

program McGonagalls_notes;
type
  tStudent = record
    name: string;
    grade: integer
    end;

var
  my_student: tStudent;

begin
  with my_student do
    begin
    name := 'Hermione Granger';
    grade := 100
    end
end.

Professor McGonagall remembered that when she is only thinking of one particular student, she doesn't need to remember all the information about where or how the student is referenced --she can just concentrate on that particular student. If she had preferred, she could have just said:

my_student.name := 'Hermione Granger';
my_student.grade := 100;

It is the exact same thing, but written using different scoping rules (by using the with statement).

The scope is what you can see at the moment. In an earlier example I created a unit to return whether a number is odd or even. Now, consider the following:

program oddness;
uses oddstuff;

procedure is_it_odd( n: integer ): boolean;
  begin
  result := FALSE;
  end;

var x: integer;

begin
  write( 'Please enter a whole number greater than zero> ' );
  readln( x );
  writeln( 'The statement "', x, ' is odd" is ', is_it_odd( x ), '.' );
  writeln( 'The statement "', x, ' is even" is ', is_it_even( x ), '.' )
end.

Now, the question is, "Which is_it_odd function gets called? The one in the unit or …

squidd commented: very well written and helpful +1
Duoas 1,025 Postaholic Featured Poster

Always fix errors in the order they come. Line 81 is incorrect, so no variable named recta is ever created, so when the compiler hits line 86 it complains about some structure variable you are using that doesn't exist.

Try this instead: Rect recta( 12.9, 13.4, 7.6 ); Also, please avoid MS stuff whenever possible. Your main function should be typed: int main( int argc, char *argv[] ) At the time MS wrote all those macros and junk, they had a pretty good reason. But there is no reason to contaminate new, unrelated code with it.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Sorry, I should have made myself more clear.

Try this:

procedure TMainForm.RemoveDuplicatesButtonClick(Sender: TObject); 
  var
    i, j, num_removed: integer;
  begin
    num_removed := 0;
    for i := 0 to ListView1.Items.Count - 1 do
      for j := ListView1.Items.Count-1 downto i+1 do
        begin
        if i = j then continue;  // <-- this line shouldn't be necessary
        if ListView1.Items[i].Caption = ListView1.Items[j].Caption then
          begin
          ListView1.Items.Delete(j);
          inc( num_removed )
          end;
        Application.ProcessMessages;
        end;
    ListView1.Columns[0].Caption := inttostr(ListView1.items.Count);
    CurrentStatusLabel.caption := 'Removed ' + inttostr(num_removed) + ' Duplicates';
  end;

I didn't actually test this code --it's late and I'm going to bed now... Also, with the revised j loop I don't think you need to test for i = j, it should never happen. (Alas, my brain is shot right now...)

Good luck.

squidd commented: Always an enormous help to me and has never given up in his efforts to help me. No amount of thanks descirbes my appreciation for this individual! +1
Duoas 1,025 Postaholic Featured Poster

An overloaded function is a function that shares its name with one or more other functions, but which has a different parameter list. The compiler chooses which function is desired based upon the arguments used.

An overridden function is a method in a descendant class that has a different definition than a virtual function in an ancestor class. The compiler chooses which function is desired based upon the type of the object being used to call the function.

A redefined function is a method in a descendant class that has a different definition than a non-virtual function in an ancestor class. Don't do this. Since the method is not virtual, the compiler chooses which function to call based upon the static type of the object reference rather than the actual type of the object.

For example, if you have an Animal *george , and george = new Monkey; , where Monkey inherits from Animal, if you say george->dosomething() the Animal.dosomething() method is called, even though george is a Monkey (even if a Monkey.dosomething() method is available).

Good luck.

Duki commented: Well said. Really helped me to put concepts into words. Thanks! +4
Duoas 1,025 Postaholic Featured Poster

Not really. It is about as simple as it gets. You'd have to add a bit of complexity to make it less brute force, and for what you are doing it isn't worth the effort.

Good job, BTW.

maxmaxwell commented: He was a great help in helping get my problem solved +1
Duoas 1,025 Postaholic Featured Poster

/me re-reads the first post

Ah, just use new to create an array big enough to hold the head of each linked list. node **listarray = new node*[ number_of_lists ]; Then return listarray.

Hope this helps.

Ratte commented: Very helpful replies. +1
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

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

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

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

Or you could just use the strspn() function: if (strspn( dnaStr, "AaTtCcGg" ) < strlen( dnaStr )) puts( "error in DNA" );

Aia commented: Aye +4
Duoas 1,025 Postaholic Featured Poster

Float types are just the hardware's floating point data type. Usually this is an IEEE single (4-bytes), double (8-bytes), or extended (10-bytes).

The problem with these is that they approximate numbers. Hence, they are not very exact. They lack precision and they are susceptible to the influences binary arithmetic.

The python decimal module gives a floating point class called Decimal which stores a number exactly. The tradeoff is that it is not as fast to use as a float. In most cases it is not so important to be so exact, so the float works just fine and there is no need to use Decimal.

However, in scientific computing exactness is often very important, so the Decimal type is very handy whenever it makes a difference between, say 1.000000000 and 1.000000001 Hope this helps.

bumsfeld commented: very nice explanation +3
Duoas 1,025 Postaholic Featured Poster

Both your teachers are full of crap.

Use ==.

Keep in mind, though, that == is limited to an exact match comparison and only returns bool. You can get a little more information back using functions like string.compare().

Hope this helps.

[EDIT]
I should give a little more info.

For the first teacher: if system load were to affect your code then there is something seriously wrong with your compiler. Chances are that == just calls the compare function... (but I don't actually know, having not bothered to read the STL code for it).

For the second teacher: why waste time and space converting a C-string to a std::string when you have a function that will do what you want perfectly well without going through the long winded and wholly unnecessary effort... Kind of like this sentence, no?

@rugae, just smile and nod when they start spouting stuff about odd behavior and extra hoops. :wink:

Duoas 1,025 Postaholic Featured Poster

You overload the istream whenever you want to do serial input. This requires your class to have a definite (and hopefully unique) way to store its data. You can format it any way you desire, so long as you can tell where it begins and ends.

So, for example, if you have a class named Employee:

class Person {
  string surname;
  string given_name;
  string job_title;
  time_t hire_date;
  float pay_rate;
  //etc
  };

You can pick all kinds of ways to save this information. One would be just to list each piece as a string in a text file:

Shunpike
Stan
Knight Bus Conductor
1993/4/12
$7.15

Bones
Amelia Susan
Head of the Department of Magical Law Enforcement
1972/5/19
$50.32

Given a file like this and an appropriately coded >> operator you could read in the data, knowing that there are five lines of data plus one blank line per record. No need to ask questions or do anything else.

It depends entirely on your storage requirements. In this example I chose a simple line-by-line data dump. It can be more carefully organized textual information (for instance, if your Employee data is mixed with other types of data), or purely binary. It is up to you.

However, you really should read up on serialization.

Hope this helps.

christina>you commented: great explanations. +15
Duoas 1,025 Postaholic Featured Poster

Watch your fencepost conditions. j can become negative.

Try tracing your sort using this input:

arr3 = 1 3 7 2 9 0 5
       j
         i
temp = 3

Good luck.

tracethepath commented: thanx...it worked +1
Duoas 1,025 Postaholic Featured Poster

Yes, yes, exactly. Thank you.

I've nothing against memcpy(). Just using it improperly.

iamthwee commented: I can't believe you don't use video tutorials they save hours! Thanx +13
Duoas 1,025 Postaholic Featured Poster

That's because you've got it buried in the Employees namespace. Use its full name: Employees::TitledEmployee frank; Have fun.

Duki commented: Thanks for the C++ help! +4
Duoas 1,025 Postaholic Featured Poster

This is deliberately obfuscated code. Where did you get it?

Salem commented: Certainly looks like it to me. +11
Duoas 1,025 Postaholic Featured Poster

Er, the standard way to do it is to use a vector or a deque. These automatically size to fit and allow you to add or remove elements very easy from the back (and front if a deque), and middle without too much trouble. Both can be accessed with the [] array indexing operator, are fast, don't require you to manage their memory, and have only one "disadvantage" over an array (or a newed array): they can't be treated as a pointer. Additionally, deques allow you to work with arbitrarily large amounts of data (or numbers of particles) without any increase in time.

If you want to be throwing random numbers of particles around, I suggest you use a deque, not an array (whether new or not).

Good luck.

Ancient Dragon commented: very well said +20
Duoas 1,025 Postaholic Featured Poster

Best answer is, don't do that.

You are playing with undefined behavior. For any single variable, there should be a maximum of one pre/post increment/decrement operator. Otherwise your results may vary: You could just as easily have gotten 1 2 3, 1 3 2, 3 1 2, 2 1 3, or 2 3 1.

The actual reason you are getting 3 2 1 is because your compiler plays with the arguments in the same order they must be pushed onto the stack to call a c-function. However, that's just one compiler. Others could easily give you different results. (Heck, the same compiler could give you different results at different times.)

Therefore, better to say:

int a = 1;
printf( "%d%d%d", a, a+1, a+2 );
a += 3;

This avoids the undefined behavior of multiple pre/post inc/dec ops for a single variable in one statement.

Hope this helps.

Salem commented: Good answer +11
Duoas 1,025 Postaholic Featured Poster

An array is just an ordered list of things. So for the array to be serializable the elements of the array must be serializable. Hence, your conclusions 1 is correct. Conclusion 2 is correct for all elements in an array (not just objects).

However, conclusion 3 needs a little help: Primitive types are serializable by default whether or not they are stored in an array. Therefore it follows that any array made of primitive types is also serializable.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Time enough has passed that I haven't answered here.

As I mentioned already, the reason you see a button on the taskbar is because the application puts it there. Your forms don't. You can see this by going to the main menu --> Project --> Options --> Application --> Title and giving your application a title that differs from the main form's caption. The button on the taskbar will show the application title, and not the mainform caption.

When you have MDI children, which cannot be hidden, the application button is restored to the taskbar because you technically still have windows showing... even if the MDI main form is hidden.

So, to get rid of it you have to turn it off explicitly. In MAIN.pas, make sure you have the following:

interface
type
  TMainForm = class(TForm)
    procedure ApplicationActivate(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private:
    procedure SysCommandMessage(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
  protected:
    procedure CreateParams(var Params: TCreateParams); override;
  end;

implementation

procedure TMainForm.ApplicationActivate( Sender: TObject );
  begin
  // Remove the application button from the taskbar
  // (and make sure it stays that way)
  ShowWindow( Application.Handle, SW_HIDE )
  end;

procedure TMainForm.FormCreate( Sender: TObject );
  begin
  // Keep the application button out of the taskbar
  application.OnActivate := ApplicationActivate
  end;

procedure TMainForm.SysCommandMessage(var Msg: TWMSysCommand);
  begin
  // Routing WM_SYSCOMMAND messages through here instead of the default
  // handler prevents Delphi from trying to create a taskbar button for the
  // application when minimized and maximized, which when combined with
  // ApplicationActivate would otherwise cause flicker. …
csy commented: Helpful +1
Duoas 1,025 Postaholic Featured Poster

Pointer syntax in C/C++ is very flexible, but likewise very confusing. You can say something like int i, *pi, **ppi; but this should be read carefully as

int i;
int* pi;
int** ppi;

:an integer, a pointer to an integer, and a pointer to a pointer to an integer. Yeah, I know... read it again anyway... (I attached the "*" to the int because it is part of the type of each variable, but it could be anywhere between the base type and the variable name.)

In C, you are forgiven a lot when dealing with the type of things. Hence, as already mentioned, the variable int* pi can be a pointer to a single integer or a pointer to a whole lot of them. Typically, programmers will state their intent by saying either int *a --pointer to a single int, or int a[] --pointer to an array of ints.
However, you can't use the [] brackets when declaring a function return type, so you are stuck with the *.

Hope this helps.

zandiago commented: pretty decent breakdown +1
Duoas 1,025 Postaholic Featured Poster

The strrev() function is somewhat more common on windows. In linux you have an even shot of having it and not having it. It isn't in the ISO standard (AFAIK).

Here's a simple strrev:

char *strrev( char *s ) {
  char *u, *v;
  char c;
  for (u = s, v = s +strlen( s ) -1; u < v; ++u, --v) {
    c = *u;
    *u = *v;
    *v = c;
    }
  return s;
  }

You could combine the strcpy() and strrev() functions into one function to reverse and copy a string at once...

Also, iamthwee makes a good point. Make sure you are compiling with -Wall to see all errors you can get. Windows compilers are notorious for letting you get away with improper headers.

All these palindrome programs --isn't this too strict? After all "A man, a plan, a canal: Panama!" is a palindrome, but none of the programs posted so far considers ignoring punctuation and spaces. Ask your professor "Can I attain a 'C'?".

Salem commented: I like the last palindrome :) +11
Duoas 1,025 Postaholic Featured Poster

It is good that you are thinking in terms of separating out functions in your code.

In this case, there is no compelling reason to do it either way. Each loop must iterate through the exact same sequence of numbers.

If you were to use two separate loops though, you would need to store the numbers obtained by the first loop somewhere (such as in a vector or list or an array), then loop through them again to calculate their average.

Write your (one) loop as if you were calculating the average. Only instead of getting the next number from an array or something just get it from the user. When the user gives you the sentinel quit the loop, finish calculating the average, and print it.

Hope this helps.

iamthwee commented: glad to see you posting again. +12
Duoas 1,025 Postaholic Featured Poster

Actually, I've answered your question quite thoroughly. You have to think now. I'll not do your homework for you. If I did, you wouldn't learn anything.

Narue commented: Good. +18