jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Here is an interesting article how on people keep their banking passwords safe

Mine is "BOSCO" but don't tell anybody.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's gotta be mileage with a lowercase m. Make sure the variables in the set statements match the case of those in the private: section.

You'll see that once you knock a couple of these errors off the rest may be residual.

Some of us are still learning. It doesn't end. Not a bad thing.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

All right, breathe now breathe. All small things:

void car::setMileage(float mile) 
{       //no semicolon after the method definition
     mMileage = mile;
     //mMileage must be a private variable, yours is called something else
}

And for the others, variables are case sensitive.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Anything that's private, forget about using the dot operator with it at all. You're closer:

string carsmake;

	cout << " Please enter Make of car: ";
	cin >> carsmake;  //taking into your temporary
                              // (this presumes a one word car make btw)
	cars.setMake(carsmake); //passes in through your method,
                                 //compiler is happy
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The actual error is in main() in line 34. You have make declared as private in your class so you cannot access it with the dot operator. In the same way as you have a getMake() method, you need a setMake() method to change the private value and act as an "interface" (that word can have other meanings in other situations but I mean it generically) between the outside and your class.

So have a public method void setMake(string inmake) {make = inmake;} EDIT: nice vmanes :)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

you absolutely need one, because of ( matrix (*this) )

Parsing error in my brain in regards to my last post there. I got it now. Apologies.

I had implemented == and != (I had thought they were inline in the header) so I hadn't run into that but it's true that as it were they were non-existent.

Another observation: I'm thinking that += should use + operator, not the other way around.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Why do you have "matrix" on line 79 of your implementation file? Were you trying to cast *this? There's no need to do so. I'm getting responses without crashing, but check they are the right ones.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you post your header up? I can recreate most of it but it's time consuming to do so. More than likely you have an exception that is sneaking past your catch statements but I am not certain of that.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Well, take a step back and ask what are some examples of imperative and critical applications.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Well what are some of the characteristics of imperative and critical applications? (specifically their hardware)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What are some of your ideas? I don't want to spoil your fun.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Don't have to, just giving you the proper credit and verifying that I didn't lie there in wait for you to post and immediately copy what you said. Or it's a bad habit I picked up. Your choice :D

WaltP commented: I'll take it as a bad habit :-) +9
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Either make choice a single character and acquire it by cin.get(choice); (you will need a cin.ignore() after to mop up the '\n'
or use if(strcmp(choice,"Y") ==0) instead of your (choice == "Y") EDIT: D'OH WaltP beat me to it

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Part of the problem is you are trying to read a text file in binary mode. In binary mode you need to use read() to get a block of bytes. I can see how it might read some of the chars in that way but there must be some subtlety that is goofing it up. I would omit the ios::binary and see if that improves things.

Also, why are you trying to read 257 characters into the 256 char array? (that would be valid if you had indexes 0 through 256 but you only have up to 255)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
stringstream ss;
ss <<"Hello"; //send this into the stringstream
cout << ss;    //gives the address of ss
cout <<ss.str();  //gives "Hello"
string mystr = ss.str();
then mystr.c_str() is "Hello\0"

so with ss.str().c_str() we're first taking the stringstream object and using it's str() method to access the string, which we're then calling the c_str() method of that string to get the null terminated one.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can use a stringstream:

#include <sstream>
.....
stringstream ss;
cout <<"Enter store no.:";
cin >> number;
ss <<"Store "<<number;

Then use ss.str() to get the std::string version and ss.str().c_str() to get the c string version for strcmp.
There's probably a different approach that would work but I think this is the most intuitive (for your insert method to work you'd still need the integer as a string).

As far as the adaptability of your code to larger lists it should be fine. Try it out, add some more stores into the file. Add some "junk" in there to throw it off.
The code that VernonDozier gave you should be robust to these changing file size situations (he used the eof because it's fairly certain that your store number won't be the last or second to last line in a valid file). You could use getline to drive your while loop if you were concerned about running into the end of your file. So:

(if infile is your ifstream and chararray is an array of char,40 chars in length)
while(infile.getline(chararray,40)  //#40 so you can store the address ok
{
      if(strcmp( ...etc
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm embarrassed because I thought I had tested it. It turns out that it's trickling down from the cin >> fileName call. Put the cin.ignore() immediately after that line (13 I think*) and take the other one out. I wish I'd seen it before.

*also please use the code tags on your post (that would give the line numbers and keep the formatting):

[code]

//code goes here

[/code]

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Okay, so you have a mean now, but you're still not applying the pow stuff right. Again look at the theory, you are averaging the amount of variation of each point from the mean, squared and taking the square root of it. So it's going to be pow(x1-x,2)+pow(x2-x,2) + etc.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Put in a cin.ignore(); right before your getchar() call. There is probably something left over in the input stream after your getline call (though I think getline should discard the newline but maybe I'm thinking of something else) which is taken in by your getchar ending the first pause.

Another thing to watch out for is your use of !file.eof. Take a look at this thread for an explanation.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm assuming x1 thru x5 are your data points?

The definition of the standard deviation involves first finding the mean of the values.
Then find the variance by summing (the difference between data point i and the mean)^2 divided by either the number of values (for an entire population) or number of values - 1 for a sample.
What constitutes a population is debatable and so you probably have a sample.
Taking the square root of the variance gets you the standard deviation.

Some p-code:

double total;
for loop to find the total of the data points

double average = total/ 5;
double totaldev;

for loop over the data points again
      totaldev += pow((data i - average),2);

sDev = sqrt(totaldev/4);

(obviously I've hardcoded the N values based on the number of parameters you pass in)
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Did you try branching off from your 3 of a kind method?

bool FullHouse;
if (Hand.Card[4].iValue == Hand.Card[3].iValue && Hand.Card[4].iValue == Hand.Card[2].iValue)
{    
      if(Hand.Card[1].iValue == Hand.Card[5].iValue)
             FullHouse = true;
      else
      ThreeOfAKindCard = Hand.Card[4];
}
else if (...) etc.

I know it doesn't combine your pairs check with the three of a kind but if you don't "sequester" the three of a kind cards they'd be counted by the pair finder too. A solution would be to have a pair finding function that you could call both for both finding the pairs and finding the full house.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your function signatures should look like the following:

double getAvg(school &, int);
string getGrade(school &, double);

You turned average into a double which was the right thing to do (but see below) but your function was still returning an int. Why you are getting the weird amount (and no grade) was because you need to pass school in by reference to these 2 functions also (since you are modifying student within the method). I did give you a partial glimpse of this back in post #3.

Since total and 4 are integers, essentially what student.average = total /4; does is do the integer arithmetic (with truncation) and then assigns it to the double as such. You need to cast total (or write 4 as 4.0, or both), so student.average = ((double)total)/4.0; will do the trick (I know there are extra parens but just for clarity)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I took your advice but I get but I am getting errors that total isnt declared, getAvg doesnt take 2 arguments, among others when I try to change student and school, etc.

Probably should repost the code since I don't know where you added and subtracted stuff. Once you get it running it would probably be good to try what vmanes proposed.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No. The 2008 compiler is more compliant with the C++ standard (see something like this for the few ways the 2008 compiler is not compliant-- they don't have a listing for 6.0 any longer) so it may pick up more corrections but it will make your code more compliant by extension.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I believe it's a known problem. I don't have a solution offhand but unless you are needing 6.0 for MFC or ATL work then you should probably grab the 2008 express edition (http://www.microsoft.com/express/Downloads/#2008-Visual-CPP) it does console programs, Win32, and Winforms via C++/CLI.

Ancient Dragon commented: Good advice. +26
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Firstly, please use code tags (there's still time to edit your post and put them in).

For your for loops, you are incrementing your values in your initialization step (and thereby skipping over the first value) and you were losing your last (if you want it) by having a termination condition that was < instead of <=: for ([COLOR="Red"]f++[/COLOR];f<l;f++) in both cases
Use a different variable if you can and have for (int index = f;index <=l;index++) (for example) In that same vein don't use 1 letter variable names, there's no savings there and there is a decrease in readability.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The best way is to pass your struct around (you did it by reference into getInfo() which is fine) So change the prototype of getAvg to take a school & also int getAvg(school &, int total); instead of a student (which isn't known about until you made a variable student of type school in main. Just leave the call to getAvg in main() as it is.

I suspect that in time you'll make an array of structs so you can have multiple students but that will require a few name and type changes.

EDIT: V beat me to it

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yeah, no that's what i saw. It's probably a cleaner approach. It's all good. I was just warning OP about the cast.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

For next time, please use the code tags

[code] //code goes here

[/code]

Count needs to be initialized to zero before the loop, otherwise you're getting whatever junk is in there upon declaration. If you want a space in your output just do outfile<<firstName<<" "; or wherever you want the spaces.

You are right in wanting to take it one step at a time. Once you get this part working try to write out your other values and see what happens.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Add it back in again to your sum. You'll need to make one small change to your if statement (the one to find the minimum) so that it doesn't get -999 each time. average = sum/count; Also see post #20 ^^^^ why this is going to be problematic.

EDIT: Fbody's approach will do too but it doesn't affect the last concern about average = sum/count;

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

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

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

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

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

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.