jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Anytime you have an if statement without braces following it, only the next line down is included as part of the if statement.

if (condition)
      x = y;  //what gets evaluated pending true condition

cout <<"whatever "; //new program statement, if statement done

else  //compiler says where did this come from?

you need
if (condition)
{
     x  = y;
     cout <<"whatever ";
}

else  //immediately follows if statement because of { }
   etc.
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You left off the ampersands in the function definitions for print and display: void Display(StudentArray & CSCI208Class, int &N)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your get_lname method is void and on 141 you are trying to compare two return values from it using strcmp. Try something like this:

Name_t lname;
Name_t nextlname;
CSCI208Class[I].get_lname(lname);
CSCI208Class[I+1].get_lname(nextlname);
if(strcmp(lname,nextlname)>0)

or something to that effect. Or you could change the return type on get_lname() to Name_t but I don't know if you have some flexibility in that regard.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Increment your count variable inside of your while loop (with count++; ). Each time the loop goes around the counter gets pushed up by 1. Just remember what value count started out as to get an accurate reading.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Apologies. Were you able to get it working without the objects in main being consts themselves?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That's why I said to put it in the declaration (up in the header in the class SparseMatrix{//declarations go here}; It does not go in front of the definition (where you write out the procedures of the method).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try prepending "friend" to your declaration (not definition) of this << method: friend ostream& operator<<(ostream& out, const SparseMatrix& rhs);

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Just my 0.02 but it sounds like it might be a candidate for a singly linked list. You can enter the datum into it's proper place in the chain as it's coming in from the file. That approach is basically sorting the data but it doesn't explicitly take everything into a collection and then sort it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Pretty cool.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Did you read the website's author's response to the first comment? He essentially answered your question about the precision. The step size (epsilon) from one double to another is on the order of 10^-16. Any decimal digits you have left over smaller than that are useless. He recommended GMP or another library for which he's written a wrapper So if you want the level of precision reflected in your current numbers that's what it will take.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

For your overloaded << operator it would have to be defined as ostream& operator<<(ostream& out, const SparseMatrix& rhs); otherwise the compiler is unsure whether the method will try to modify the const object or not.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Check out the GMP for the level of precision that you need.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

omathinga-whatta? :) That was the biggest shock for me to find out that he didn't really look like his avatar.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

His title ("He's the daddy") could be taken in so many very different ways I try not to think about it. But you see my point. The game is afoot.


EDIT: He just showed up! Omnipresence as well?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Don't overbook it, don't provide the "scratchy towels" (a la Verizon ad) and make sure it remains an "ool."

On a more serious note, what ideas have you had thusfar? It's going to be quite similar to any kind of hospital management in terms of having people as an object, or library management program where the objects are books. There are lots of examples of these types here on the site that you can draw ideas from.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I just noticed you changed your custom user title, cwarn and I was reminded that I never replied to this thread. Still really enjoy the show though I don't own any of the DVDs (I watched through the series on TV Land about 6 years ago). Richard Dean Anderson showed up for one of the McGruber bits on SNL. I hadn't seen him in a while (I'm not into Stargate) so to me he aged quite a bit.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Nope. That was the double, you could so tell. The real Depp is none other than our own Happygeek. He's all but admitted it. Don't you see his clever attempt to redirect attention to an article where he refers to himself (Depp) in the third person.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I must say, Happygeek, I swore more people were going to join in our mock elation over the news of Johnny Depp's undeadedness. Oh well, their loss.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

First think of how you would find the minimum and maximum values without the -999 present and then figure out how to exclude it (-999) from your scheme to get the max and min.

Think if you were walking along a list of numbers and you could only carry one in each hand, how would you keep track of max and min?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Awesome, good luck with the rest of it!

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

line 164 in songs.cpp library->push_back(*newSongInfo);
line 171 in songs.cpp playlist->push_back(*newSongInfo);

You needed to deref library and access member push_back so that needed to be changed into an arrow and since your newSongInfo was a pointer to song and your vectors held songs you needed to dereference that also. Same applies for playlist on both counts.

I didn't look things over very carefully or fully test them out, but I figured I'd give you a head start on bug hunting.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You have to cast either the numerator or the denominator (or both) to a double otherwise it does the integer arithmetic first and stores it in the double. double average=((double)(sum+999))/(count-1); I put some extra parens on there just to be sure.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I totally missed it. The whole point of the do/while is that you can get the input first and evaluate it versus the condition after. So you don't need the lines 35-37 at all. You get the first input right off the bat.
So retool your do/while statement to just say "enter a number < 0.51" or whatever or change the error message.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No ; on the if line if(percent < 0.5); I think you have the sign backwards for the warning too, should be percent > 0.51 just like you have on the while condition.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Ah. When you put an if statement with no braces, only the next line down is part of that if statement. So to the compiler it looks like

if( )
   statement;

another statement

else -- no if because they are broken up

Your if statement will not allow you to ask the question again after one incorrect response. If you want it to repeat you need the do/while.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

floats are not an array subscript, ints are. You have it right there in the comments that it's a counter so it's not going to have decimal digits.
We won't be able to do this inch by inch, it looks like you made the first function and then tested it, no? Is that what you are trying to accomplish with this one?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your leading code tag got messed up I can't see which is line 55. Post the code for the do while as that's the right way to do it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You have to pick one of your threads, don't just keep adding to both. What's not working about it?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Function definitions belong outside of main(). One style is to put prototypes before main and definitions afterwards, or you can just put the definition before without needing a prototype

void myfunc(int, int);

int main()
{

}

void myfunc(int param1,int param2)
{


}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes. Though it doesn't mean you can ferret all the files away on your harddisk somewhere and they'll automatically compile or anything. Namespaces still need to end up being part of a particular assembly (search ".NET assemblies" for more info) to make sense.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No worries.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

once the user inputs -999 then the program should terminate and give the user the sum of the numbers entered, average, count etc.

The loop should terminate and it should _display_ the information. Nothing says it has to be calculated at that point. In fact it would be ludicrous to ask you to get all the sums right at that point without having an array in which to store numbers. You're doing the right thing.
Now increment your counter variable within your loop.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

string temp = *iter;

My simulation of your program wasn't structured properly.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Did you move the sum into the loop like I was saying? If so, print it out after the loop is finished. Boom that's done. You've got count I think, right. Then you've got average. Keep putting couts in your code in places where you want to check values.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You aren't that far away from it, unless its due in like 30 minutes, but ok suit yourself.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It works. At first I was a little skeptical...

What he's doing is getting a vector full of words that may have an 'h' in them, lopping off the letters before the first h and then writing the modified string back into the vector.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Think of it as an extra layer of misdirection :)

If you code in any kind of organization (or even if you don't), you will inevitably have 180 different Print methods in different classes, some of which will be named Output (just for sake of argument).

Now say 16 divisions got together on a project and pooled all their class resources together into one megaproject. People would be trying to call Print() and getting all kinds of results. You can encase your classes in a namespace (not completely unlike encasing your methods in a class) and be able to tell them apart.

So you can have the output class of production be Production.Output and the Print method be accessed as Production.Output.Print(). If someone wants to use a particular method they can call it by it's fully qualified name. If you know that you're just using the class or method within your own division, you can put a using Production.Output; at the top of your code (conventionally, I suppose it can be anywhere before you call the method, but I may be incorrect about that).

As to your specific question, you can and will have a namespace that crosses multiple files. For instance when you create a winforms application you get a Form1.cs, Program.cs, the design files, etc. that all share a common namespace by default. It's not necessarily a collection of files but for example a certain subset of a dll's classes …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

While loop runs while the condition is true. Hence, if you want it to stop running when one or the other goes under zero you need an &&. It's counter-intuitive at first but just do a quick truth table

cond1             cond2            &&
    T               T                T    (loop continues)
    F               T                F     (loop stops)
    T               F                F     (loop stops)
    F               F                F     (loop stops)

As opposed to having the or where if only either one is false, the || is still true and the loop continues.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

it just doesn't go with the loop anymore

Sure it does. You want to keep a running total, so you want to add into your sum during each cycle. Trace it out by hand to convince yourself (which is a good thing to do with any programming problem).

  1. sum = 0, you enter 10, sum now = old value of sum + x = 0 + 10 = 10
  2. next cycle sum = 10, you enter 25, sum now = 10+25 = 35
    So it's the loop that keeps adding that new x value on.

Also, please use the code tags to surround any code that you post:

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your for loop is problematic. When i =0 it gets stuck since temp[0] !='h' is true.
Try

int count = 0;
while(temp[count] != 'h' && count<temp.size())
                count++;
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

put that section of the code into a do/while loop

do{
      cout<<"Please enter a percent(<.5): "; //you're meaning for 50% right?
      cin >> percent;
      if(percent > 0.5)
               cout << "Invalid.  Re-enter\n";  
       //you could have a break statement within this if 
       //statement but I think it's tidier as is
}while(percent >.5);
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

a should be new at each turn of the crank so to speak, but you only read it in once.
Take a look at the example about 1/4 of the way down the page on this site. You take in your "first" coefficient 2, from 2*x^4, then bn = 2. You take in -3, if you're evaluating at x = 2, then you have 2*2-3 = 1 (using the prior bn, and now updated bn to be 1. There's no incrementing going on and it doesn't matter if this coefficient is less than the terminal one. Since your "an" is different on each step you need to read in a fresh one. You can use your while loop for this but you can change your condition to i < order+1 (but in that case you should certainly initialize i).

Based on all that I ended up with something like:

if(i == 0)
	bn = coeff;
else 
bn = bn*x+coeff;

with all that inside a for loop (but you can use while) along with the statement to get input from the user.

Maybe it's still clear as mud at this point. I just have some difficulty with what you have proposed... I think this is the simplest way to do it (well, iamthrwee's example initializes p using a ghost term inside his loop which is even simpler) but if your method is fundamentally not getting the input it needs I'm not sure how it would …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's rarely a bad idea to initialize something. Were you able to follow iamthwee's example? Post what you've attempted with the revision thusfar and we can straighten it out.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
void SearchNames(string names[], int &rIndex,string &rName,int &rCount_Name)
{

	
	// Basic Binary Search Alogorithm

	/********** Declared Variables **********/

	//all the variables you had here

	
	// Start of Binary Search to find rName & rName
	while ((LowerBound <= HigherBound && Found_rName == 0))
	{
		MiddleBound = (LowerBound + HigherBound) / 2;			
		
		if(names[MiddleBound] == rName)
		{
			Found_rName = 1;
			
			++rCount_Name;
								
		}	


		else if(names[MiddleBound] < rName)
		{
			LowerBound = MiddleBound + 1;
		}
		else
		{
			HigherBound = MiddleBound - 1;
		}
		// This value holds the amount of loops (How many cycles)
		Permutation++;	
	}
	if(Found_rName == 1)
	{
		cout << rName << " Is In The List, " << rCount_Name << " Times. "<<endl;
				
	}
	else 
	{
		cout << rName << " Is Not In The List. "<<endl;
	}										
			
}

I whittled away some things, the search only does one at a time. I think doing both was seriously goofing things up and would turn out to probably be inefficient by pushing your middle point all over the list.

call it in main like: SearchNames(names, rIndex, rName1,rCount_Name); you'll have to swap some of those variable names around.

I also took out the cin.get()s that were inside of the method, since the return to main after the method completes won't clear the screen. You can leave one at the end of main().

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Clipboard::SetDataObject(copyString); See this

EDIT: Beaten again by AD ^^^^

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
while(x!=-999);  //this semicolon ends your while right there
x++;                  //without the semicolon only this would be part of the 
                        //while loop
cout <<" enter a number (-999 to quit)";
cin >> x;

Solution:

while(x!=-999)
{
      x++;
     cout <<" enter a number (-999 to quit)";
     cin >> x;
}

EDIT: AD beat me to it lol

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you were reading strings into your numeric variables before then it should improve things a bit. One way to find out...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Right so it's exactly like what I said. Create some strings to throw away (or just use 1 if you really don't need the labels at all).

string applelabel,tealabel,coffeelabel;
//or just string label;
inputFile >> applelabel;   //or inputFile >> label;
inputFile >> appleP;
inputFile >>tealabel;      //or inputFile >> label;
inputFile >> teaP;
inputFile >> coffeelabel;   //or inputFile >> label;
inputFile >> coffeeP;

That way everything's happening in the proper order.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to take in the order of the polynomial from the user so that you can loop over the Horner's code that many times + 1 and take in the coefficient, do the processing and hang onto the result, all within the loop.

His method evaluate() is correct (EDIT: took a second look). You were adding the calculation back on to the value with the += and that is definitely incorrect.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You have names[MiddleBound] < rNameONE but what happens if the opposite is true? How do the boundaries shift?

Rather than coding the method for rNameONE and another exactly the same for rNameTWO why not have a method that takes in a name and a count for that name, both by reference (index and names too) . Then you can call the method twice from your main(). That way if you want to expand the search to 3 names you have the flexibility.