JasonHippy 739 Practically a Master Poster

I have c++ functions in which all the arguments are integers....I was wondering if there was a way of telling the computer this, other than typing int before each and every variable....I tried
function S(int a, b,c..)
but did not work....

Short answer...No, you can't. You have to specify a type for every parameter passed into a function, even if there are more than one of the same type.

Inside a function body, you can define local variables of the same type like so:

int main()
{
    int a, b, c, d, e;
    // Some code here........
}

But for function declarations and definitions, you have to specify the type for each parameter:

void myFunc(int a, int b, int c, int d, int e);

Hope that clears things up for you.
Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

Ooops, good point Dave. Nicely done!

I should've been using unsigned ints in my code too. I completely forgot to take the sign into consideration. The rotate functions in the OP's code won't work with negative numbers! {kicking self!}

I toyed with the idea of doing something like your UINT_BITS definition to get the actual system size, but admittedly I would've ended up doing it for int... Tut! I should've thought it through! However, I decided to run with the hard-coded 32 that the OP posted in their code.

Anyways, hats off to the Davester!

Jas.

JasonHippy 739 Practically a Master Poster

456 is certainly far too big for n. n should be somewhere between 1 and 31 (shifting x by 32 places in either direction will give you x!)

This is the statement you were referring to, just to clarify things here I should really have written:

456 is certainly far too big for n. n should be somewhere between 1 and 31 (shifting x by 32 places using rotateleft or rotateright will give you x!)

[edit] But as there is rotation going on, I guess that entire statement is actually pretty redundant!

JasonHippy 739 Practically a Master Poster

But if you take another look at the code that is being used in the rotateleft and rotateright functions in the OP, it's not just a straight shift, there actually is some rotation going on. (or at least something equally as cunning!)

There are two operations in the rotateleft and rotateright functions. The first operation is a straightforward shift of x by n places in the relevant direction, but the result of the first operation is OR'ed with the result of the second operation. The second operation shifts x by 32-n places in the opposite direction.

Try running my code and vary the values a little and you'll see.
Perhaps keep x as 4 (or something easily predictable) and try varying the value of n.
In fact if you set n to 32, you'll find that the result of shifting x by 32 places in either direction (using rotateleft or rotateright) results in the value of x staying the same.


[EDIT] In fact, because it actually does rotate, try n as 64, 96, 128 or any other multiple of 32 and the result will be x.

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

The macro functions rotateleft and rotateright perform binary shift operations, shifting the binary value of x by n places in the appropriate direction using the << and >> binary shift operators.

So using some smaller, more sensible values for x and n (e.g. x=4 n=2);
if we now did something like:

x= rotateleft(x,n);

Using my example values for x and n, we know that x==4.
In binary 4 is represented as:
100

if we shift the binary value of x (4), n places to the left (n==2 remember), we get this..
10000
Which is the binary representation of the number 16.

So the value of x would become 16.

To get the original value of x back, you need to call rotateright passing x and n, which will output the value that results from shifting x (16) to the right by n (2) places.
So we'd call this:

x = rotateright(x,n);

This time the value of x is 16. n is still 2.
16 in binary is:
10000

shifting 2 places to the right gives you the binary value:
100

Which is the number 4 (the original value of x!)

Just in case you're not 100% clear, have a butchers at this simple example:

#include <iostream>
#include <string>

#define rotateleft(x,n) ((x<<n) | (x>>(32-n)))   
#define rotateright(x,n) ((x>>n) | (x<<(32-n)))

using std::cout;
using std::endl;

void output(const std::string &message, const int &x, const int …
JasonHippy 739 Practically a Master Poster

Oh hang on... looking at your original post again, you said version 8 not VS2008. Version 8 is VS2005 isn't it?!

Doh! Sorry, if you're using VS2005, disregard my previous post entirely...

Well, almost entirely! It might be worth making sure that you've got all of the relevant service packs installed for the VS2005 IDE.
Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

Hmm, this problem sounds interesting...
I've just been upgraded to VS2008 Pro, from VS2003 Pro at work and it's been great so far. The ability to see inside std library containers from the debugger without having to add code to log values has been most welcome.

VS2003's debugger was a royal pain in the posterior when it came to seeing what was inside std::library classes, I resorted to using my own logging class to log the details of objects stored in std:: containers.

Anyway, we use some pretty complicated class structures and objects in our product (3D CAD/CAM) and I've not seen any problems with the debugger so far. I'm in the middle of updating/re-implementing some old legacy code at the moment, so I'm going to be using the debugger rather heavily soon enough. I'll keep an eye out for any problems and repost if I spot anything unusual.

Just a thought, and this may sound like a stupid question; but do you have service pack 1 for VS2008 installed? We patched all of our installs to SP1 when we installed VS2008, so none of my dev team have tried it without the service pack.

If you've already got SP1 installed, then I'm out of ideas I'm afraid. I'll keep an eye out, but I've not seen any problems with the debugger yet. None of the other members of my development team have reported any odd behaviour from the debugger either.

However, if you …

JasonHippy 739 Practically a Master Poster

One thing in your code struck me almost immediately. In functions.cpp you haven't included functions.h, which is most likely the root cause of your problem!

Cheers for now,
Jas.

[edit] P.s. I think you also need to include stdlib.h for srand, but I could be wrong!

JasonHippy 739 Practically a Master Poster

Good Afternoon All,

I have a template that I'm working on with the same flash header on each page. The header contains the drop down menu to go to the other HTML pages in which the header is placed. I noticed this as one of the parameter lines

<param name="movie" value="../../../client%20websites/Kingdom%20Coaltion%20International/KCIF%20phase%202/MTech/cugb/header_v8.swf?button=2" />

Can someone explain what I have put in green please? With all the Flash I have seen and worked with this is my first for this.

Thanks for your time and assistance.

To put it very simply, the code you've highlighted in green is the name of the .swf and a parameter that is passed into the .swf.

Something in the actionscript inside the .swf will then use the passed-in value to initialise a variable in the script.

There are several ways of passing parameters to a .swf and this is one of them!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

From the looks of the error you're getting, I'd say you probably need to create an override for the operator< to allow two instances of your node class to be compared.

I've not really looked through your code too much, I've only given it a brief once over so I'm not 100% on what you're doing, but I'd guess that you need to be adding something like this:

bool operator<(const Node &n1, const Node &n2)
{
	return n1.path_cost < n2.path_cost;
}

If that's not exactly what you want, you might just want to slap the code from cmpNodes() in there. Either way, you should put your own code in there to compare two Nodes. But one thing's for sure, the compiler is almost certainly complaining about the lack of an operator< override!

I did notice a few other things during my brief sweep of your code. I noticed with your usage of printf, scanf and sscanf, you're mixing some outdated and potentially unsafe C stuff with C++ there. Could be worth updating. It also looks as if the variable 'line_no' is uninitialised at line 124 before it is incremented at line 132. Another potential bug!

You should also be getting an error about the ChildNode function as it doesn't return anything ATM. But I'm guessing that's because you haven't got round to implementing that yet!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

Try opening up a python command line, and enter the folowing:
help()
modules

After a short while you should see a list of all installed modules.

Does PIL appear anywhere in the list??
If you can't see it, you should try running the PIL installer again.
But if it is there, I'm not sure what to suggest....

Just a thought, which version/s of python do you have installed?
If you've got more than one version of python installed, have you installed PIL for a different version of python?

For example, I've got 5 versions of Python (2.4, 2.5, 2.6, 3.0 and 3.1) installed on my work PC, but I've only got PIL installed for python 2.6.

So as long as I'm using Idle2.6 or the python 2.6 shell, PIL is available to me. But if I'm using any of the other versions of python, it is unavailable to me... Not sure if that could be your problem...

Other than that I'm pretty much out of ideas!
Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

I've recently been upgraded at work from VS2003 to VS2008 (woo hoo I can finally see inside STL Containers without having to use my own logging class!! :) ).

Visual Studio is a great IDE, the debugging features are second to none, VS2008 is definitely my favourite IDE on Windows.

But I mainly use my *nix laptop for developing at home, so Code::Blocks with gcc/g++ is the order of the day there. Debugging with C::B and gdb can be difficult, but it's worth the effort IMHO.
C::B is really fast to start up and has loads of different built-in project templates, so just like visual studio, you can get a new project up and running pretty quickly.
The wxSmith plugin for C::B is a godsend, allowing RAD with wxWidgets. C::B is very similar to VS in many ways, but perhaps not quite as powerful or as richly featured....But hey, it's free!
It's also cross-platform, so it works equally well on windows and mac too!

I have also tried Anjuta, Netbeans and Eclipse on *nix. I found that Netbeans and Eclipse were just too damn slow to start up (or to do anything with) and I never really got on with Anjuta... I just didn't like it.

Occasionally I'll use Emacs to edit and compile simple single-file programs (like when helping people with code here on Daniweb).
Or use gEdit and compile with the command line....Sometimes you've just gotta do it via the …

JasonHippy 739 Practically a Master Poster

>In most, if not all OSes; if a program's main function returns an int, 0
>indicates that program execution ended normally.
>Any other value indicates that the program execution ended
>abnormally. In other words an error occurred.

That's required behavior for a C++ implementation. It has nothing to do with the OS, because the calling code is (rather than the OS itself) a C++ runtime that interprets the return value of main and converts it to something suitably equivalent for the system.

Fair point! I was probably oversimplifying my explanation there. But as ever, you've summed things up far more succinctly and accurately than my own fumbling attempt! Thank you Narue! :)

>Likewise if the main function of a program returns boo
The main function doesn't return bool, and suggesting that it does, or that the integer value returned represents a boolean value, is terribly confusing.

I know that, but surpisingly I've seen a few odd programs (emphasis on the odd) that actually use the bool return type for main...Thankfully I don't think that this unusual practice is particularly widespread or particularly well advised for that matter. Certainly not an option I'd choose, but something I have seen used on my travels. So I thought I'd share just in case!

I've only seen it a handful of times. The one time I came across it professionally, you can be sure that I changed the return type to int! Bool main?? Weird!
I …

JasonHippy 739 Practically a Master Poster

Yes it is possible.

If you've been having trouble trying to do this, I'm assuming you were doing something like this:

pResult = p1 + p2

Which is definitely not what you want to do. The compiler probably wouldn't allow it anyway, but what that code would attempt to do is add the memory addresses of p1 and p2 together and assign pResult to the resultant memory address...which could contain literally anything!

But as I've said you'd more likely just get a compiler error saying that the two pointers cannot be added together like that!

Assuming you have three int pointers correctly assigned to valid int variables; To add the values of two pointers together you'd do this:

*pResult = *p1 + *p2;

Which simply adds the values stored at p1 and p2 together and stores the resultant value at pResult.

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

I kind of understand, so for this example, what does return T do if its not in a main function?

Well, lets look at that in terms of my definition of what return does:
return exits the 'current function' and returns to the 'calling function' passing an appropriate value.
In this case, the return is in the Add function, so the 'current function' is the Add function, the 'calling function' is whatever bit of code that called the Add() function and the value being returned is T.

So at the return statement in the the Add function, code execution jumps back to whatever bit of code called the Add function and passes the value of T.


Assuming that your function works (I haven't actually read through the rest of the code, I'm just gonna explain the return thing for now):
If you had a void function called process that called the add function like this:

void process()
{
    // not sure how you're using the add function so apologies if this is wrong.
    // the main thing here is the actual function call..
    const int maxSize=200;
    int result;
    Time myTime[200];

    // This is the main thing we're interested in:
    result = Add(myTime, maxSize);

    return;
}

At the line where the Add function is called, the code is basically saying:
"Call the Add function, passing myTime and maxSize and assign the returned value to the variable result"

So execution jumps from …

JasonHippy 739 Practically a Master Poster

OK, I'll try to explain this as simply and accurately as I can.

First though, a note on functions:
All functions must return something...Anything, even if that something is actually nothing (if a function returns nothing then you use the 'void' return type).

Return doesn't end the program unless the call to return is made in the main function.

A more accurate description of what the return keyword does is this:
The return keyword exits the 'current function' (the function we're returning from), returning back up the call-stack to the 'calling function' (i.e. the code that called the 'current function' we're returning from).

I'll try to explain this in more detail, but first take a look at this very quick code snippet as this will form the basis of my explanation:

#include<iostream>

// here's the declaration of a function which returns a boolean (true or false) value
bool somefunction();

// Here's the main function, the entry point of the program
// returns an int value
int main()
{
    if(somefunction())
        return (0); // end the program normally
    else 
        return(1); // end the program but flag an error condition
}

// Here's the definition of someFunction
bool someFunction()
{
    // we'll just return true here
    return true;
}

Now imagine this:
From your OS, you compile and run the above program.

The main() function is the entry point of the program, so when you run your program, your OS loads the program into …

JasonHippy 739 Practically a Master Poster

Have you tried using ios:: flags on the file open instead of the fstream:: flags?
Perhaps try:

fstream file ("myFile.dat", ios::out | ios::binary | ios::app);

Does that make any difference??
Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

Well you're very nearly there!
You said you wanted to find out how many items in the array were greater than 100, that would imply that you need some kind of counter, which is the missing ingredient in your original description.
So in your code:
You set your counter to 0
You use a for loop to loop through your array.
On each iteration of the loop, if the current item is greater than 100, increment the counter by one.

Once you're out of the loop, your counter holds the number of items which were greater than 100.

Cheers for now,
Jas.

EDIT: doh beaten to the punch!

JasonHippy 739 Practically a Master Poster

Your GetData and GetSize functions need to be declared const
e.g.

unsigned GetSize() const // This
	{
		return n;
	}
void* GetData() const // and this needs to be const
	{					
		return v;
	}

Because the parameter 'a' to the Allocate classes operator = override function has been declared as a constant reference to an Allocate object, then the GetData and SetSize functions have to be declared as const otherwise the compiler thinks that they might attempt to modify the Allocate object....If you follow me!

Cheers for now,
Jas.

edit:
Dammit, beaten to the punch again!

JasonHippy 739 Practically a Master Poster

I think that learning about tweening is a great idea, you should do it! heh heh!

When used properly tweening can make your animations look a lot more natural, realistic and life-like.

There are some great free tweening libraries available for AS3 (like tween lite http://blog.greensock.com/tweenlite/ ) which are actually more powerful than the built in tweening classes (and easier to use as well!)

Regarding your preloader question...Google it, there are loads of tutorials about creating flash preloaders all over the web (or at least there were the last time I looked). You certainly don't need to go buying a template! Why do that when you can create one yourself?!

The bar and % loaded indicators are quite straightforward to create, but there's nothing to stop you from doing something more elaborate while the file is loading.

I recommend that you do the following:
1. Take a look at some preloader tutorials (even if they are sucky bar and % indicators)
2. Understand exactly what they're doing and how

Once you've done that and you understand how they work, you can use that knowledge to create your own preloader...If you like you can make a monkey breakdance while the file loads, it doesn't have to be a bar and a %loaded indicator.
The only reason most flash files use simple bars and % indicators is to ensure that the preloader part of the .swf loads and starts running really …

iamthwee commented: I'll second this. +11
JasonHippy 739 Practically a Master Poster

Take a look at this page:
http://msdn.microsoft.com/en-us/library/b9skfh7s.aspx

Assuming that the other processes you mentioned are programs that you've written and as long as I understood the above page correctly, if you set the code for all of your programs/processes to open data files using this syntax:

FileStream^ fs = File::Open( path, FileMode::Open, FileAccess::Write, FileShare::None );

or:

FileStream^ fs = File::Open( path, FileMode::Open, FileAccess::Read, FileShare::None );

That should stop other processes from being able to open the same file. I imagine there will be an exception thrown by any attempt to open a locked file, so if your processes are also set up to catch any relevant exceptions that might also help things along!

So any time your programs need to open a file for read/write, try opening with the above code. If an exception is thrown, perhaps set up some kind of timer for a few milliseconds and then try opening the file again.
If all of your processes are doing this, then I guess you can be sure that the only time your processes will be able to use the file is when none of the others are using it!

Not sure if that's any help, I've not done any managed C++ in donkeys years. But from an initial glance that's how things look to me!
Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

My crystal ball says the UNICODE macro is defined, which causes CString to resolve to an actual type of CStringW. The implicit conversion ends up actually being CStringW to wchar_t*, which cout (the narrow stream object) isn't built to handle. Two simple options are to undefine UNICODE (if you don't need Unicode in the project), or use wcout instead of cout.

Aha, thanks Narue, that was beginning to bug me!
I've not done anything much with unicode, so I've never come across that particular problem before. But I guess that would make sense!

I shall endevour to remember that for future reference.

Thanks again,
Jas.

JasonHippy 739 Practically a Master Poster

Hmm, That's very odd!
After looking into this, Niek e's example compiles ok for me and outputs the strings properly.
I'm not sure why you're seeing the addresses of the columns instead of the actual strings..

What happens if you explicitly cast the result of the 'your2darray.at().at()' function call to a CString?
e.g.

std::cout << (CString)(your2darray.at(y).at(x)) << " | ";

That's about the only thing I can think of right about now.
If that doesn't work, I'm at a loss I'm afraid!
Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

OK, if you need a fresh pair of eyeballs to go over the code, .zip up all of the source files for your project and post it here as an attachment, I'd be more than happy to take a look at it for you!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

It's literally just this...

void withdraw(double amount)
	{
		balance -= amount;
	}

I'll attach the file that this is done in but I'm nearly 100% sure it's not this method because when used with a vector this did the job

Hmmm, that's odd. That looks like it should correctly update the objects balance. Have you tried using the this pointer to refer to the balance?
e.g.

this->balance -= amount;

That might just do the trick!
If that doesn't work (and I can't see why it shouldn't!), I also noticed that in your constructor you're setting the balance using:

Account::balance = balance;

So perhaps as a last resort you could try adjusting the balance like this:

Account::balance -= amount

Other than that, I can't see anything obvious there!
Cheers for now,
Jas

JasonHippy 739 Practically a Master Poster

OK, well take another look at your code...
When the Bank::withdraw function is called, a pointer to the relevant account is obtained. If the account balance is >= the amount, then the withdraw function is called for the account pointed to by the account pointer.

Therefore if the accounts balance is not getting adjusted when Bank::withdraw is called then your problem is actually in the Account::withdraw function.
So there's nothing wrong with any of the code you've posted here. The problem is in Account::withdraw. Therefore the question is what does the Account::withdraw function look like? (You haven't posted it!)

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

Personally I'd copy the sentence into a stringstream object and then use the stringstream's >> operator to separate each word from the sentence and store each word in a vector of strings.
Like this:

#include<iostream>
#include<sstream>
#include<string>
#include<vector>

using namespace std;

int main()
{
	string sentence, word;
	vector<string> wordlist;
	stringstream raw_stream;

	// Get user to enter a sentence:
	cout << "Enter a sentence: ";
	getline(cin, sentence, '\n');
	cout << endl;

	// Copy the sentence into a stringstream object	
	raw_stream << sentence;

	// Separate the sentence into individual words 
	// with the >> operator and put them into the wordlist
	while(raw_stream >> word)
		wordlist.push_back(word);

	// Output the contents of the wordlist 
	if(wordlist.size()>0)
	{
		cout << "In the sentence:" << endl << sentence << endl;
		cout << "The individual words are:" <<	endl;

		int count=1;
		for(vector<string>::iterator iter = wordlist.begin(); iter!=wordlist.end(); iter++)
		{
			cout << "Word " << count << ": " << *iter << endl;;
			++count; 
		}
	}
	else
		cout << "No words were entered!" << endl;

	// wait for user to press enter
	cout << "press enter to continue..." << endl;
	getline(cin, sentence, '\n');
	return 0;
}

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

Flash sucks
flash intros penalise in search, annoy your customers
anything that makes the page load longer, kills customer retention

heh heh, aside from that and actually staying on topic..heh heh!

I've never used after effects, so I couldn't comment on its functionality, but it's certainly possible to do an intro like that in flash. But you'd have to be bloody good to get something that looked as flashy looking as that behemoth of an intro!

That was a very professionally made intro..But its a shame it took so long to load...It should be noted that the flash intro you linked to there was more the kind of thing for use in a video presentation, a desktop flash app or perhaps a LAN based site rather than a web based flash site, it even said so on the web page.

If you're planning on doing an intro like this for a video presentation or a desktop flash app, then you should be OK, go ahead and give it a shot, the sky's your limit!

However; if you're doing this as an intro for a website, then you'd probably be better served doing something more optimised. As bob has already pointed out, if your intro doesn't load quickly, then potential users of your site will just leave...They won't wait!
Likewise, if the intro is too long (and especially if there's no 'skip intro' button), your users will just leave...unless the intro is really REALLY …

JasonHippy 739 Practically a Master Poster

From looking at the code, it seems to me that if you run your debugger and step through the program you'll find that line 34 will fail to read anything from the input file.

The reason for this is because by this point you've already read the entire file, so your input stream inData is pointing to the end of the file. So what you need to do is reset inData to point to the start of the file.
If you close the input file and then reopen it again between lines 32 and 34, that should achieve the desired effect.
There are probably other ways, but I can't think of any offhand!

However, the failure to read from the file is the least of your problems.
Once you've fixed the read problem, when your call to ReverseQueue is made, your program will get stuck in infinite recursion. Your program will recursively call ReverseQueue until the program runs out of memory and crashes.

Your program does not fulfil the criteria you need to meet, it doesn't reverse the queue, so you're going to need to rethink your program logic.

Wouldn't it make sense to read your input file once, sending the values into an instance of your queue class? Then perhaps iterate through your queue to output the original values to the output file before passing your queue to a recursive function to reverse the queue, before finally outputting the final values to …

JasonHippy 739 Practically a Master Poster

Oh I see you've HAD to implement your own queue class as a part of your assignment...sorry I thought you were just over complicating things for yourself.

In that case, to turn your class into a double ended queue I guess you'd need to implement a function to allow the removal of items from the back of the queue, something like this perhaps?

template<class Type>
void queueType<Type>::deleteBackOfQueue()
{
     if (!isEmptyQueue())
     {
       count--;
       queueRear = (queueRear - 1) % maxQueueSize;
     }
     
     else
     cout <<"Cannot remove from an empty queue"<<endl;
     
}

Then in the if statement:

if(aDeque.front() == aDeque.back())		
{			
	aDeque.deleteQueue();	
	if(!aDeque.empty()) 			
		aDeque.deleteBackOfQueue(); // pop the back()		
}

I've not compiled or tested the above code snippets, but I'd imagine that you would need to be doing something similar to the above!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

dkalita has already explained it to you...Try reading his post again!

The function 'fun' returns an int.
But it takes a pointer to a function as a parameter.
The function pointer must point to a function which returns an int and takes no parameters.

main happens to be a function, it returns an int and it takes no parameters, so you can easily pass a pointer to main into the function. Even from within main!

Function pointers do have their uses and I've never seen a function which took a pointer to main as a parameter, but I guess there may be some practical applications, perhaps some recursive algorithms might call for something like this.

I've expanded on the example you posted. This little doozy uses a function pointer to implement recursion:

#include <iostream>

using namespace std;

// function declaration
int myFunction(int (*funcPtr)());

// global static int to stop us from recursing too far
static unsigned int count=0;

int main()
{
	cout << "inside main" << endl;

	// now we'll call our function passing a pointer to main
	myFunction(main);
	
	cout << "exiting main" << endl;
	return 0;
}

// myFunction:
// calls a function pointed to by the input parameter (a function pointer)
// \returns<int>
// \param<funcPtr>takes a pointer to a function which returns an int but takes no parameters
int myFunction(int (*funcPtr)())
{
	cout << "inside myFunction!" << endl;

	// increment the counter
	count++;
	// if count is less than 3:
	if(count<3) …
JasonHippy 739 Practically a Master Poster

It seems to me that you are over complicating things. Wouldn't it be a lot simpler to just use a double ended queue, otherwise known as a deque?
Modifying your code from one of your previous posts in another thread:

//Implement the palindrome-recognition algorithm described in "Simple Applications of the ADT Queue"

#include <iostream>
#include <string>
#include <deque>

using namespace std;

void isPal(string);

void isPal(string s)
{	
	deque<char> aDeque;

	for(unsigned i = 0; i < s.length(); i++)
	{	
		aDeque.push_back(s[i]);
	}
	
	bool charEqual = true;
	
	while (!aDeque.empty() && charEqual==true)
	{
		if(aDeque.front() == aDeque.back())
		{
			aDeque.pop_front();
			// as long as the pop_front() didn't empty the deque..
			if(!aDeque.empty()) 
				aDeque.pop_back(); // do a  pop_back()
		}
		else
			charEqual=false;
	}
	
	cout << word;
	if(charEqual == true)
		cout <<  " is a Palindrome" << endl;
	else
		cout << " is NOT a Palindrome" << endl;
}

int main ()
{
	string input;
	cout << "Enter the string: ";
	cin >> input;
	isPal(input);

    return 0;
}

Isn't that a lot cleaner and quicker than using two queues? it certainly saves you from creating that unneccessary template nonsense in queue.h!

EDIT:
Now modifying the above code to read words/lines from a file and then pass each word/line to the isPal() function you get this:

//Implement the palindrome-recognition algotithm described in "Simple Applications of the ADT Queue"

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <deque>

using namespace std;

bool isPal(string);

bool isPal(string s)
{	
	deque<char> aDeque;

	for(unsigned i = 0; i < s.length(); …
JasonHippy 739 Practically a Master Poster

You might want to take a look at this thread:
http://www.daniweb.com/forums/thread230230.html

The first few posts are irrelevant, but the later posts are probably more or less exactly what you're looking for!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

It's because the literal value (25.95) that you are passing into your call to the function VAR1 is automatically treated as a double, but your function takes a float as a parameter. So you're getting a warning about it.

If you pass the variable like this:

printf("%.2f", VAR1(25.95f)); // printf a float ending in .95

The f at the end of the literal value will ensure that the value is treated as a float and not a double and should stop the warning from occurring.

in fact considering this is C++ you should really be using std::cout instead of printf in line 15 too! :

cout << setprecision(.2) << VAR1(25.95f);

Note: in order to use setprecision with cout, you also need to include iomanip after iostream..:
So after you've included iostream, add the following:

#include <iomanip>

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

Aha,
I've just fired up one of my linux boxes, I've created a project in codeblocks using your files. I've made my suggested changes and and tried compiling... And there are still compiler errors.

The problem seems to be regarding the base class members (from ArrayQueue.h) in the Deque class. For some reason g++ doesn't seem to recognise the protected members from ArrayQueue.h like front, back, count, items etc.

I'm not sure if there's a compiler switch to enable the compiler to recognise these correctly, but I've found that if you reference the base-class members using the 'this' pointer in Deque.h, then the compiler errors disappear.

Here's a snippet from Deque.h to show you what I mean:

template <class T>
bool Deque<T>::dequeueBack(T &itemRef){
	if (this->isEmpty()){//cannot dequeue
		//cout<<"Empty dequeueBack in Dequeue\n";
		return false;
	}
	else{//procede dequeuing
		itemRef= this->items[this->back];
		if (this->back==0)
			this->back = MaxQueue-1;
		else
			this->back--;

	}
	this->count--;
	return true;
}

Anyways, the program now compiles without errors or warnings on windows and *nix. A .zip is attached with my changes applied.

In order to ensure that my changes haven't introduced any bugs to your code (apologies if any have crept in there!); you might want to ensure that the program still works in the way you originally intended it to.

Cheers for now,
Jas.

[EDIT]
p.s. I'm fairly new to *nix programming myself...Up until recently I've only ever developed on Windows (so yes, I'm a bit wintarded!). The little *nix programming …

JasonHippy 739 Practically a Master Poster

Can Someone tell me why these files won't compile on unix but work fine (mostly) in windows?

It looks like unix-land doesn't load the variables from the inherited class QueueArray into the proper scope.

prog5.cpp is supposed to create 3 different types of Deque classes.
each Deque inherits from ArrayQueue

Your help is greatly appreciated =)
Thanks everyone

One thing that immediately strikes me is that you are using #pragma once, which as far as I am aware is a preprocessor command that is used solely by Microsoft compilers. So perhaps using traditional inclusion guards might help here. e.g.

#ifndef SYMBOLNAME_DEFINED
#define SYMBOLNAME_DEFINED

// The rest of your header code goes here

#endif // SYMBOLNAME_DEFINED

I'm thinking that because gcc doesn't recognise the #pragma command, it therefore sees no inclusion guards in your code. So perhaps that could be causing things to go a little screwy with gcc.

Also between lines 45 and 46 of the bool Deque<T>::dequeueBack(T &itemRef) function in "Deque.h" you need to add a 'return true', otherwise you'll get some errors or warnings from the compiler (in both *nix and microsoft environments.)

I've not got a *nix box in front of me at the moment, so I can't test this, but replacing all instances of '#pragma once' with traditional (gcc and MS compatible) inclusion guards and then adding the 'return true' to "Deque.h" would at least be a step in the right direction, if not the complete solution to your problem!

JasonHippy 739 Practically a Master Poster

Alternatively, if you only wanted the extra block to be shown if the value of the parameter was 3 then you could change this block from my previous listing:

if(i==myCondition)
{
	cout << "i = " << i << " and myCondition = " << myCondition << endl;
	cout << "This block of code only gets called when i == myCondition." << endl;
	cout << "Is that what you were aiming for?" << endl << endl;
}

to this:

if(myCondition==3)
{
	cout << "This only gets called when myCondition is passed in as 3" << endl;
}

And then your results will look like the attached .png
So now the extra block will appear on each iteration, but only if the value of the passed in parameter is 3

JasonHippy 739 Practically a Master Poster

Thank you for your answer.
In my example, MYCONDITION is known. But in my code, MYCONDITION is not. It's known only at the time of execution as an argument in the command line.

Then what you need to do is parse the command line and store the relevant arguments in variables and then use those variables to determine what happens in your code.

So perhaps something like this?

#include<iostream>
using namespace std;

#define MAXVAL 10

// program takes one argument and is invoked like this:
// program.exe {value for myCondition 1-10}
// e.g.
// program 2
// This will run the program and will display an extra message on the 2nd iteration of the loop
int main(int argc, char* argv[])
{
	int myCondition;

	// Check the command line parameters...
	// First ensure that there are only two arguments (filename and the value for "myCondition")
	if(argc==2)
	{
		// ok, we have the correct number of arguments, 
		// so convert the 2nd argument in the array to an int
		// and assign it to myCondition.
		myCondition = atoi(argv[1]);

		// Ensure myCondition is within our bounds
		if(myCondition<=MAXVAL && myCondition>0)
		{
			// now we'll loop 10 times and say hello each time
			for(int i=1; i<=MAXVAL; ++i)
			{
				cout << "Hello #" << i << endl;
				
				if( i==myCondition) // display an extra message or three!
				{
					cout << "i = " << i << " and myCondition = " << myCondition << endl;
					cout << "This block of code only gets called …
JasonHippy 739 Practically a Master Poster

Aha, I've just quickly tested it and it seems to work!
Here's a little program I knocked up, loosely based around previously posted code in this thread:

#include <iostream>
#include <algorithm>
#include <deque>
#include <ctime>
#include <iterator>

using namespace std;

struct Str
{
	int a,b;
};

bool deq_test(Str& deq1, Str& deq2)
{
	if(deq1.a==deq2.a)
	{
		return(deq1.b<deq2.b);
	}
	else
		return(deq1.a<deq2.a);
}

int main()
{
	deque<Str> deq;
	srand(time(NULL));
	Str MyStr;

	cout << "Generating values and populating deque:" << endl;
	for(int i=0; i<6; ++i)
	{
		MyStr.a = rand()%10;
		MyStr.b = rand()%10;
		cout << "a = " << MyStr.a << ", b = " << MyStr.b << endl;
		deq.push_back(MyStr);	
	}

	cout << endl << "Sorting Deque..." << endl << endl;
	sort(deq.begin(), deq.end(), deq_test);
	
	cout << "Sorted values are: " << endl;
	for(deque<Str>::iterator iter = deq.begin(); iter!=deq.end(); iter++)
	{
		cout << "a = " << (*iter).a << ", b = " << (*iter).b << endl; 
	}
}

And some sample output is shown in the attached .png.
Looking at the png, you can see that there are several values which have an 'a' value of 2. These have successfully been sorted by their 'b' values.

Problem solved??

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

I have already try this ... and i have not been able to successfully write the comparison function which would sort deque by both values.

With your code deque is sorted only by a value, so youl'll get
let's say:
02
01
05
13
11
15
21
20

instead of :
01
02
05
11
13
15
20
21

I've not actually tried this, but would something like this work for the deq_test function?

bool deq_test(Str& deq1, Str& deq2)
{

	if(deq1.a==deq2.a)
	{
		return(deq1.b<deq2.b);
	}
	else
		return(deq1.a<deq2.a);
}

In other words, if the values of deq1.a and deq2.a are the same, you sort them by their b values. Otherwise you sort them by their a values.

As mentioned, I've not tested this but I think it should work!
Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

Do you mean something like this??

numarray = [1,2,-3,4,5,-25]

for n in numarray:
    print "The inverse of", num, "is", num * -1
    #print("The inverse of", num, "is", num*-1)
    # use the above line if you're using python 3.x!

The output from the program is:

>>>
The inverse of 1 is -1
The inverse of 2 is -2
The inverse of -3 is 3
The inverse of 4 is -4
The inverse of 5 is -5
The inverse of -25 is 25
>>>

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

Ah hang on, I see the problem.....I should've spotted this off the bat! heh heh!

#include<iostream>
#include<string>

using namespace std;

 class STD1{
         int id;
         string name;  // you can't initialise it here because this is the technically the header for the class!
          char status;
 public :
         void pinfo();
         void ginfo();
};
void STD1::ginfo(){
        // but you could do it here
        name = string(""); // this should initialise name
        // alternatively, write a constructor for your class 
        // and initialise name there!
        cout<<"Enter ID : ";
        cin>>id;
        cout<<"\nEnter Name : ";
        cin>>name; // now the cin should work!
        cout<<"\nEnter Status : ";
        cin>>status;
}
void STD1::pinfo(){
        cout<<"Student Info Is ... ID : "<<id <<" Name : "<<name <<" Status : "<<status;
}

int main()
{
        STD1 m;
        m.ginfo();
        m.pinfo();
        return 0;
}

I think that might be what you're looking for!
Either initialise it in the ginfo function as shown above or add a constructor to the class and initialise it there!

So using the constructor option:

#include<iostream>
#include<string>

using namespace std;

 class STD1{
         int id;
         string name; 
          char status;
 public :
	 STD1(){name = string("");} // ensure that name is definitely initialised!
         void pinfo();
         void ginfo();
};
void STD1::ginfo(){
        cout<<"Enter ID : ";
        cin>>id;
        cout<<"\nEnter Name : ";
        cin>>name; // now the cin should work!
        cout<<"\nEnter Status : ";
        cin>>status;
}
void STD1::pinfo(){
        cout<<"Student Info Is ... ID : "<<id <<" Name : "<<name <<" Status : "<<status;
}

int main()
{
        STD1 m;
        m.ginfo();
        m.pinfo();
        return …
JasonHippy 739 Practically a Master Poster

Why don't you try using the shlobj.h function SHGetSpecialFolderPath to get the path to the users My Documents folder? It would save all of the messing about your doing there!

Try replacing the code in your main function with this:

int main()
{
    // get the path to the current users my documents folder
    // storing it in an LPSTR
    LPSTR userDocsPath = new CHAR[MAX_PATH];
    SHGetSpecialFolderPath(0, userDocsPath, CSIDL_MYDOCUMENTS, 0);

    // now copy the path into a std::string
    std::string path = std::string(userDocsPath);

    // delete the LPSTR as we don't need it any more...
    delete userDocsPath;

    // Now you've got the path to your users 'My Documents' folder
    // stored in path, you can append any further directories onto it. 
    // e.g.
    path.append("/OMG"); 
    // NOTE: using forward slashes works in file paths, double backslashes are not necessary!

    // Not sure you need to bother creating an 
    // LPSECURITY_ATTRIBUTES object seeing as you're setting it to null!
    CreateDirectory(path.c_str(), 0);
    cout << "\nFolder Created!\n";
}

For more info take a look at the following pages:
SHGetSpecialFolderPath:
http://msdn.microsoft.com/en-us/library/bb762204(VS.85).aspx
CSIDL values:
http://msdn.microsoft.com/en-us/library/bb762494(VS.85).aspx

Hope that is of some help!
Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

i use
string name="";
and
string name;

both give me diffrent error ...

What about this?......

string name = string("");

That should do the trick!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

Everything works except trace,
output panel shows:

Starting new compile.
Loading configuration file C:\Program Files\FlashDevelop\Flex_SDK\frameworks\flex-config.xml
Loading configuration file C:\Documents and Settings\rajarajan\Desktop\ProjectTracing\obj\ProjectTracingConfig.xml
obj\ProjectTracing633905373543906250 (999 bytes)
(fcsh)
Build succeeded
Done (0)
[Capturing traces with FDB]

OK, well the only thing I can think of is perhaps you aren't using one of the debug flash players...Only the content debugger versions of flashplayer will allow you to see trace actions.
The standard player doesn't show them.

Try going to http://www.adobe.com/support/flashplayer/downloads.html and download and install the flash player 10 projector content debugger.

Once you've got it, set your copy of Flashdevelop up, so it uses the content debugger as the external player. Next, reload your project and try building/testing it!
You should now be able to see trace statements!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

Yup you got it Raja, that's how you set up the path to the SDK and the path to the external flash player!

I've got my Flashdevelop set up to use the flashplayer10 debug executable!
Note: in the FlashViewer section of the program settings, ensure that the 'Movie Display Style' property is set to External!
'Popup' and 'Document' use the default player (fp 9 debug ActiveX)

In order to demonstrate tracing in flashdevelop, I've knocked a little example project together. (see attached files.)

To actually create the project, I've just gone to 'project->new project' in the menu and then in the dialog I've selected the 'AS3 Project' template and called the project Tracing.

Flashdevelop has now created a few directories (bin, lib and src) and files. Briefly exploring the generated files and folders:
The bin folder is where the final .swf will end up being built.
Initially the bin folder contains a html file which is set up to embed the final .swf using swfobject.js (found in the js sub-folder). It also includes expressinstall.swf, which is also used by the html page, in case people viewing the page have an older version of flash...in which case, it can download and install the correct version.

The lib folder is where you can put any assets for your project (Bitmaps fonts etc.). It should be noted that simply adding items to the lib folder does not make them instantly accessible to …

JasonHippy 739 Practically a Master Poster

Sorry I'm late to the conversation...Not been about today!

I'm on my linux box again, so I haven't got a copy of Flashdevelop open in front of me...But if memory serves, there is trace functionality built into Flashdevelop. It always used to be an external plugin, but I'm pretty certain it's finally been integrated into the IDE now.

Unfortunately, I think the trace functionality only works if the actionscript file is part of a project....It doesn't seem to work if you're building/testing a single standalone AS file that isn't part of a project.

Theres no need to create any .fla's or .swfs with CS4....No need for any of that at all..Although Flashdevelop does integrate really well with the Flash IDE's, so you don't have to completely abandon the Flash IDE if you don't want to. You can get the best of both worlds! Another advantage of having the Flash IDE installed (especially if it's the professional) is you can use the more advanced Flash components in your Flashdevelop projects! Anyway..going off topic there!

Where were we? Oh yeah!
If you want to use the trace functionality, all you need to do is create a new AS3 project using one of Flashdevelops built in AS3 templates...I'd pick one of the more minimal AS3 templates...(without seeing it in front of me I can't think exactly which template it is, but you should be able to work it out!)

Then start adding your classes to your project, …

JasonHippy 739 Practically a Master Poster

OK.
At the moment, Flashdevelop is only available for windows. (I believe there are mac and *nix ports in the pipeline...Not sure how well it runs on wine.). So Windows XP or Vista is the main prerequisite. (should also work on windows 7 too!)

The other main prerequisites are the Java 1.6 runtime and the flash player 9 active X runtime control (I think I use the debug version!). I think you might also need one of the .NET runtimes (2 or 3 I expect!). All of these are free downloads! If you're running vista or 7 then the appropriate .NET runtime will most likely be in place already.

Once you've got the pre-requisites installed, you'll also need the Flex 3 SDK...If you have Flash CS3 or CS4 installed, then the SDK is already installed somewhere (can't remember offhand what the default path is).
So if you have CS3/CS4, you need to locate the SDK and make a note of the path!

If you don't have CS3/CS4, or if you can't find the SDK, you can download the Flex3 SDK for free from Adobe. Once you've downloaded the SDK, unzip it somewhere on your hard-drive and make a note of it's location!

Next download and install the latest version of FlashDevelop from flashdevelop.org.
The installer is pretty straightforward...set your preferred installation options and away you go!

Once it's installed, fire it up and away you go!

Copy and paste the following …

JasonHippy 739 Practically a Master Poster

just thinking... wouldnt it have made more sense to just change "Program files" to "Program_files" or something similar?

Not really, because in MS Windows the 'Program Files' folder is the system default folder for programs to be installed in (and there are usually a lot of programs installed there!).

Simply renaming the 'Program Files' folder to 'Program_Files' would cause most (if not all) of your programs to either malfunction, or not work at all when you tried to run them.
The OS probably wouldn't take it too well either!

Plus any shortcuts you have for any programs in the 'Program Files' folder will also stop working...(e.g. desktop shortcuts and start menu links)

So in this case...No! Changing the folder name would definitely not be the best option. Ene's line of code is by far the best solution to the problem!

Cheers for now,
Jas. :P

JasonHippy 739 Practically a Master Poster
os.system('"C:/Program Files/IrfanView/i_view32.exe" ' + filename)

Dammit...I thought I'd tried that combination of string in string earlier..... Obviously that was one permutation I missed!

Hang on....Looking back at my failed scripts from when I was playing around, I had the " and the ' the wrong way around! Damn these fat drummer fingers! grrr! heh heh! :D

Thanks for that Ene! Yes that's far better than my solution!

Cheers for now,
Jas.