arkoenig 340 Practically a Master Poster

I am guessing from what you have posted that you have never successfully run a C++ program at all. I say this because of the large amount of stuff in your program that is simply not part of C++.

It is one thing to show someone a program and say "This program almost works, but there is a problem that I just can't find." It is something else entirely to post something that isn't a C++ program and say "Please make this work for me." If you had done the first of these, I'd be glad to help you, but I'm not willing to substitute for your textbook. Sorry.

arkoenig 340 Practically a Master Poster

Please read this.

arkoenig 340 Practically a Master Poster

and as for lines 124 and 133 since im using two arrays there would i not need to have a separate for loop so they have there own count variables?

I'm sorry, but I don't understand the point you're trying to make.

You have written statements of the form

array[i];

Those statements don't actually do anything, so I don't understand why they are there.

arkoenig 340 Practically a Master Poster

Hasn't he been dead over a whole year lol?

Rumors of my death are greatly exaggerated.

You're thinking of the Andrew Koenig who is the comedian who died last year, and who was the son of the original Star Trek actor Walter Koenig, who played Pavel Chekov.

No relation, so far as I know.

arkoenig 340 Practically a Master Poster

Now you've set month to 11, which means that your arrays have only 11 elements; the last element of averageStore is averageStore[10], and so on.

The right way to do this is to set your upper bound (i.e. month) to the number of elements you want, so

const int month = 12;

and then to exclude equality from your loops, such as

for (int i = 0; i < month; ++i) { /* whatever */ }

Personally, I prefer to use != instead of <, because doing so lets me use the same style for forward iterators, which do not support <; but I realize that not everyone agrees with me.

By the way, I don't understand why you're evaluating some array elements and then throwing them asay, as you do on lines 124 and 133.

arkoenig 340 Practically a Master Poster

If you want to ignore element number 0 in every array, you can certainly do that. It's not good style, but it can be made to work.

But in order to make it work, you have to make every array at least one element bigger than you think you need. In other words:

int foo[10];
for (int i = 0; i <= 10; ++i)
    foo[i] = 0;

This example never does anything with foo[0]. By itself, there's no harm in doing that. However, it also attempts to access foo[10], and that's wrong. There is no such element as foo[10], and there's no telling what the program will do when run.

So if you want to use this technique, at the very least you have to define foo to have 11 elements, not 10.

arkoenig 340 Practically a Master Poster

In the future, please post a complete program.

However.... Even though this program is incomplete, I can see a serious problem: In C++, arrays start with an index of 0. So when you write a loop such as

for(int i=1; i<=month; i++)	{
	monthAverage[i] = monthSum[i] / month;
}

that loop cannot possibly work: It ignores the first element (monthSum[0]) and tries to use a nonexistent element that is past the end of the array (monthSum[month]).

arkoenig 340 Practically a Master Poster
arkoenig 340 Practically a Master Poster

No, you just need <.

arkoenig 340 Practically a Master Poster

When you call a function foo with an argument x that is a variable of type char, you call it by writing foo(x) , not foo(char x) . That's your first problem.

Your next problem is that the variables d1 through d8 are not declared at the point at which you have called acknowledge_call .

And your third problem is that you are still not using code tags.

arkoenig 340 Practically a Master Poster

Please don't make us play guessing games: Show us exactly what you wrote, and tell us exactly what errors you got. And please use code tags.

arkoenig 340 Practically a Master Poster

You have defined acknowledge_call to take eight arguments. You have called it with no arguments. Hence the error message.

Next time, please use code tags.

arkoenig 340 Practically a Master Poster

Your dealCard member function has a serious flaw: It returns a reference to a local variable, which will refer to nothing valid after the function has returned. You should probably just return a Card (assuming that Card is a class whose values you can copy).

If you're going to use a vector to represent your deck of cards, you should really take cards off the end, not the beginning. The reason is that every time you take a card off the beginning, the library has to copy all the rest of the cards.

Also, I note in passing that before you remove a card from a deck, you should really verify that the deck is not empty.

You can implement these three suggestions by changing the dealCard member as follows:

Card Deck::dealCard()
{
    assert(!deck.empty());
    // Create temporary card
    Card temp = deck.back();
    // Take the card out of the deck
    deck.pop_back();
    return temp;
}
arkoenig 340 Practically a Master Poster

Did you call srand first?

MasterGberry commented: fast response +0
arkoenig 340 Practically a Master Poster

Change "int i = 0" to "vector<string>::size_type i = 0" in line 44 and to "string::size_type i = 0" in lines 58, 71, and 84.

Next time, please cite the text of the error message so we don't have to look it up.

Zvjezdan23 commented: Thanks a lot for your help +1
arkoenig 340 Practically a Master Poster

I made a detailed suggestion as to what you should do about your input loop. Lines 59 through 64 of the program you posted are quite different from what I suggested.

That difference is the reason your program does not work. I think you should take the time to look at your code carefully. Trace through what it does by hand, including the values of all of the relevant variables, until you understand why it does not work.

Until you take the trouble to understand what you are doing and why, nothing that anyone else says will help you.

arkoenig 340 Practically a Master Poster

When you write a string literal that contains backslash (\) characters, you need to escape each one. So if you want to read a file named C:\201\GPAFile.txt, you need to give an argument of "C:\\201\\GPAfile.txt"

arkoenig 340 Practically a Master Poster

Your loop in lines 54-57 is wrong, because in.eof() will be true only after you have reached the end of the file. So the last time through the loop, in.eof() will be false, but the two read attempts will fail. One workable way to write such a loop is:

while (i < MAX && (in >> student[i] >> studentGPA[i]))
    ++i;

This strategy increments i only after both read attempts have succeeded.

As for your bogus output, why don't you start by printing your data before you try to sort it, so that you can see whether you read it correctly? If that works, you know to look for trouble in your sorting code; if it doesn't, you know to look elsewhere. Either way, you have made your problem easier to solve.

arkoenig 340 Practically a Master Poster

It's the same problem in slightly different clothing. In line 10, you say that readArray accepts a pointer to a string; in line 41 you say that it accepts a string.

arkoenig 340 Practically a Master Poster

In line 11, change "double studentGPA" to "double studentGPA[]" to match line 60.

Also, I'm afraid I need to point out that if you really do not know how to answer this question by yourself, you have a lot of studying to do.

arkoenig 340 Practically a Master Poster

In line 11 you say that gpa_Sorter takes two arguments: a double and an int. In line 31 you call gpa_Sorter with an array of double. Thus the error message.

arkoenig 340 Practically a Master Poster

If you're using consecutive integers for the map indices, why not just use a vector?

Independently of that, it would seem to me that you could simply replace lines 8 through 11 of your code by a call to std::swap(theDeck, theDeck[r]) and delete line 4 entirely.

arkoenig 340 Practically a Master Poster

I tried the second example there and I get the same runtime error.

My runtime error is:

Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)

I'll bet you tried to execute

delete [] error;

but because error isn't pointing to memory that was allocated with new , you mustn't delete it.

arkoenig 340 Practically a Master Poster

You first. Otherwise it looks too much like you're asking someone else to do your homework for you.

arkoenig 340 Practically a Master Poster

What is a "negative number of type string?"

arkoenig 340 Practically a Master Poster
arkoenig 340 Practically a Master Poster

What do you expect line 14 to do?

arkoenig 340 Practically a Master Poster

Well... set_union and set_intersection are really intended to let you do set operations on sorted vectors. Curiously, they don't work if the destination is an actual set. So you have to implement those operations yourself using insert and erase, which, fortunately, aren't particularly different operations.

arkoenig 340 Practically a Master Poster

Use begin() and end() the way you would for any other container.

arkoenig 340 Practically a Master Poster

When you don't know it, stop spamming people's threads.

Don't worry: I do know the answers to your questions. I'm just not going to tell you, and this post explains why.

arkoenig 340 Practically a Master Poster

Here's my problem. The question you've asked looks like a homework assignment, which is intended to test your knowledge of pointers. If all you know about a pointer is that it is "a variable that stores a memory address," and you have a homework assignment that asks the questions that you've posted, it looks to me like there is some material in your textbook or classroom that you should have studied but haven't.

As a general rule, this list does not do people's homework for them. More specifically, if you've really told us all you know about pointers, then you do not know enough to answer these questions, so answering them would be helping you cheat.

Therefore, I would like to suggest that you spend some time studying what you are supposed to be learning about pointers, and try answering the questions again. If you have made a genuine try at it and still have trouble, someone here will be sure to help you. As it is, though, I think you're just hoping that someone else will do your work for you.

Moschops commented: Right on. +3
arkoenig 340 Practically a Master Poster

What do you know about pointers?

arkoenig 340 Practically a Master Poster

I'll reinforce what PhysicsExpert said: I see no reason to define a class here.

That said, I'd like to point out some other problems with your code.

Perhaps the most important problem is that what your program actually does is different from what you said you were asked to do. You said that the program is supposed to read 10 numbers and print the largest. What it actually does, however, is to print 10 numbers, each of which is the largest number encountered so far--unless all of the numbers encountered so far are negative, in which case it prints zero.

Next, you should be consistent in your indentation. For example, whenever you have curly braces, you should indent the text within the braces by the same amount.

You didn't do that here. For example, in your cpp file, line 8 is an open brace, but lines 9 through 11 are not indented. Similarly, line 34 has the same indentation as line 36, which contains a close brace.

When you write an if statement with an else clause, the parts before and after the else should be indented the same. In your code, lines 23-28 are indented more than lines 31-33.

Finally, you have written a fair amount of unnecessary code. In particular, it is possible to reduce lines 21-33 to three lines without much effort. I'll leave it to you to figure out how.

arkoenig 340 Practically a Master Poster

What have you tried so far? Why doesn't it work? What sort of trouble are you having?

arkoenig 340 Practically a Master Poster

Wouldn't you think that when someone posts a program in a C++ forum and asks for help, the program would actually be a C++ program?

Fbody commented: You're tight, it does look more like Java doesn't it... +5
arkoenig 340 Practically a Master Poster

Yes, that's what it means. A reference to a pointer is useful for exactly the same reasons that a reference to any other type is useful.

arkoenig 340 Practically a Master Poster

You can replace

for (unsigned long int k = 0; k < inTables[q].Items.at(j).Size; k++)			inTables[q].Items.at(j).Data.push_back(tempItem[k]);

with

inTables[q].Items.at(j).Data.insert(inTables[q].Items.at(j).Data.end(),
                                    tempItem,
                                    tempItem+inTables[q].Items.at(j).Size);

with the same effect. However, it would not surprise me to learn that doing so does not change the speed of your program much. Unless you have actually measured where it spends its time, you probably don't know where the time goes.

arkoenig 340 Practically a Master Poster

arkoenig Can you pls tell me about the algorithms that you mentioned in your earlier post abt sorting using multiple files

Look at std::priority_queue for a good example.

arkoenig 340 Practically a Master Poster

Sounds like you need to measure the time more accurately. I suggest wrapping another loop around the entire program to run it a thousand times or so, and figuring out from that how long it takes to run once.

arkoenig 340 Practically a Master Poster

Exactly. You have to initialize a reference and you don't have anything to which to initialize.

You are completely correct that a reference cannot be a member of a class unless every constructor initializes it. Part of the point of references is that they are always initialized.

If you want something that is similar to a reference but does not need to be initialized, you should use a pointer.

arkoenig 340 Practically a Master Poster

You've initialized myList to myList, creating a circular reference that then you cannot undo.

I think you will make your life easier if you use a pointer instead of a reference.

arkoenig 340 Practically a Master Poster

I doubt you want the fastest algorithm; what you probably want is the easiest one to use that will give you the results you want in an acceptable amount of time. For that reason, I suggest you start by using std::sort, and look elsewhere only if std::sort is unsuitable for some reason.

arkoenig 340 Practically a Master Poster

To merge n files into one, all you need is an n-element array.

Begin by reading the first element of each file into the corresponding element of the array. That is, the first array element is the first element of the first file, the second array element is the first element of the second file, and so on.

Give each array a "mark" -- a single bit that indicates whether the corresponding file has reached its end. At first, every element is unmarked.

Now, you repeat the following steps:

1) Find the array element with the smallest value that is not marked. If all elements are marked, you're done.

2) Write that element into the output file.

3) Read the next value from the input file that corresponds to the array element. If you reach end of file, mark the element.

There are clever algorithms for keeping track of which array element is smallest, but unless you have a lot of input files, you won't need them because the time spent on input/output is much greater than the time spent on working with the array.

arkoenig 340 Practically a Master Poster

Does your compiler not have a problem with line 16(i.e declaring a variable twice)?

No, there's nothing wrong with it. The two definitions are in different scopes.

arkoenig 340 Practically a Master Poster

Here's a hint: You don't need an array.

arkoenig 340 Practically a Master Poster

Show us what you've done so far.

arkoenig 340 Practically a Master Poster

Break it into manageable chunks. Sort each chunk into a file. Merge the files into another file.

arkoenig 340 Practically a Master Poster

You tell me. An element of a string is a single character. It's not immediately clear what you mean when you say that a character is empty.

arkoenig 340 Practically a Master Poster

You said that TableRow is a vector<string>. Apparently it's just a string.

arkoenig 340 Practically a Master Poster

In line 1 of your code, you add an integer to what you claim is a vector. I don't know what you think that's supposed to do, but it's not well defined in standard C++.

Four times in you code, you explicitly convert an enum to an int. That shouldn't be necessary, and vector subscripts are unsigned anyway.

The most straightforward way to check whether a std::string object is empty is to call its empty member.

So... you should be writing something along these lines:

if(tableRow[H1280].empty())
    continue;