Narue 5,707 Bad Cop Team Colleague

>list<humanPlayer> jailHouse;
jailHouse is a list, the list class doesn't allow random access with the subscript operator.

>if(find(countriesOwned.begin(), countriesOwned.end(), countryToCheck) != countriesOwned.end())
I'm guessing this is giving you problems too. ;)

Narue 5,707 Bad Cop Team Colleague

No, you're just on a roll. I'm sure you'll say something stupid eventually and things will be back to normal. ;)

Narue 5,707 Bad Cop Team Colleague

A birthday, perhaps? I occasionally use 1178 as a dummy value.

Narue 5,707 Bad Cop Team Colleague

>and i prefer using those because the other two are two tricky to use, and
>trigger lots and lots of problems...
That's a good reason.

Narue 5,707 Bad Cop Team Colleague

Just keep plugging away at it. The more you practice, the better you get. :)

Narue 5,707 Bad Cop Team Colleague

>one of the warnings is, incompatible implicit declaration of built-in function strcpy.
You need to include <string.h>.

This compiles, and I fixed a few obvious logic errors (like the first call to strtok needing the string you want to tokenize instead of NULL):

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
  struct {
    char origin[50];
    char destination[50];
    char flight[10];
    char aircraft[3];
    char days_of[7];
    char departure[4];
    char arrival[4];
    char begin_date[10];
    char end_date[10];
  }flight_details[1679];
  FILE *fp;
  char buf[50];
  int i = 0, j;

  fp=fopen("iaschedule-07(edit).csv","r");

  while( fgets(buf,sizeof(buf),fp) != NULL)
  {
    strcpy(flight_details[i].origin, strtok(buf,","));
    strcpy(flight_details[i].destination, strtok(NULL,","));
    strcpy(flight_details[i].flight, strtok(NULL,","));
    strcpy(flight_details[i].aircraft, strtok(NULL,","));
    strcpy(flight_details[i].days_of, strtok(NULL,","));
    strcpy(flight_details[i].departure, strtok(NULL,","));
    strcpy(flight_details[i].arrival, strtok(NULL,","));
    strcpy(flight_details[i].begin_date, strtok(NULL,","));
    strcpy(flight_details[i].end_date, strtok(NULL,","));
    ++i;
  }

  printf("print details\n");

  for (j=0; j<10; j++)
  {
    printf("Origin : %s", flight_details[j].origin);
    printf(", Destination : %s\n",flight_details[j].destination);
  }

  return 0;
}
Narue 5,707 Bad Cop Team Colleague

>why don't you better use cin and cout?
Agreed. Perhaps this thread is in the wrong forum and he's really using C.

>either way, it would be like this: scanf("%s",&word);
No, it wouldn't. There are two glaring problems with that code:

1) Never ever ever use %s. It's no better than gets because you have no way of defending against buffer overflow. It's possible to make it safe by adding a field width, but by the time you go to all of the trouble, you might as well just have used fgets (or getline for C++).

2) word and &word are very different things when word is a pointer to char (and that happens to be the type that %s requires). If the argument to scanf is already a pointer, you would be wise not to use the address-of operator. If it's not a pointer, you need the address-of operator to make it a pointer.

>I somehow cannot get declare a variable as a string. (it won't turn blue.)
There's no built-in string type, so your editor will never tell you that you've declared one. You simply have to know what types are treated as strings. In C++ you should be using the std::string class declared in the <string> header. In C, the standard string type is an array of char with '\0' as the last character to mark the end of the string. In your case, it would be like this:


       
Narue 5,707 Bad Cop Team Colleague

Your bracing and indirection are off. To get the address of the links, you need to first dereference current_node. Then you need to do a member access using the arrow operator to get the link, then you need to take the address of that result:

&( *current_node )->left

Or with full parens:

&( ( *current_node )->left )
Narue 5,707 Bad Cop Team Colleague

>I have been working on this school project and have figured out every step but two.
>
>So far I have everything done, and my stumbles are on #4
>
>Also on #6 I can add the explanation point to the end of the words that
>are longer that 8 characters but not to the ones that are shorter.
I'm seeing slight contradictions here.

>word.erase (8,20);
Where does 20 come into the picture? The second argument defaults to npos, so you can just say word.erase ( 8 ) and the string class will do the right thing.

>word.replace(6,1, "#"),word.insert(8,"!");
Um, overkill? Why not just say word[6] = '#'; ? And append would be a better choice than insert here. Of course, since this is the last operation for the line, you can just print a bang character and call it good without modifying the string. Also, this is an extremely poor use of the comma operator. Separate operations should be on separate lines:

word.replace(6,1, "#");
word.insert(8,"!");

Also, you only append the bang in this condition, but the requirements seem to want it all of the time.

>else if (word.length()<=8)
If the word is exactly eight characters, you don't need to append with 'B's. Your logic is broken here, but the body of the condition hides it from you.

>word.insert (8 - word.length(),"B");
This doesn't do what you think it does. It inserts the string "B" …

WolfPack commented: お疲れ様でした。 +8
arjunsasidharan commented: What does that mean wolfpack? the chinese letters? +3
Rashakil Fol commented: Those are Japanese. +6
Narue 5,707 Bad Cop Team Colleague

You're mixing up the meaning of a row and a column. The following allocates using column major order (a[cols][rows]):

mat1 = malloc(cols * sizeof(int*));
for(i = 0; i < cols; i++)
{
  mat1[i] = malloc(rows * sizeof(int));
}

And this prints using row major order (a[rows][cols]):

for (i = 0; i < rows; i++)
  for(j = 0; j < cols; j++)
    scanf("%d",&mat1[i][j]);

Unless rows and cols have the same value, the two aren't interchangeable and you're accessing memory outside the bounds of the array you just allocated. Linux is giving you a segmentation fault.

Narue 5,707 Bad Cop Team Colleague

>and it's so difficult to learn some one don't know !
I gave you the exact name of two algorithms that find a minimum spanning tree. What more do you want? Me to write up two super easy implementations and describe how every line works? I didn't feel the need to do that when just about every result from Google has sample code.

>what can i do if teachers don't explain it , and there is no time to search and search .
http://en.wikipedia.org/wiki/Prim's_algorithm
That's the first result from Google. It took me about 5 seconds to search and search. Stop being a weenie and show some effort.

Narue 5,707 Bad Cop Team Colleague

>i do not know these algorithms
Which is why I suggested that you study them. If you did know them, you wouldn't be asking how to find a minimum spanning tree. Really, is Google that difficult to use?

Narue 5,707 Bad Cop Team Colleague

There are several ways. Not to mention that graph algorithms tend not to be trivial, so you'd be better off studying existing solutions, like Prim or Kruskal's algorithms.

Narue 5,707 Bad Cop Team Colleague

You derive Operators from BaseToken, but tokenValue is a member of Operators, not BaseToken. So BaseToken can't use it because inheritance goes down the chain, not up it.

Narue 5,707 Bad Cop Team Colleague

>Can I compare more than 1 things inside the overloaded functions?
It's a function. You can do anything you want as long as you maintain the correct interface for the overloaded operator.

>if so how would i get the users input? and how would i find the difference?
If I understand correctly, you would get the user's input by overloading the >> operator and doing something like this:

D d1, d2;

cin>> d1 >> d2;

d1 = d1 - d2;
Narue 5,707 Bad Cop Team Colleague

>why not?..
Because VC++ 6 was released before the C++ standard was ratified. It has serious conformance issues and will refuse to compile perfectly legitimate C++ code. I spent more time hacking the damn thing to get it to work right than I did getting any work done. I strongly suggest you get Visual Studio 2005.

Narue 5,707 Bad Cop Team Colleague

>D D::operator- (const D &d2);
You have a rogue semicolon.

Narue 5,707 Bad Cop Team Colleague

value is an array. When you pass it as the second argument to get, it acts as the initializer for the std::string parameter. You've lost your reference, and any changes to the parameter will not be reflected back in displayAll. Change value to a string and pass it by reference to get.

Narue 5,707 Bad Cop Team Colleague

In againstComputer, the first if statement needs braces. In main, when you test move, you used else instead of else if twice. And you use cMove before giving it a value in againstComputer.

Narue 5,707 Bad Cop Team Colleague

He probably wants to be given a folder and open the files in that folder. Your solution assumes that he already knows the names of the files in the folder and the number of files is a constant.

Narue 5,707 Bad Cop Team Colleague

I'm reasonably sure that's not what he wants.

Narue 5,707 Bad Cop Team Colleague

>i mean what is the difference between char and unsigned char?
char isn't portable because it could be either signed or unsigned.

Narue 5,707 Bad Cop Team Colleague

>which datataype can my input take.
The same data type you used to write it if you want a meaningful comparison. If you're just checking for equality, you can use unsigned char and compare every byte individually.

>also, the comapred stream is in this form 0004a4900
>i made this stream as a cons int and then with 0x it is already stored as an hex. stream
>now when i read i want to search this strream in my input file
There's no question here.

Narue 5,707 Bad Cop Team Colleague

C++ doesn't know what a folder is. That kind of operation is dependent on the operating system, and the solution will use a system specific function or class of functions. So, what compiler and OS are you using?

Narue 5,707 Bad Cop Team Colleague

The hardest part of learning any language is forcing yourself to write logically in that language. It's pretty easy to write C++ in C# because there are many similarities, but that's not necessarily good C#.

Narue 5,707 Bad Cop Team Colleague

Change this:

double M2_0(c,m)
double c[160];
double m[16][5];
 {

To this:

double M2_0(double c[160], double m[16][5])
 {

C++ doesn't support the old C-style function declaration. C also no longer supports it, so I don't recommend using it in C either.

Narue 5,707 Bad Cop Team Colleague

Do you mean add the digits together? Or are you really going to get multiple huge numbers that need to be added together? Show us some sample input and the expected output.

Narue 5,707 Bad Cop Team Colleague

>how do you know which one is going to be applied in what you do or how good the code will stay up?
Experience.

>should I expand into other codes
Eventually, but learning too many languages at one time will just confuse you.

Narue 5,707 Bad Cop Team Colleague

C++ is extremely limited in the values you can use. For example, the int data type is only guaranteed to hold the values -32,767 to 32,767. A large integer like 9999999999999999999999999 can't be stored in a single variable of any type. So you get around it in one of two ways.

The first way is manually. You store pieces of the value in multiple variables and write functions that handle the math between those variables. This is tough, and I don't recommend it if you're not confident in your C++ abilities.

The second way is by using a library that does the manual stuff for you. This one for instance. The problem with this solution is that you have to learn a library and now you're bound to something that isn't standard.

Now, from the looks of your problem, I'd say you've been given an assignment to manually perform addition on large integers. But it's hard to be sure because you've been rather vague in the requirements. Can you describe your assignment in a little more detail? There's a possibility that you simply asked the wrong question and that's why the answers are confusing you.

Narue 5,707 Bad Cop Team Colleague

>The code processes millions of transactions, but less than .01 % has this error. Any ideas?
That's a typical floating-point rounding fudge. If it's a serious enough problem, you can try to use a more precise type such as long double, or remove floating-point altogether to maintain exact precision. Though I suspect that an imprecision at the eighth decimal place isn't that much of an issue unless you're trying to do something with vanilla C++ types that shouldn't be done with vanilla C++ types. If that's the case, you really need to get a high precision mathematics library.

Narue 5,707 Bad Cop Team Colleague

>I have no idea! XD
Thanks for letting us know. :icon_rolleyes:

Narue 5,707 Bad Cop Team Colleague

The C++ beep is all you get. If you want different notes, you need to go lower (and try to access the hardware, which isn't portable and probably won't work) or go higher (and use a library that lets you produce notes from the sound card rather than the internal speaker).

Narue 5,707 Bad Cop Team Colleague

>I seem to be upsetting you
I doubt you could manage to upset me.

>I wanted to ask you about the "braces on a separate line part, I'm not sure what you mean by that.
I mean that anywhere you use { or }, they should be alone on the line and everything between them should be indented. Like this:

void function()
{
  // statement

  if ( something )
  {
    // statement
    // statement
    // statement
  }

  // statement

  while ( something )
  {
    // statement
  }

  // statement
}

This guarantees that it's easy to see where in the nesting each statement is, and you save yourself a lot of trouble trying to match braces because a missing brace is painfully obvious.

>I'm just trying to understand this stuff that seems to be extremely hard for me.
Okay, let's keep it as simple as possible. Treat the odd and even calculations as completely separate. If nothing is related, the relationships won't confuse you. Then it boils down to two separate loops:

int oddsum = 0;

for ( int i = 1; i < 3579; [I]next number[/I] ) {
  // add the odd numbers to oddsum
}

int evensum = 0;

for ( int i = 522; i < 2222; [I]next number[/I] ) {
  // add the even numbers to evensum
}

Now, we can do this two ways. We can look at every number and pick out the evens or the odds, …

Narue 5,707 Bad Cop Team Colleague

>I am new to C++
Then I'll encourage you not to use that horrid style of formatting. Ideally you should put braces on a separate line. Look for code posted by members here with high post counts. Chances are good that they use a highly readable style.

>but then I tried making some changes to it
In other words, you took the example I gave you (which worked perfectly according to your requirements) and butchered it.

>but now cant get back to where I was
This is where versioning helps. Unfortunately, I can't help you get back to where you were because I don't know where you were unless where you were was the code I posted, in which case you can just cut and paste it again.

>disregard last code this is the one I have so far
Grrr. You're right back where you started. The if statement guarantees that you calculate evens, or odds, but never ever ever both. I explained this to you in post #2.

Narue 5,707 Bad Cop Team Colleague

>entry->set(NAME, AGE, JOB);
This is equivalent to:

(*entry).set(NAME, AGE, JOB);

The arrow operator dereferences your pointer for you and then grabs the member you specify.

Narue 5,707 Bad Cop Team Colleague

It looks like your logic is reversed a bit. You want to sum both the odds and evens, but in your current logic, it's either one or the other depending on the initial number.

Since the range of odd numbers is wider than even numbers, you can include the test and sum of even numbers in your loop for the odd numbers. Just do the sum for even numbers conditionally:

for ( int i = 0; i < 3579; i++ ) {
  if ( i % 2 != 0 )
    totalodd += i;

  if ( i >= 522 && i < 2222 && i % 2 == 0 )
    totaleven += i;
}
Narue 5,707 Bad Cop Team Colleague

During initial development you don't have to provide releases, or patches, or documentation, or support to anybody outside of the development process. You can correct bugs and add features quickly and easily en mass. After the product has been released, you don't have these luxuries, and they all have a significant cost.

Narue 5,707 Bad Cop Team Colleague

And I'm giving you a good explanation by making you think about it.

Narue 5,707 Bad Cop Team Colleague

Could you please stop resurrecting year old threads?

Narue 5,707 Bad Cop Team Colleague

Let's play a game. Why do you think maintenance doesn't cost more than development?

Narue 5,707 Bad Cop Team Colleague

>I know it seems impossible
What it seems is stupid. But since you insist on doing something stupid, for probably a stupid reason, you can unpack both libraries and repack them using ar.

Narue 5,707 Bad Cop Team Colleague

You're getting into the realm of needing a makefile. Ask man about the make utility.

Narue 5,707 Bad Cop Team Colleague

>Always Remember The GOLDEN RULE that
That's the golden rule? Gold must be pretty worthless these days if all of the vastly superior rules were shoved aside for that one.

>when any funtion needs to return any value or recieves a value then it
>should proceed with a type of value it can recieve usually an int
Um, return and receive tend to be mutually exclusive. You should pick one when talking about return types. I'd recommend "return". "receive" is generally what one means by parameter or argument.

>ending with semicolon (;)
I think it's a a fair assumption that we all know what a semicolon is.

And of course, you didn't answer the question of why int main is preferred over void main. You just made the common mistake of pretending that main is a normal function and propagated the misconception that main's return type is the decision of the programmer. Both of which are false.

Aia commented: Gold is not what is used to be. +2
Narue 5,707 Bad Cop Team Colleague

>Surprising Salem didn't comment on this..
He probably doesn't want to explain it for the umpteenth time, like me.

Narue 5,707 Bad Cop Team Colleague

So...basically you're writing a heap, right?

>The part I am facing trouble with is doing the actual swap, as 'parent' is only a pointer to the node's parent.
Are you swapping data or doing a physical swap? If you're swapping data, I don't see what the problem is. If you're doing a physical swap, you should be using rotations.

Narue 5,707 Bad Cop Team Colleague

>So what would one cite as the main difference(if any) between iteration and recursion?
Recursion is recursive and iteration just repeats.

>are these following points differences?
The first is, but the second is just two ways of saying the same thing.

Narue 5,707 Bad Cop Team Colleague

>Why can't it be placed in a function?
It can. For your statement to be true, both of my conditions would have to be true, and neither of them are.

Narue 5,707 Bad Cop Team Colleague

>So can you say that the point I made is the difference between them?
No. I don't see how the two statements describe a difference unless you're adding the restriction that only one loop can be used ever and it can't be placed in a function.

Narue 5,707 Bad Cop Team Colleague

>when it is necessary to include a return statemnt in one's code
When you're returning from any function whose return type is not void.

>what is the difference between recursion and iteration?
At what level? At the highest level, there's no difference. Go a bit lower and recursion is just a more flexible form of iteration. Go down to the client level and recursion is a series of nested function calls while iteration is just a glorified goto loop. Go even deeper and recursion is an execution stack where stack frames are piled on top of each other and the instructions that operate on each frame happen to be the same while iteration is nothing more than conditionally jumping around the same instructions within one stack frame.

Narue 5,707 Bad Cop Team Colleague

>true, fflush(stdout) is well defined
:icon_rolleyes: You have no idea what I'm talking about, do you? fflush takes a FILE* as its argument. If that pointer is a null pointer, fflush is required by the C standard to write all unwritten data from every open output stream. stdout is included in that, as is stderr and any other output stream that was opened by the program.

>0 is stdin not stdout
No. You're confused about the difference between a file descriptor and a FILE pointer. stdin isn't (and can't be) 0 because that would make it a null pointer when treated as a standard FILE*. stdin is likely to be defined like this:

#define stdin (&__iob[0])
#define stdout (&__iob[1])
#define stderr (&__iob[2])

Where __iob is an array of FILE, and FILE is a structure that contains various useful information (such as buffering and positioning) that may or may not include a file descriptor depending on how I/O works on the system.