StuXYZ 731 Practically a Master Poster

Well that is not much of an improvement!

You have left the get() in. You haven't bothered to print out
ch to find that it is always the FIRST character on the next line.

You didn't read what getline does. It consumes the '\n' character.

You need to either (a) learn how to use the debugger.
(b) write a lot of std::cout<< statements.

I asked three questions:

(A) a to put getline (well you sort of have)
(B) to find out how many times it goes through the loop
(C) the line that your code failed to read.

You failed on 2/3. I used to use logarithm marking when I had students so that makes you on ln(1)/ln(3) == 0% More effort required.

StuXYZ 731 Practically a Master Poster

Whoa, I would NEVER have thought of that string issue if you wouldn't have told me. I'll look into it but just a few questions while we're at it:
1) How do you explain that it works when I first write to the file and then read,

Well that is not an easy question since my version of your code doesn't. BUT if when you read/write, you look like you may have caused string to reserve the same length. It is also possible that
you are writing junk to a piece of unused memory. (not that string is referenced counted, so you should check that changing the original AFTER your read/write doesn't change the string on the later -- that would be another unexpected corruption.

Note you may get different behaviour dependent on you compiler optimization flags, your compiler choice and which implementation of the STL you choose.

2) With the "<<" thingies, you're suggesting I turn my binary file into a text file, don't you?

Yes. But how can you tell the difference (AFTER it has been written)
of a binary file with the characters
"abc" or a text file with the characters "abc". :)


3) Can't the string issue be solved by using char arrays of predetermined size?

Yes -- Careful because that sort of thing is very easy to get wrong in different ways.

StuXYZ 731 Practically a Master Poster

The lack of initialization is a problem I fully concur with.

But your maths is junk.
You are multiplying a side length an angle in degrees!!!
Try some trig.

You want to do it is set

x_coord[i]=x_coord[i-1]+side_length*sin(angle);
y_coord[i]=y_coord[i-1]+side_length*cos(angle);

Note that you are setting the next point based on the previous.
Obviously, you might need to set the first point, and you might need to convert from a centre point representation.

And remember to convert angles to radians.

Additionally, write a short point class for 2d and 3d points because it will make life much easier later.

The code above does scale for larger objects.

StuXYZ 731 Practically a Master Poster

Sorry but I am going to disagree with Freaky_Chris for the second time in two days! I hope he realizes the I agree with him most of the time :)

Anyway, you MAJOR sin is to think that reading into a class which may or may-not allocate memory will work. Let us take an example:

class X
{
   int * array;
};

Now the size of class is undetermined. You don't know when the size will change. So NEVER do a binary read into a class/struct unless you have absolute certainty about the size. Practically that means no pointers to memory, no STL object (e.g. vector or string) since these reserve an unknown amount of memory, no classes with static objects.

In your case you read from User. And look it has std::string. And wait, std::string often uses reference counting and static members, so that you corrupt memory is no surprise.

Your best bet is to read each item one by one. e.g.

void write(std::ostream& OutS)  const
{
    OutS<<username<<std::endl;
    OutS<<password<<std::endl;
    OutS<<verified<<std::endl;
    return;
}

void
User::read(std::istream& Input)
{
    Input.getline(username,'\n');
    Input.getline(password,'\n');
    Input>>isVerified;
    return;
}

That will actually give you LESS bytes of output than a binary dump.

p.s. you had better add some error checking to the read method, and you could implement some operator<< and operator>> methods if you like.

[Note: To the experts: I know you can do the binary writing and reading but that is because you know exactly how to do …

Freaky_Chris commented: Hehe, agree with me when you have a reason. I' self taught so i lack alot of knowledge and college takes alot of time of my ability o read around. I always appreciate extra material to read +1
StuXYZ 731 Practically a Master Poster

Well first off you are trying to get a protected object.
Second even if the object was public you are trying to get it as a static object.

So you need to (A) make the object static and then it there is only one version in all instances of the class. [sometimes used to implement singletons for example] You get one initialization (never in a function) before your main() is called.

(B) make the object public and then access it via an instance of the class (each instance is different).

(C) Make it static AND public. Then you get an initialization (obligitory) and you can access it when you like.

You need one of the following:

namespace NY
{
class X
{
   private: 
     static int Item;
   public:
     static int Number;
     int OtherItem;
};
}


int NY::X::Item=1;        // valid as static initializer
int NY::X::Number=3;   // also valid
int main()
{  
NY::X xobj;                   // create an obect of type X
xobj.OtherItem=2;      // Valid as via an instance of X
NY::X::Item=3;            // NOT valid
NY::X::Number++;      // VALID
int NY::X::Number=4;  // NOT valid (this is initialization)
}

Namespaces are just globally or locally visible scoping rules. Use them as such. They are not class/struct/union.

StuXYZ 731 Practically a Master Poster

This is easy.... Count
If you get below zero then you have failed,
and if you get not-zero at the end you have failed.
You might want to check scope bridges. I.e.
icode}[/icode] which I would pass as fail.
but that is easy to modify the code below to include.

Example of pseudo code for JUST ( and ).

string A = "(expession) with ) ( ";
int b(0);
for(int i=0;i<A.length();i++)
 {
   if (A[i]=='(') b++;
   if (A[i]==')') 
     {
       b--;
       if (b<0) failed();
     }
} 

if (b!=0) failed();
success();

Additionally, I am sorry BUT you cannot use boolean values as suggested by freaky_chris since
the expression ((x+y)) would fail. And that is not acceptable.

StuXYZ 731 Practically a Master Poster

Ok Now you have updated your code. Post what you have and the error message. However, I will be seeing getline :S , won't I?

Then tell us who many times it looped through etc, and the output
and the line that it failed to read from your file.

I am afraid I concur with Freaky_Chris, you didn't use a debugger, or you would have known that you hit the fail state when you got to the
while in the first post. Debuggers DONT "come back with no errors",
they help you step through the code, and see the state of variables/classes/memory at instants in the execution sequence.

StuXYZ 731 Practically a Master Poster

I can't, our instructor wants us to use the end of file method to check the text file. The loop seems to run through the while loop once, then stops, but if I search for anything beyond the first three lines, it won't echo it, so I'm thinking the problem is with the if statements, but I'm not 100% sure...

Your PROBLEM is that you are not using a debugger. I cannot state that too strongly. If you are on Linux then try ddd. If you are on windows, there must be good free debugger, don't do anything until you have found and installed one. If need be ask here or anywhere else [Start a new thread]. This is why you do not know what is causing the problem.

My mistake was not seeing that your code can get to the fail state in a number of other ways. (i) If you have a blank line (just '\n') AND it is not on the three line boundary then you can hit the fail because of the function get() will set that when if gets no characters.

Solution:

(i) use getline
(ii) Bin your peek and the whole of that while loop.
(iii) Never write [icode]!content.eof()[/icode] ever again. (unless you are separately handling fail )

Alternatively:

you can use the code you have written without the ch=get();, but you need to use your ignore loop after EACH read.

The second solution is nothing but ugly.

StuXYZ 731 Practically a Master Poster

C++ streams have to be treated with a little respect. You have assumed that the only error condition is eof. That might be true if you were reading into values BUT you decided to use peek. Peek CAN set fail().
You do not check eof BEFORE the peek so when you are at eof THEN you go to fail.

If you put replace while (!content.eof()) with while (content.good())) . The program does not sit in an infinite loop.

BUT WHY did you not just use your debugger???? I mean that is what they do so well, run the program and interrupt it and see what has gone wrong, maybe step through a few commands.

Finally, look up getline in the istream class. It will help make you program a little tidier.

StuXYZ 731 Practically a Master Poster

First off you need to read the srand information on the web
try http://www.cplusplus.com/reference/clibrary/cstdlib/srand.html and understand that you are setting a seed.
That means do it once and unless you want the same numbers again do not do it twice. Since you are setting it with time(0) and most short programs take less than 1sec to run you will re-set the random number seed to the same number if you use it twice in the program.

Additionally, if you look on the web page you will see that srand takes an integer so why you are trying to cast is to something I have no idea
use: srand(time(0); or use srand(34567); were 34567 is an integer of your choosing so that you get the same number each time. (Excellent for debugging). Put the single call to srand in main() so that you are certain it is called once only.

You have a number of other errors and since this is a c++ forum you might want to think about getting you code into some object orientated form. e.g. have card class and a deck class maybe.

Additionally, I don't understand the rand() % 14 part since you have 28 cards but maybe it is just that I don't know how to play war (and I haven't look it up).

StuXYZ 731 Practically a Master Poster

sorry but the book is correct. It is a double pointer because it represents a set of strings. For example it might be

/* Effective what it is. Not real code */
argv[0]="this program";
argv[1]="option";
argv[2]="another option";

It is perfectly correct to ask stuff like what is the eighth character in the second string e.g. char x=argv[1][7]; Also note that you are not responsible to freeing the memory for argv, and that argc tells you the number of strings, but you have to test the length of each one (strlen) if you want to use them reliably.

Finally, many people like to write it int main(int argc,char* argv[]) and that is perfectly acceptable as well.

StuXYZ 731 Practically a Master Poster

You haven't posted enough to figure thst out certainly.
My guess is that x and/or bestP are double/float etc and you are committing the cardinal sin of using == with floating point numbers.

I am guessing that x is very very close to bestP but that one is held in a register. The printf causes x to be dropped out of the register onto a memory location (i.e from 80 bit to 64 bit) and then == returns true. It should also work with any other complex command.

If this is the case, please read my post in http://www.daniweb.com/forums/thread160698.html

If not, please post a little more code including the definitions of the variables. Maybe make a short test case.

p.s. Please use preview post to get the [ code ] sections correct.

StuXYZ 731 Practically a Master Poster

Assuming that you have a source array that isn't abc... then you want to do it with one + one loop. I don't know why you read only 26 characters from the keyboard line. What if I have a long sentence ...
If you have a loop in a loop say for an input of 500 charaters and 26 letters, then you have 500*26/2 as the number of operations (assuming you find the letter you are after in 13 tries on average).
That is a huge overhead

So you create a mapping of a->? and b->? in another array and then
pass your input line.

You will need to get the correct look up for the array carefully done

outputLetter = newTarget[inputLetter-'a'];

Some care will also be needed on the issue of capitals and non- alphabet input, etc.

StuXYZ 731 Practically a Master Poster

The obvious (to me anyway) way round this is to create a
base class to either message or to dataPacket.
e.g.

struct baseMessage
{
  int messageId;
  int senderId;
  int recvId;
};

template<typename TX>
struct message : public baseMessage
{
  dataPacket<TX> data;
};

Then store a pointer to the base-class and get everything by
virtual functions / dynamic_cast etc.

If you intend to do this, have a look at the boost::any class as it effectively does that for you without having to write any code.

StuXYZ 731 Practically a Master Poster

Floating Point Result

I would like to comment that the issue of getting 0 or getting 5.77e-17 is mainly a CPU issue. Intel and AMD use 80bit registers. This hides and creates a lot of numerical rounding error.

This is a nightmare in numerical code since as the code gets interspersed or threads are used or recursion is used, you don't know when the compiler requires to move that 80bit temporary into a memory storage at 64bit. However, at 128 bit (long double) it is certain and that make life a little easier.

Additionally, if you use gcc/g++ then you can use -ffloat-store to avoid the register problem and that gives you the correct IEEE result of 5.77e-17 (long double) and 0 for (double). [Note that -ffloat-store can be a seriously CPU expensive option]

If you use long double then the results tend to be more IEEE based. If it matters to you then use the correct compiler flag.

Tolerance

I also would like to seriously caution you from using either fabs(A-value)<1e-10 or such similar device. This has a habit of begin very difficult to get right over a large range. There are several alternatives and I normally use the boost::test::tolerance class
http://www.boost.org/doc/libs/1_34_1/libs/test/doc/components/test_tools/floating_point_comparison.html.

StuXYZ 731 Practically a Master Poster

Think about how you add up. Suppose I ask you to add the
number in the series 2,6,9. you don't go let me put the numbers into
an array. you simply keep a running total,

So in your case

start a total
total=0
then IF the number is >0 add to total
divide total by the number of >0 numbers (or 42 ;-)

Just because it is programming it doesn't mean that you can forget you kindergarden maths.

StuXYZ 731 Practically a Master Poster

I'm trying to get the game below to work with 2 players. It's setup the way I need it (even the entering the numbers for the die instead of using a rand function and not allowing the bet amount to change(crazy teacher))

First off you teacher is trying to save you some complexity. Complexity KILLS.

Second, Assuming that you seem to have done some c++. I think this is an excellent example of the break between old-style procedural programming and the beginnings of object orientated programming.
You can to this problem in a procedural way BUT it is easier to do it in an OO manor.

Thirdly. I suspect that you were initially asked to write a craps game and then asked to modify, which reinforces the difference. It is important that those who started very OO at the beginning are laughing and those that didn't are facing a big re-write.

Solution:

What all mathematicians know (instinctively), is that there are only
three number 0, 1, and infinity. 0 is an easy case (no-code) and 1 is what you currently have. 2 or many makes no difference it is the same.

For example you have a variable BankBalance. What you want is a BankBalance for every player, you have a Wager, you want one for every player.

You need to do several things.

(a) write a class for player. That has the things that are associated to the player.

(b) …

StuXYZ 731 Practically a Master Poster

I am going to comment on the maths/computing interface.

You have two problems here, first is that although mathematically correct, the formula [tex]\frac{-b\pm\sqrt{b^2 - 4ac}}{ 2a}[/tex] is is awful as a computational base, since, as you partially discovered, if a or c are very small you get junk.

So you set
q=-\frac{1}{2}(b+sgn(b)\sqrt{b^2-4ac} )
and the roots are q/a and c/q. (sgn is the 1 if b>0 and -1 if b<0)

Note: additionally you need to check the condition that
b^2-4ac\ge0 or do the calculation in the complex plane.

Additionally, this still holds if the coefficients (a,b,c) are themselves complex or quaternions. (the condition is different).

There are many numerical discussions in scientific literature on
(a) approximating this (to speed up the calc at the cost of accuracy)

(b) the issue of machine accuracy. google scholar is helpful, but a membership of the ACM digital library is also going to help [and it is expensive].

(c) Numerical Recipes for X, have a discussion in chapter 5. http://www.nrbook.com/a/bookcpdf.php Note: I have given the link to the free to download pdf of the 2nd edition. You pay money for the third editions and NEVER put NR code in production code, as it is rarely robust.

p.s. I am not a proper mathematician. So if you talk to a REAL mathematician he/she will complain at my imprecision.

vmanes commented: Good comments on the math +7
StuXYZ 731 Practically a Master Poster

Hi,

Ok this is a post about HOWTO find your errors, which will result in actually finding one of your problems, but it is more a breakdown of what you should be doing.

(a) Ok write some output and it doesn't work.
(b) See that your input look ok for now. [It is random ish]
(c) What function is called first and what does it call.
-- Merge_sort
-- merge_sort and merge at the end.
(d) Is the input for merge ok.
-- put a return list at the top of merge().
(e) Check that left and right are correct AFTER one iteration.
-- put a return left; after the first loop in merge().
--- PROBLEM. This returns 1,2,3,4,5

Observe that you have written push_back(i) NOT push_back(list[i]) Further, note, that there is a std::list and since you insist on using using namespace std; I am 99% certain that latter that is going to bite you in the foot. [Not yet since you haven't included list but I am sure you will when you optimize it.]

Note that is not all of your problems but shows you how to go about debugging a problem.

Additionally, I would almost certainly start with setting the initial array to say 1,2,3,4,5,6,7,8 and then a random mix of those numbers.

Hope this helps. I would like to think that the rest of the bugs in your code are not just …

StuXYZ 731 Practically a Master Poster

Remember the K&R masterpiece:

while (*dest++ = *src++);

Unforgettable Algol 68's genes are still alive in C and C++ ;)...

can I just add, you need to remember to add a *dest=0; line after the while. You will need something similar in any of the other posts.

StuXYZ 731 Practically a Master Poster

Please read the posting FAQ. Then try again AFTER cutting down this junk to a small testable sub-program that shows the same errors.

Also I am not answering post that put "Please help as soon as possible , as i have to complete the project". It is your assignment and your problem.

Finally, describe the problem AND things you have tried. (e.g. after googling your error message, you will see 500 suggestions (all the same)).

[While you are at it -- google about the physics you are describing so badly.]

mrboolf commented: good advice :) +2
Salem commented: Absolutely! +23
StuXYZ 731 Practically a Master Poster

Oh I am sorry but I have just LOL big time!!!

You forgot to compile and include smartDuck.cpp and player.cpp in you makefile.

Well in light of that I would suggest that your next project look at splitting the program into shared libraries built in sub-directories and using some Makefile builder.

For this project, just add a player.o and smartDuck.o to your makefile and remember to add it to the link line.

p.s. Debugging with the -O2 option is pretty hairy, I would drop that from your makefile [Except production release, but then you drop the -g]

Sorry to put you through the trouble of sending a whole project file.

StuXYZ 731 Practically a Master Poster

As written there is nothing wrong with this (except I think that you would benefit from a typedef. e.g.

typedef std::map<std::string,int> mTYPE;
mTYPE aMap;
//....
aMap.insert(mTYPE::value_type(word,i));

However, I would guess that you have swapped the declarations of fileMap and freqMap.

It that is not the problem, please make a short test program and post that.

StuXYZ 731 Practically a Master Poster

But can you inform me why that worked now? I want to be able to understand what im writing instead of copy and pasting. Thanks!

Ok, well you have gone up in my estimation. So let me see what I can do to answer the question. [feel free to ask for clarifications/questions]

The C++ standard says that you cannot jump over an initialization statement (implicit or explicit). [ISO C++ 2003 6.7]

Interestingly, this means you cannot write

// This code will fail to compile
goto label;
int a=4;       // NOT OK.
int x;            // OK 
label:
int b=10;
// .. more stuff

The switch statement is such a code block (effectively). As I understand the reason, it is because the case points are actually effective labels. The worst example of that I have seen is Duff's device. It is on line everywhere and it is in the C++ book (as a question!!). . But is uses a do { } while block with case statements within the do while!.

This is a start on a long road of strangeness. C++ has a strong tension between compiler writers / low-level access / high order coding. It is places like this that it comes to the fore.

Salem commented: reps for analysis, and mentioning Duff :) +23
StuXYZ 731 Practically a Master Poster

The original question set out the problem. What happens when a non-number is entered. e.g. the user types "a" by mistake.

Unfortunately, preet4fun's code does not address that problem, it traps into an infinite loop if that is the case. All the other posters identified a path to a solution. The difficulty is in expressing that succinctly.

StuXYZ 731 Practically a Master Poster

I think that it is easier to get the input as a string and then parse it using a stringstream. If that is successful you have a number. If not then you don't. The problem with isdigit etc, is say you want to enter 1.43e-7. Failes on e and -. [yes it works for positive integers/ but not double or complex, or anything negative etc]

So have a look at this bit of code. If anyone can see a simpler way please post. But all the edge cases are an issue.

// returns 0 on success -1 on failure
int getNumber(const std::string& A,double& N)
{
std::istringstream testStrm;
testStrm.str(A);
testStrm>>N;
if (testStrm.fail())  return -1;

const char xc=testStrm.get();
// was the stream completely consumed or did we reach a space.
return (!testStrm.fail() || isspace(xc)) ?  -1 : 0;
}

Obviously that can be converted to a template function easily.

It takes input of a string (use getline etc) and successfully takes
"-3.4e-2" and fails (correctly) on "3.4g". That is important since
if you do xStrm>>N; that sets N to 3.4 regardless of the trailing g.
It succeeds on "3.4 " as well and additionally " 3.4 ". Again both expected behaviour.

You might like to change the code, not to change N if the tests don't succeed, in which case use a temporary.

If you want "3.4 4.5" to fail, then you have to test that all remaining characters are not a space. (while …

StuXYZ 731 Practically a Master Poster

As has been repeated many times in the last few days.
You cannot declare anything in the outside scope of a case statement.
you need either to put cList outside of the switch or use something like this

case 4:
   {
      ofstream cList;
      // ..... stuff
    }
   break;
 case 5:

Also please put break; after each case.

StuXYZ 731 Practically a Master Poster

Actually, it is simply to use

gcc -shared -o libmyshared.so file1.o file2.o

Have a look at the gcc manual. http://gcc.gnu.org/onlinedocs/.

The only thing that you will need to be a little careful of is were to put it so that it is system wide. That is normally defined as directories in /etc/ld.so.conf. That means if you put you lib in /usr/local/lib it normally works.

However, you can get round that by using it as

gcc -Wl,-rpath,/home/serk/yourlocallibpath -o finishedProg file.o libmyshared.so

There are a few more options in the manual but really that covers just about everything. (obviously, you put that in your Makefile appropiately)

StuXYZ 731 Practically a Master Poster

Sorry I had a quick look at this. The problem is that I cant compile it since there is lots missing and you have a link-time error.

Additionally you have missed (I think) a "}" on the duck constructor.

Can you post the program as a tar.gz or however you like, but put it as an attachment. (sorry I should have said that in the first message)

StuXYZ 731 Practically a Master Poster

Sorry to all, who I seem to upset. I should have just suggested here is another way to do it.

I have two comments (in my not very humble defense):

Infraction's error is a horrible thing to debug. You somehow have to know that ss >> temp sets the eof flag (assuming it consumes all the string). So you have to know that you need a ss.clear() afterwards, or do it differently. A journey-man programmer, can easily spend a long time trying to find that out. Nearly working but leading the questioner down into such difficult language/library issues is worthy of pointing out.

Swot, sorry, I was a bit flippant but the problem will be that to avoid an extra inner loop you have to head down to stdlib stuff or use streams. (or fancy stuff.). you are correct that ifstream needs a char* but it needs yet more to get confused with. (especially since you can get a char* from a string with one method).

Overall the questioner (serleon) has (a) put some effort in, (b) is obviously comes from a field were his main expertise are not C++,
but requires serious ability.

This deserves a level of respect above that we typically see, i.e. "I am doing a course on c++ and I want my homework debugged". I just wanted him to see something working.

So overall, sorry if my tone was a bit flippant. I didn't mean to offend so …

StuXYZ 731 Practically a Master Poster

Let me see now. But sorry, a set of things were pointed out
(A) have you removed the #define ?
(B) have you improved the stupid do I win section
(C) Have you made ANY changes above the simplest 5=row, 5=col,
like actually improve the loop

Answers on a postcard please ..... Beyond that I am prepared to look at you ugly code for a total of the amount of time required to make your changes.

StuXYZ 731 Practically a Master Poster

First off welcome. I think this looks like particle physics code :-)
In particular Cern style code. Looks like you are going to have fun.

Swot:
I am going to disagree with Swot since it doesn't compile.
You can't add a char to a char array.

Infarction:
Sorry, I think you are also wrong since your are not clearing the flag state of the stringstream. So you will get "1.dat", empty string, empty string

So this is my attempt

std::vector<std::string> Filenames; 
std::ostringstream ss;
for(int i = 1; i <= 10; i++)
   {
      ss << i << ".dat";
      Filenames.push_back(ss.str());
      ss.str("");
    }

Finally, stream object DO NOT TAKE strings, into open, you need this (example):

std::string temp="afilename.dat";
std::ifstream X(temp.c_str());
StuXYZ 731 Practically a Master Poster

Yes it did. There were are number of horrible errors associated with
gcc-3.4 series on reverse iterators. You have to use == and !( iter == v.rbegin()) or as you say write you own.

I am sorry but I pity you having to write for 3.4. (My problem is I have users who want to use 4.4 alpha.... ;-)

StuXYZ 731 Practically a Master Poster

First off -- You know about loops, so what is that monstrosity of a list of
stuff deciding who has won. Why not use a loop.

The problem is actually in the last two else if statements.
board1[5][5] which does two things. (A) there is no board[5][5] the
array is ranged 0-4 + 0-4 so that is a random UNKNOWN memory location. (B) use didn't you mean [row][col].

(C) it is pain ugly.

const char PUnit[]="X 0"; 
for(int row=0;row<5;row++)
{
  for(int col=0;col<5;col++)
     std::cout<<PUnit[board1[row][col]];
  std::cout<<std::endl;
}

Note that the idea in this code, effectively transform -1/0/1 into characters. You might want a if guard on the values BUT it is possible that is only in debug mode as you shouldn't be able to get out of the -1,0,1 range on board1.

p.s Sorry but there are other errors with your code. BUT how to test code is also part of the process of learning to program. (and is easily transferable to any other language -- most likely a more important skill than how to write C++. )

StuXYZ 731 Practically a Master Poster

Yes, this case I would post the code. I figure that (a) you have actually googled this. (b) and tried some testing.
(c) your using a compiler that give better error messages that VC++.

However, this is not a completely uncommon error so I would like to explain what it normally means and if that doesn't fix it then please put some code up.

the destructor not adequately defined, normally means that you have a pointer that you cannot find the vtable back to the base.
E.g. consider class Base; class A : public Base; class B : public A;
No in a separate file you define stuff that uses ptrs/ref or B, and those ptrs get deleted OR those refs get moved out of scope. You don't have sufficient includes in the file, but you have pre-definitions. Then you have an implicit/direct call to a destructor that needs to call A and Base destructor. gcc can't resolve that.

So I AM GUESSING!!! that the error is in the lack of an include.

However, some code is going to help here so I think some posting is in order. If you have large methods maybe strip them down.

StuXYZ 731 Practically a Master Poster

To open an output stream it is output.open("ParkingCharges.txt",ios::out); NOT: ofstream.output("Parking Charges.txt", ios::out); Because you are using a class name not an instance/object (ofstream is not an object) and you are using output which is not in the class or the public base classes.

StuXYZ 731 Practically a Master Poster

You error is the fundamental language mistake. It is not possible
to declare any new variable or object in the scope of the switch statement that has outside scope. ifstream input("help.txt"); is not allowed.
Additionally, you have already declared input at the top
[4 lines below main()].

If you want to try this

switch(option) 
{
  case 'h':
   input.open("help.txt");
  break;
  .....
}

Further, you don't actually use input and output, but define a NEW
instance of output in the function CarParking.

perhaps you wanted this

int CarParking(std::ostream& output,const int min)
{
     int total = 0, time = 0, fees = 0;
      time = (min/60);
     // rest of your code
}
StuXYZ 731 Practically a Master Poster

I think that the problem is that section is a char array and you have
the problem that you have to convert them to integers first, otherwise they have their ascii value. e.g. 1 is 49 (I think)

So isolate the number part of section and convert to an integer/double and then add.

however, all of that is a guess, you will need to post a little more code, in particular the type definitions of track, section and answer. Additionally,
while you are looking at it does track become to big... i.e. bigger than the array section?

StuXYZ 731 Practically a Master Poster

From looking at you code I don't think you are clear on (a) the objective
(b) how to use const references. So I am going to re-write a bit
to do something (Unlikely to be what you want) but hopefully that will separate between (a) and (b).

Let us start with machine.

It has a method increment, Let us say that add a value to to rackID.
That doesn't need to take ANOTHER machine object.

Then we are going to write a method add that takes another machine object and adds their rackIDs together.

Here is the class definition:

class Machine
{    
public:
    std::string owner;
    std::string make;
    int rackID;

    Machine() : rackID(0) {}
    virtual ~Machine() {}
    virtual void displayMachineDetails();
    void increment(const int =1);
    void add(const Machine&);
};

Now let me write increment, basic stuff

void
Machine::increment(const int Index)
{
   rackID+=Index;
}

void
Machine::add(const Machine& A)
{
   rackID+=A.rackID;
   return;
}

Note in add, we add TWO Machine objects and the SECOND object does not change. I reference the second object without changing it. Since A is also and object then you can access A's private members. This would not be the case for say void Machine::Test(const Other& X) .


I use a reference because (a) a copy would be expensive (b) you have not provided a copy constructor and that can lead to problems, and you have a string object, so it will.

StuXYZ 731 Practically a Master Poster

Sorry my mistake, I just read the error message and assumed.
Ok so I copied and compiled the code.

Here is what I had to fix.

(a) Size in the constructor needs to be size.
(b) Expand doesn't have an SS_2 variable and the last line
should be SS=SS_2; (c) The guard in the assignment operator is mal formed
it should be if (this!=&RHS) (d) In the same function, SS_2 should read SS.
(e) Stack::Push capacity is actually size
(f) That is it...

Don't think the code works but it does compile.... time for you to test....

StuXYZ 731 Practically a Master Poster

You have not defined a few components.
e.g.
you need to add a destructor
Stack::~Stack()
{
// stuff
}

etc.

StuXYZ 731 Practically a Master Poster

The difference between (int) and static_cast<int> is really the limitation
of static_cast<>

I think it is easier to see an example and then discuss it.
E.g.

char A('x');
double X[50];

int i=static_cast<int>(A);      // OK
int k=(int) A;
long int j = (int) X;
long int k = static_cast<long int>(X);   // FAILS AT COMPILE
long int z=reinterpret_cast<long int>(X); // OK

Basically, static_cast will only allow conversions between related types.
Note, the very subtle error in the code above (int) X will work BUT loses precision so the full address is not converted [ok I know it is machine dependent.. but 64 bit/gcc is does], and that alone is worth the extra typing.

StuXYZ 731 Practically a Master Poster

Why not use a string
Add #include <string> at the top
replace char* ... with this std::string str; // and
and change your output line to this.... std::cout<<"Length == "<<str.length()<<std::endl; note that since string is a class, and str is an object of type string,
you call the string method called length. It is not a variable of string but a function hence the () after length.

However, it you want to count the letters and be a bit more careful about
spaces etc. Then there a a lot of post here and FAQs elsewhere that discuss how to proceed.

StuXYZ 731 Practically a Master Poster

Ok the question really has highlighted just how ignorant I am about
regex.

I have a solution to the problem BUT I don't think it is elegant and
I am sure that others know how to do this properly.

Anyway here is what I have:

boost::regex Re("([A-z0-9]+)");
std::string Text;
std::string Out;         // output space
// Text set somehow or use iterators to a stream

boost::sregex_iterator m1(Text.begin(),Text.end(),Re);
boost::sregex_iterator empty;
while(m1!=empty)
   { 
      Out+= *m1;
      Out+=' ';         // add space .
      m1++;
    }

Now you might like to add the space into the regex code and then
not worry about the word spacing, but you can experiment.

What I am not sure of is m1!=empty the best way to terminate this?
If you figure it out something better or anyone else please add a comment.

Hope this is helpful.

StuXYZ 731 Practically a Master Poster

uinput is defined as an integer / and 'N' is not.
(actually, N is converted to an integer but as its ascii value)

Adding some structure to this would greatly help. Use some functions etc.
Separate the question/answer from the actual processing. That also allows you to write tests easily. Since you are using C++, you could even think about a class or two.

StuXYZ 731 Practically a Master Poster

Despite your simulation set up, do not put the point as the first
part of the map.

The map is actually a std::set taking a pair. It is sorted on the first
on a red-black tree. If you use a point, you will end up with a horrific sorting problem, insert removes will take forever, additionally, I know of no way of getting avoiding the problem of different sort criteria for a point. (you need the particle closest to X). So divide you space into N bin and use that as the level and the map index. You can be clever and divide say 1024 and sub-divide each by another 1024 and make a large number for the level. This it is easy to pick-out based on the find.

If you need to do something specialized on the 3d-point write your own map/set class.

StuXYZ 731 Practically a Master Poster

A few points: Sorry to preach...

You allocate 33971 lists!! Much better is to use a map.
std::map<int,std::string>

If you want to record clashes then us a multimap.

Next: Why open all the files at once, have one ifstream and open a file, process and open the next file.

C: The loop from line 68 shows that you missed that strings can expose their char data.

for(int i=0;i<SIZE;i++)
{
    fin>>str1[i];
    mastercount++;
    char* ptr=str1.c_str();
    for(unsigned int q=0;q<ptr;q++,ptr++)
      num+=static_cast<int>(*ptr)*(q+1);
}

Then I lost the will to live.... I can't figure out what the get six words bit is below is intended to do.

However, hope this helps a bit, anyway.

StuXYZ 731 Practically a Master Poster

It depends on what you want to do with the code.
If you want a vector of all the words or a particular one
Try this

std::string Text;
// set text equal to something ...
std::string searchString="(\\S+)\\s";
boost::regex Re(searchString);
std::vector<std::string> Aout;
boost::regex_split(std::back_inserter(Aout), Text, Re);   // Destroys Text string in process

The regex expression is not great, (or is that what you are after)?
but you can fill anything you like in there. There are a lot of different ways of using regex, the boost site has an extensive user manual.

Can you be a bit more specific, it this is not what you want?

StuXYZ 731 Practically a Master Poster

I have seen this problem before. I would advise
(a) Never round up/down until the end.
(b) It is tempting to count the large number significant bits in the input data e.g. if the user enters 3.45 lb + 12.3 oz. And then say round to 3 sig.fig. but you will annoy more users than not.
(c) It is better to round to +/- 2 + log_e(items_added) of the lowest significant number. E.g in the example above the SLN is 0.1 oz so you get a +/-0.25 oz.
spread into the base units.

In short that worked for me, but it depends on your user base.

If this is a scientific user base, you are less and less able to round numbers and you head from biology to physics.

StuXYZ 731 Practically a Master Poster

You have missed that you could have 2 aces e.g.
AAK45 would be 21 but you will not score it as such.

So ADD 10 if you have an ace. Since you can't have two. as AA+ 20 == 22.
e.g. lines 42-46 become

if ((dHand < 12) && (Ace == true))
{
 dHand += 10;
}

Notice you have also made the beginners error of writing ace=true which is always true and sets ace to true. But any modern compiler gives warnings about that.