StuXYZ 731 Practically a Master Poster

Sorry, but most of these solutions are inelegant and that is because to achieve randomness they require an excessive number of random number calls:

(a) Shuffling the stack by selecting two cards and exchanging requires about 7 times the deck of length to get to nearly random on a 52 deck set, and more on a later deck. It is because you can't ensure that you avoid leaving pairs (do this with a deck of 1,2,3,4 ... etc and shuffle and see how many consecuative pairs you have.

(b) If you loop through the deck index in the forward direction and then swap, you definately want the possibility that a card does not move. BUT this shuffle is flawed. Take a deck of 26 0 + 26 1 in that order ie. 0,0,0,0.....,0,1,1...1 and then shuffle. If you do the shuffle once and then add the first 5 cards you get about 2.55 and 2.45 for the sums as you repeat to an infinite number of tests. [i.e. shuffle the deck, sum, reset the deck] * infinity. That is a significant fraction for a casino to lose. The drift to pure randomness is asymptotic.

(c) Use the algorithm shuffle. Depends on implementation but normally very good

(d) something that is random is this: [ well significantly better than either (a) or (b) ]

int deckIndex[52];
int deck[52];
for(int i=0;i<52;i++)
   deckIndex[i]=i;

for(int i=52;i>=1;i--)
  {
     // ugly: Use a proper random number system e.g
     // Mesene Twister. …
jephthah commented: nice +6
StuXYZ 731 Practically a Master Poster

Looks to me that you are not creating an instant of the template class
for <int>.

You have put the link body in a .cpp file. That is perfectly acceptable and good practice if the body is large. BUT you have not created an explicit instance of it.

So add
template class Link<int>;
at the bottom of your Link.cpp and I think that all will be fine.

Note: notice that your second case is actually a declaration to a function that is not used, that returns a Link<int>. Hence it compiles.

StuXYZ 731 Practically a Master Poster

You have several potentual problems :

(a) If you have an extra character at the end of the file (e.g. '\n')
Since you test fin.eof ONLY at the start of each sequence you probably read the array then find that you are not at the end of the file , read ONE extra character and reset the whole array with junk.

Fix : Remove the while loop.

Better method: Read the whole array in one go:

fin.read(seat[0],15*30);
// Now test to see if you read enough characters...
if (fin.gcount()!=15*30)
   {
      // some error handling
  }

That will be a lot quicker as well.

StuXYZ 731 Practically a Master Poster

However, you can use the std::distance function to determine the
distance between two sequentual iterators.
e.g.

std::vector<int> A;
std::list<int> B;
// ... populate A,B:
std::vector<int>::iterator AIter=find(A.begin(),A.end(),7);
std::list<int>::iterator BIter=find(B.begin(),B.end(),7);

std::cout<<"Distance Vector == "<<distance(A.begin(),AIter)<<std::endl;
std::cout<<"Distance List== "<<distance(B.begin(),BIter)<<std::endl;

// THIS DOES NOT WORK::
// std::cout<<BIter-B.begin() <<std::endl;

The list iterator is not random access so you can use +/- between iterators. But distance is ok.

StuXYZ 731 Practically a Master Poster

First off rayone is just random troll.

Second: Your problem is that you have (a) forgotten to put a endl
after the output and (b) forgotten that x and y are separate entities.
So you need

cout<<x<<y<<endl;

finally you forgot that after an if you need { }, so that the braces enclose everything that you want to do: You don't need { } BUT you can put it, if you have ONE statement. If you are unsure USE { }

This is your code in a working format. Note it only works for n=1 or n=2. You can with a loop make it general.

I have done one other thing. I have fixed x,y,n in the program. This is good practice. Your test program will now be quick to change/compile/run. You will not be slowed down by entering lots of values each time. When it works, compile for a different number or two, then when that works, deal with keyboard/user input.
This will speed up your development process.

// includes here... 
int main()
{
   char x('a');
   char y('b')
   int n(2);

   if (n == 1)
      std::cout<<x<<std::endl;
   else if (n==2)
      { 
         std::cout << x<<y<<std::end;
         std::cout<<y<<x<<std::endl;
      }
  return 0;
}
StuXYZ 731 Practically a Master Poster

Ok: Not perfect but a good attempt:

First off scoping rules:

if you have a class variable e.g.

class A {
    int index;
};

Then that variable is effectively hidden by this

class A
{
   int Index;
   void run(int Index) const { Index+=20; } 
};

Note that run does not change Index in the class but a local value.

Hence

void SetX (float x) {x=x;}

is wrong. You could have (a) seen this by writing the function using const. e.g.

void SetX(const float Xvalue) { x=Xvalue; }

Had you done x=x; then the compile would have complained.

B) you don't qualify classes within a definition. e.g
for your destructor Point::~Point() is wrong since it is withn the definition.

C) Scope again!!! pPoint is declared in constructor. it is not a member of the class. So it goes out of scope at the end of the
Structure constructor. Lost memory. Additionally you cant delete it later

Finally: You are getting boged down in new/delete etc. Please, use OO first. That means you write a Plane class. That takes one plane.
A plane can then have a number of points (if it is a limited range)
or three if it is infinite. (or a normal + distance if you like).

That way you will find that you enrich your point class to have dot product etc. and Planes can be stored in a simple flat array or …

StuXYZ 731 Practically a Master Poster

And your problem with this assignment is.....

Suggested reading:
http://www.daniweb.com/forums/announcement8-2.html

StuXYZ 731 Practically a Master Poster

The list you are after in in http://gcc.gnu.org/gcc-4.3/cxx0x_status.html

I am assuming that you are using 4.3.

However, I am sligthly mystified , I though that you can only write what you have if you are using static or const. If you have the C++0x reference could you/someone post it please. Many thanks.

StuXYZ 731 Practically a Master Poster

Sorry but anubis' process injection code, is normally used to put code into running windows processes for the purpose of running a rootkit. As far as I can tell.

So why should we help given the site rules and likely purpose. The only good news is you don't seem to know much.

If that isn't the case, then please explain further or we are all very unlikely to help. Please note the last section in:
http://www.daniweb.com/forums/faq.php?faq=daniweb_policies.

StuXYZ 731 Practically a Master Poster

If you are using that much memory, you will be much better off using the boost array/multi_array classes. Then you will be better off using Blitz.

Word of warning: write the code using boost/stl untill it works with smaller data sets. THEN use Blitz. Otherwize the error messages and other problems are incomprehensible.

StuXYZ 731 Practically a Master Poster

Well depite the fact that this looks awful, you almost definately have a
memory leak. You initialize line to fslen+10, whatever fslen is. Then you do not delete it.

However, as vmanes says, you are not giving us much to go on. I would, at the minimum post the class and related functions

StuXYZ 731 Practically a Master Poster

It still amuses me to see stuff like:

(after any other discount is subtracted).

It doesn't matter what order you apply you % discounts.

However, rather than that : this is c++ the advantage that gives you (along with many other languages) is you can code stuff as functions or classes. That helps break your problem down.

So maybe you want to think about it in terms of a function. So
write a function to take a number and apply a % change (either +ve or -ve). The you are half way there. you will benefit greatly by actually putting that function into a program that calls it, and allows you to test it.

you could also set up a function to determine the number of minutes between two times.

Then maybe write a class to set and get information like time start/time end/cost/fedral tax/discount etc.

That way you have more problems but they are all easier.

StuXYZ 731 Practically a Master Poster

I think you have made a mistake in your question. If you have
0..25 in your code your compiler will tell you that it is an error.
However, if you are trying to go from a string to a number the simplest way is to use a stringstream.

The problem with

std::istringstream IX;
double x;
IX>>x;

is that as you say 0.. and 34y will work. So you have to do some more work.

You need to (a) determine if the stream is emtpy or (b) determine if the stream's next character is a space (or other suitable separator). Either (a) or (b) would mean an acceptable number had been read.

StuXYZ 731 Practically a Master Poster

Answer is: Start again

You have

while (getline(cin, info) && info != "")
          { if ( isInVec(word[info.length()], info) == false) 
                 word[info.length()].push_back(info); }

Now word starts empty, so IMMEDIATELY, you access work[X]
were X is a large number. Then you push back to that place.
That is memory corruption.

info is a global string : That is horrible info!="" is better as !info.empty() I am not sure what you are tring to achieve but use .at instead of [] for your vector and it will throw exceptions when you make mistakes like above.

StuXYZ 731 Practically a Master Poster

In addition, replace the semi colon on line 21 with a colon ( : ).

Swap line 22 with line 23. That will avoid a compiler warning.

StuXYZ 731 Practically a Master Poster

First off: The polynominal class, it is a start but you have a number of things to adjust.

First off polynominals have three common types of coefficient: complex , floating point (double etc) or polynomial. Note the last one: if you want to express [TEX]3y^2+xy+x^2+1 =0[/TEX] then you will want that type.

Then how you design your class is dependent on what you want it to do. The important things are: do you want to find roots.? Second do you need to solve simultanious equations (multi-variable). What sort of integrals do you want?

Second consider this polynomial equation:
[tex]3x^{-1}+5x^{-2}=0[/tex]
Perfectly valid equation, easy to integrate in the complex plane, easy to find roots.

Now that suggests a number of fundermental changes to the polynominal class.

(a) First use either a low/high exponent values or use the original exponent form. [e.g. equation above is -2,0]
(b) Use a vector or variable length polynomial power system.
(c) Implement multiplication first, it exposes most of the short-coming of the other designs, without being too difficult.
(d) Then do division.

StuXYZ 731 Practically a Master Poster

You can't copy it to a set and back again without breaking the order.
Sets store on a compiler defined manor but normally red-black trees.
Hence you will destroy the order.

The easiest way is to copy to another vector sort, unique
and then find the copies.

Another slightly more involved way is to copy to a map in which you have the positions in the vector as the second component. The remove the clashes. Depending on the vector type a hash map may work better.

robotnixon commented: thanks for the help +2
StuXYZ 731 Practically a Master Poster

Nucleon is 100% correct that it gives "multiple definition of void Output<unsigned int>" on standard compliant compilers.

The standard says that if you put implimentations in a declaration then ALL used specializations must be availiable at that instance.

Some compilers do help you out here BUT it is not standard and you should NEVER program to a single compiler unless ABSOLUTELY FORCED.

p.s Many thanks to nucleon for reading my previous post, I am surprised anyone except the original poster read that far!

StuXYZ 731 Practically a Master Poster

Let me see what I think you question is, then answer that....
Not idea I know!

If you have a templated class and you put 100% of the implementation in the definition, shoudl you compile it in stages?

The answer to that question is that it doesn't matter. In a perfect world, with infinitely fast computers it doesn't matter since compiling takes zero time. In a real world, it takes a lot longer to compile so we split programs into parts, to get it to go faster.

If you put 100% of the implementation ino a definition AND
the class is large, then at each point that you include the definition you are going to have to pay a compilation large price. It still works BUT the c++ standard was written a long time ago when compilation too a LONG time and thus it allows the template instantiation.

If you compile all your code in one go, that is fine BUT you will take a lot longer each time that you make a change, than if you split it into parts and use a make file.

StuXYZ 731 Practically a Master Poster

Yes certainly you can do that but you have to resolve the instance at some point. So perhaps you want it is another templated class.

template<class First, class Second> 
struct foo
{
     First f;
     Second s;
};

template<typename A,typename B>
struct Other
{
  std::vector< foo< A, B > > bar;
  std::vector< foo< B, B > > barX;
};

Note that you still have to have the compiler figure out the exact versions that you will need. You have only delayed the choise.

StuXYZ 731 Practically a Master Poster

Summary to the last two points:

1) Inlined IF THE COMPILER inlines it. Does exactly what it says on the tin. It takes the code for the function and writes in the code as if the function does not exist. Effectively you compile that bit many time but it is ok since it is as if you did this

// withouth func inlined:
int func(const int I)
{
   return I+18;
}

int sum(0);
if (x==5)
   sum+=func(j);
else
   sum+=func(j);
// Same code but func is inlined
int sum(0);
if (x==5)
   sum+=j+18
else
   sum+=j+18;

As you see the func has gone, hence it works. with multiple repeats.

2) The official stl: Note you will learn a lot by having a look at the code. Try the simple stuff first e.g. vector, pair.
But they include everything in the class definition and the standard says that is ok as long as the definitions are all the same. In practice the compiler can't check that except and link time BUT normally it doesn't. [Exception is Portland, sometime!]

StuXYZ 731 Practically a Master Poster

Below I am going to post a working set of code.

The requirements are simple. You write an implimentation of foo and you put template class Foo<float> in that implimentation.
This is 99% portable and 100% within the standard. It works on portland, IBM, and g++. I don't have VC++ to test it against but I guess it will work there if you have it.

Next: The compile sequence is something like this:

g++ -c class1.cpp
g++ -c ultra.cpp
g++ -c foo.cpp

g++ -o ultra ultra.o class1.o foo.o

You compile one and only one instance of foo.cpp, which builds one and only one version of Foo<float>.

This route completely avoids the problem of hundreds of implimentations on each instances. Speeds compile time up hugely.
This is the normal route for any LARGE class which is only likely to have a few template instances. Sure with something like std::vector, you need to include it in a .h file since it (a) is a small class (b) has many different template instances in a code base.

// foo.cpp
#include <iostream>
#include "TemplatedFoo.h"

template <typename T>
//inline  <- works if uncommented
T Foo<T>::getValue() const{
  return m_value;
}

template <>
//inline  <- works if uncommented
Foo<float>::Foo(const float value ) {
  std::cout << "I do floats:\n";
  m_value = (value);
}

template <>
Foo<std::string>::Foo(const std::string val)
{
  std::cout << "I don't do strings:\n";
}

//THE BIT YOU KEEP MISSING: GOES HERE
template class Foo<float>;
// Templatedfoo.h
#ifndef TEMPLATED_FOO_H …
monkey_king commented: very helpfull and throughly +1
StuXYZ 731 Practically a Master Poster

You don't seem to have posted enough code for anyone to tell but are you using: m_pEcoAreaTeam = new EcoAreaTeam(); and then the class does not have m_pEcoAreaTeam and you have a scope issue??

If the class has m_pEcoAreaTeam check the spelling. And why the use a global m_pEcoAreaTeam or was that just to illistrate ?

StuXYZ 731 Practically a Master Poster

Does your problem persist with a instance in you Foo.cpp file??
e.g template class Foo<float>;

StuXYZ 731 Practically a Master Poster

Ok you have made several little errors/annoyances and one misunderstanding as I see it.

(a) First you #ifndef TEMPLATED_FOO_H does not finish

(b) You use a chained #include system. Please don't, it can be done but write .h file for the classes adn use #include's in the cxx. That will make g++ templates pleasing to read and readable in 6months time.

The major error: g++ has three ways of doing templates and you have not decided on any one of them.

Your can
(a) use -frepo : I don't because the compile time is horrific.
(b) You can include the whole class in the .h file and include it everywhere it is needed.
(c) use template instansiation.

I use (b) for container type classes e.g. Triple<A,B,C> which have lots of strange instances like Triple<int,double,std::string>. I use (c) for everything else.

You need a template class Foo<float>; at the base of your implementation of Foo. I am reposting a CUT version of your file that compiles.

#ifndef Foo_h
#define Foo_h

template <typename T>
class Foo
{
public:
  Foo(const T value);
  T getValue() const;    
private:
  T m_value;
};
#endif

and

#include <iostream>
#include <string>

#include "testAll.h"

template <>
Foo<float>::Foo(const float value ) 
{
  std::cout << "I do floats:\n";
  m_value = (value);
}

template <typename T>
T Foo<T>::getValue() const
{
  return m_value;
}

template class Foo<float>;

Note that if you want to use Foo<std::string> then you must add a template class Foo<std::string>

StuXYZ 731 Practically a Master Poster

Note: [Ark -- I know you know this] but I think it is worth pointing out.

If you think that you HAVE to put the template stuff in a single .h file this is wrong. It is ok and works but really really quickly leads to serious slow down on the compile.

You can also put the code for list (or any other template) in a .cpp file and include only the header in the .h. However, you then (unless you have a nice compile) have to explicitly declare your instances e.g.

template class list<double>; 
template class list<int>;

at the end of you .cpp file.

The main problem with this is that if you want a list<myClass> you have to include the header for myClass in list.cpp. There are ways round that using a third include file etc. but that normally isn't worth the pay back.

None of this matters for small project, but just look at what happens if you change a basic list in Qt3 you spend forever (+1hour) compiling since it is in SO many places. [the simplified a lot in Qt4]

StuXYZ 731 Practically a Master Poster

Ok there is no way for us to know the problem but you most likely have a macro #define size .... somewhere in the mess of headers.

Have you stripped this down to the minimum- does it still work.

If you put a line #undef size just above the PQueue::PQueue line does it still go wrong??

The code you have posted without the #include "junk.h" works fine.

Finally, if it is a #define problem, it shows one of the subtle ways in which #defines are evil.
If you had used a const int size(50); then the code would have worked perfectly, since the scoping rules prevent a clash.

StuXYZ 731 Practically a Master Poster

I think the fatal error says everything

Disc quota exceeded

I think it is time to talk very nicely to the system admin. or delete that large cache of movies.... ;)

StuXYZ 731 Practically a Master Poster

First off, well done for using code tags for your first post.

Second, your error is that you are returning 0 but actually need to return a string.
Try as the last two lines of padBlanks, this:

blank+=string1;
return blank;
StuXYZ 731 Practically a Master Poster

Syntax mainly:

Constructors use variable initializers and an additional code block
which happens after initialization.

i.e.

Customer() : id(0),name("X") 
{ // code block here }

the second version is wrong because you have an extra ().
(write long int please!).

The only other thing you are going to need is that initialization of c++ constructors is in order!

// WRONG CODE:
class A
{
    int a;
    int b;
 public:
    // THIS DOESN't WORK 
    A(const int I) : b(I), a(b+1) {}  
    // THIS WOULD WORK: 
//    A(const int I) : b(a+1),a(I) {}
};

Try the fragment above and you will find that a can be just about anything as b in uninitialized when b+1 is calculated. That because despite the order you write it in, a is initialized first as it is in the class first.

StuXYZ 731 Practically a Master Poster

Well first off, thanks for actually posting a proper program.

The following code crashes for at least four reasons. (all easily discoverable with 20 seconds with the debugger. [which is both why you should learn to use ddd/gdb, why you should compile with full warnings, and why you should post complete code]

The first error. in Runner::Runner(int,int,int) you allocate memory with malloc. Then in Runner::~Runner() you deallocate that memory with delete []. This is not correct and will result in memory corruption. What happens after that I have no idea.

Second: Trainer::random() does not work. using rand() gives a number between 0 and INT_MAX. BUT you have hand coded in int max on a 16 bit machine!! So you don't get a number between 0 and 1. That messes up many other things, e.g. base becomes lots.

Third: Initialization, you do none. So you end up deleting memory locations that don't exist. If you write a default constructor then write a proper initializer list.

Forth: assignment operators : operator=(const Runner&) is compiler constructed. BUT you have allocated memory. 99.99% certain to fail. Write one/ OR if you think it is not used declare it private. Then you will see that g=Runner() uses it. [And is a pointless create/copy/delete sequence.]

That fixes just about everything. Well I didn't worry about the results. But it runs without memory corruption.

StuXYZ 731 Practically a Master Poster

Sorry but it has been spelt out several times USE CODE TAGS.
Let me put it this way. If I see another post by you that doesn't do this I am simply going to add negative reputation.

As for the rest, your code it an improvement.

Now spend some time and tidy the code up. Make it look presentable, get ride of code that doesn't nothing. Look at it with the debugger. If you want to use this in a simulation, this code has to be 100% bullet proof. The you can think about writing a recycling simulation from population.

Now imagen that

StuXYZ 731 Practically a Master Poster

There are many things in this code that are very strange.

For example: what is the loop in Trash* operator()() doing. i.e. for(int i=0;i<30;i++) doesn't do anything because no matter what the switch returns on the first loop.

You REALLY need to have virtual destructors. generator_n does nothing because bin always has size zero. [note: it does execute one call to TrashGen with reinitializes the random number seed]

Don't uses rand(time(0)) more than onces in the code without a very good reason.

Clean up your memory before the program exits.

If I was adding a simulation, I would want to
(a) have a amount of each type specifiable.
(b) compact all the similar objects into one.
e.g. Aluminium with 10 units, and other with 12 can become 1 aluminium with 22.
(c) then have some code to evaluate the total weight and the total value of all waste.
(d) allow some to be removed/processed.
(e) have items come in with different types in different orders.

StuXYZ 731 Practically a Master Poster

The anwer is exactly as above, assuming that you want to put it into a structure. If you are not then you will have to write a less comparitor for it.

There is no fundermental different between your struct data , and your struct containing maze, in terms of the priority_queue.

The only problem is the coping of the class. You have to be careful about (a) the number of copies and (b) the way the copy is done.
If maze is big. then you are better storing a pointers to the structures. If it is small, be sure to write the copy/assignment operators.

StuXYZ 731 Practically a Master Poster

How is anyone suppost to GUESS what is wrong with that ??

There is no definition for Intstack but a cryptic comment about what is private/public.

Beginners using #define macros/parameters are heading for a (100-epsilon)% certainty of having incomprehensible bugs. Use const int or a function.

There are no declarations. What is ARRAY_SIZE, did you leave it undefined so you have [-1] on line 6?

You allocate memory (values2) and it gets dropped on program exit only. Really not good practice.

If you use macros like COUNTOF(values) [by the way what is values??? did you forget the 2) , especially as I can guess that
COUNTOF is something like

// DONT EVER WRITE THIS:
#define COUNTOF(v) sizeof(v)/sizeof(int)

I am beginnng to think that we need a stick post that says :
(a) Use code tags
(b) format your code so it look nice
(c) if you want people to find bugs post a complete example
(d) check that your example REALLY compiles if you are looking for a runtime bug.
(e) Spend some time simplifing your example and adding appropiate comments.
(f) Copy and paste DIRECTLY.
(g) Check you post.

You are asking people to FREELY give up there time and help, show them some respect.

To all sorry for the rant, I have read a large number of posts recently that I think fail to fill that brief.

StuXYZ 731 Practically a Master Poster

Well what is the recycling system? If you post some/all of that we can see what we can suggest. If you post your attempt then normally this forum will suggest what they think is would improve it.

A few iterations later you will then have really nice code....

Don't forget to use code tags, because that really really annoys everyone when you forget. [use the "go advanced button" to see effect.]

StuXYZ 731 Practically a Master Poster

There are three ways to do this:
(a) use the printf style

// Note thist must have at least one fixed argument:
void foo(int flag,...)
 {
    va_list ap;
    va_start(ap, flag);
    if (flag)
      {
         char* s = va_arg(ap, char *);
         double d=va_arg(ap,double);        
         std::cout<<"s == "<<s<<" "<<d<<std::endl; 
        va_end(ap);
       }
   return;
}

Ugly and there are not type-checks until runtime.

Second : get smart. What about how string works and have a function that returns an object of itself ie.

string operator+(const std::string&) const;
//...
string a,b,c,d;
//...
string X=a+b+c+d;

Then there is template land. Now the obvious way to do it is via a typelist or a tuple and since lyou have one class. That says the boost::tuple class is going to be how to go.

StuXYZ 731 Practically a Master Poster

What you have done is perfectly doable, but not the way you have done it.

First: Why yours is wrong: priority_queue<int,vector<int>,less<int> > pq; We see here that priority_queue is storing type of int. BUT at lines 19 and 22 you are pushing a struct of type data.

But you can easily do this

#include <iostream>
#include <vector>
#include <list>
#include <queue>

struct data
{
  int year;
  int n;
};


class compGT
{
public:

  bool operator()(const data& A,const data& B) const
    { return A.year>B.year; }
};

int main()
{
  std::priority_queue<data,std::vector<data>,compGT> pqC;
  data m;
  m.year = 19;
  m.n = 12;
  pqC.push(m);
   
  m.year = 119;
  m.n = 22;
  pqC.push(m);
  
  std::cout<<"Smallest data:"<<pqC.top().year<<" "
	   <<pqC.top().n<<std::endl; 

  return 0;
}

I have used an external comparitor functional but you can just as easily use an interal operator<. You can compare on both year and n or some complex function should you wish.

I have fixed a number of basic errors, that is beginning to tell me that you are getting a little out of your depth. That is ok, but remember to be continuously thinking about the basics first. That means REALLY reading the error messages your compiler is giving you.

(i) You return a pcC.top() item to the operator<< but don't provide an operator<< that works with data.

(ii) You push back a type (data) rather than an object m.

StuXYZ 731 Practically a Master Poster

The problem with that line is not that it is in not in function but this:

You have defined

template <class T>
ostream& operator<<(ostream& out, Matrix<T>& m)
{
  m.output(out);
  return out;
}

BUT you need to use it in a context that requires const Matrix& since you are returning Matrix<T> from operator-() . You can fix the problem by adding const to the Matrix<T>& part.

p.s. I wish I hadn't downloaded the file and looked...

Please consider that 1e-16 != 0 . Now think hard, how is that going to effect your code.

There are other things but .... fix the base first.

StuXYZ 731 Practically a Master Poster

Additionally, to the errors above: Errors on initialization.

bool solved;
  int i,j;
  if (solved)  // ERROR: Un-initialized variable
    {
      return;
    }

You have a faliure to limit range on
line

// Find next empty value
  for (i=0; i!=9; i++)
    {
      for (j=0; j!=9; j++)
        {
	  if (rows[i][j] == '-')
	    break;
        }
      if (rows[i][j] == '-')   // ERROR j == 9 here and is out of range
        {
            break;
        }
    }

You call block() with i=0, j=0 but your switch [Very UGLY] takes 1-9 and has no default to tell you you have an error.

That results in a memory violation later.

There are others, but please please (a) use -warning-all or (-Wall for gcc). ie. put the warnings in and assume all warnings are errors.
(b) run through a debugger.

StuXYZ 731 Practically a Master Poster

Sorry but the "but it is proprietary technology" is complete junk.
What made me irritated, was that you couldn't be bothered to post a working example of the problem. Sure if you don't want to post proprietry code then just base your example on it. BUT MAKE IT WORK. MAKE IT COMPLETE

You have learnt very little about your problem and we have gained no new insight into stl problems/interesting code etc.

What you are doing using an old code like that especially in the field of genetic algorithms, you are going to suffer, since a lot has been discovered since 2000.

Additionally, if you are using proprietary code for you Phd thesis, expect two things (a) that an external examiner will want to see the code -- but then because he is old etc will want to give it to his grad student etc. (b) that the next person who hires you will want to help eductate his/her group with your techniques. Both of these are going to be very very unpleasent experiences with your proprietary code.

StuXYZ 731 Practically a Master Poster

Before I tell you what I think is wrong I am going to tell you what I think has lead you to not being able to solve this.

First: the layout. It is a mess. Code has to be tidy. I understand you are most likely not a CS grad but please take some pride in your code. It should be the same as your lab work etc.

Second: the try blocks. Put ONE round the whole lot. You then refine later.

Third:

catch(bad_alloc)
{
    cout << " MUTMEMLIMIT ";
     try{
        mutcross_sig.push_back(0);
        }
}

Are you insane - What do you think is going to happen now! You have freed no large block of memory, (since the code above is singular addition.) This is just a 100% mess.

Fourth: Include string.h/math.h is about 10 years out of date.

Five: using namespace std; as a global is asking for trouble.

Six: This doesn't compile, it is not that you just couldn't be bothered to copy with the mouse and that you forgot whole section of classes. Trainer refers directly to stuff in runner etc.

Seven: What is this loading string, then using char[40] to get a filename...

Eight: How many times do you create a large 2d vector THEN create another version in a copy. e.g. vector<vector<float> > Runner::load_training_data()

Nine:

training_data = vector<vector<float> >(n_trainings, vector<float> (total) );
training_data = load_training_data();

So excellent create something into training_data and then forget it and write something new.

Ten: You are …

StuXYZ 731 Practically a Master Poster

I thinks you just need to add { } round the loop part.
You add up count each time but then only output n at the end.

If you output n for each step of the loop you will get exactly what you want.

StuXYZ 731 Practically a Master Poster

First of all play with pointers until you REALLY understand, if you are doing sufficient C++/Computer science failure to understand pointers, dereferencing etc. is going to leave you in tonnes of trouble. [The advantage of being old, is that we had to grok pointers, in assembly aged 10 (to crack the latest 32kilobyte game) :)]

If you are confused with pointers, then start small. Move just one item. If you can do that (and print out the stack). Then can you move two. Then can you move an item twice, and then three times etc.. then move one item a random number of times..

Post some code as you do each stage and get stuck and you will quickly get it [or decide to change major ;) ]

StuXYZ 731 Practically a Master Poster

Probabily not what you want -- But why not have an object class that holds the strings and whatever else you need. Then have each of the classes C+Element as you have except that Element has a pointer to the container class. [version of the handle class -- see Ruminations on C++ -- Koenig amoung many other places.]

However, I am not a professional software designer so I would defer to them and anyone with lots of real experience.

StuXYZ 731 Practically a Master Poster

Let us start with this:

void rightRotate(int *y, int n)
{
int temp ;
for (int i = 1; i<= n, i++)
{
 temp = y[i];
y[i] = y[n-i+1];
y[n-i+1] = temp;
}
}

I am 100% certain you have absolutely no idea what this does.

First is does not compile, you need a ; after the i<=n not a comma.

The loop runs from 1->n BUT arrays are arranged 0 to n-1 in c++/c.
Yes you can call it like this

int x[10];
rightRotate(x-1, 10);

but seriously unreadable.

Finally the function does absolutely nothing. Since you go past the mid-point and undo your swap!!

So TEST YOUR CODE. Then you will begin to understand. That means figure out what you code SHOULD do and write a test and compare.

So to answer your question the best way to write the code is as follows: ;)

void rightRotate(int*,int)
{
}

I would suggest that you test the second code fragment. Get it to do something and then let us know what you were trying to achieve.

StuXYZ 731 Practically a Master Poster

If you need sqrt of a matrix you are going to need serious heavy duty numerical/symbolic matrix code. If it is numeric then use uBlas.
http://www.boost.org/doc/libs/1_37_0/libs/numeric/ublas/doc/matrix.htm

There are simpler forms that probabily are ok, you can always get it by taking a SVD of the matrix but is often non-optimal. There are lots of requirement on the input matrix as well.

If it is symbolic then google is your friend. (or mathematica).

StuXYZ 731 Practically a Master Poster

Please note that the code you have is 99% wrong.

Consider

Polynominal A;
A=A;

And before you say you would never do that, be very very careful of compiler opimization, double loops that i=j (e.g. for(int i=0;i<N;i++) for(int j=0;j<N;j++) and many other places.

You should write FOR EVERY operator= (-- with a MINIMUM of a paragraph of comment if you break the rule) this:

Polynomial&
Polynomial::operator=(const Polynomial& A)
{
    if (this!=&A)
      {
          // coping stuff
      }
    return *this;
}

Additionally, since you are actually in the class I stronly suspect that you don't need the

for (int i = 0; i <= rtSide.degree(); i++)
		this->setCoefficient(i, rtSide.coefficients.at(i));

which is ugly since you use setCoefficients but access coefficient directly.

but rather just

coefficients=rtSide.coefficients;

you might need to add a little index/other parameter control etc
but it is likely to be much quicker AND much less error prone.

StuXYZ 731 Practically a Master Poster

That is no fun comatose!!!! The program should write itself without reference to the source code!!!

You want to look up quine

e.g.http://prokutfaq.byethost15.com/Cquine

I distinctly remember the first time I saw a quine program,. fortran-77 -- I am getting old :) -- and I was very happy when I finally groked it.

Comatose commented: :) +10
StuXYZ 731 Practically a Master Poster

First, well spotted nucleon for the additional semi-colons
But there are other horrible errors here.

First off I am surprised that you don't ask about the doubled/redoubled status, it affects scoring greatly.

Second, you should use any of the editors that lay out the code/or do it by hand AND used GNU style or any of the styles that line up the { }.

Then you would see for example, that you initial test if(winner!='N' && winner!='S' && winner!='E' ... doe not close after the comment and the return. Let me write it out how my editor sets it out.

if(winner!='N' && winner!='S' && winner!='E'&& winner !='W')
    {
      cout <<  "Directions must be N, S, E, or W.\n";
      return 0;
      // The line below is indented to far: [forgotten } above] 
      cout << "What won the contract? " "(Such as 2 H or 3 NT): ";

So you see that the next question is already in the loop.

Thirdly, you are drowing in miles of code in one function. First write the code WITHOUT all the checks in for "if the input is correct". THEN when it works for good input, go back and put in the checks. What you will then find that you can then read the logic of the code and the layout will show you the error of you logic.

Finally, before putting back the test, think about writing a function to do the checks. It will …