jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your if statements should look more like this:
(you must change the y<=X<= z statements but you don't absolutely have to have the else if, but it's more efficient if you don't have to go through a bunch of if statements)

if ( comission <= 299 )
	        ++count1;

	else if ( comission>=300 && comission <= 399 )
	        ++count2;

	else if ( comission >=400 && comission <= 499 )
		++count3;

        etc.
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No, you want to go from 0 to side, since you loop is j<side, in this case side is 4, giving 0 1 2 3 (so 4 stars). You don't need the star at the beginning either.

So it goes:

for loop (over the rows)
{     
         for loop over the stars
         {
                 Print stars
         }

         line break (cause once we're done here we're off to the next row 
                           in the loop)
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In main() you don't need the void in front of displayBoard() like you do in the prototype up above.
Is there no definition for the displayBoard() either?
It doesn't seem like you have quite enough to be running it yet. It might compile but that's just a step in the right direction.

Also, next time please use code tags surrounding your code, it's part of the site rules and makes it easier to read.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You don't need it:

int i = 0;
while(input>>employee[i].spotnumber)
{
      input >> employee[i].driver_name;
      input >> employee[i].car_reg;
      i++;
}

Search the threads on this site about eof and why it's not reliable. E.g., http://www.daniweb.com/forums/thread19956.html , post #18 on that thread. (that thread/article is also the 5th sticky post down at the top of this forum)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How in the world am I supposed to "get" the first fraction to multiply it with the second one???

You have it. Read up in your text about the *this pointer. You've formed this object and now it has a reference to itself:
this->numerator and this->denominator are the values for the current object (since the object and any other objects of the class can "see" its private members). So in your frac1s that you are passing in, the numerator and denominator will be visible (but invisible to other classes since they are private.

So for the addition operator for example, declare a new fraction local to that block, Fraction fracresult; or something:
fracresult.numerator = (this->numerator x denominator of frac1) + (numerator of frac1xthis->denominator); (standard formula for adding two fractions - now the denominator will be the product of the denominators and set equal to fracresult.numerator)
The reason you need the -> is that the object has a reference to *this, so you need to dereference and . to access the method and arrow is a shortcut for that.

EDIT: Well there's an outpouring for you. What he said definitely works too (with using the constructor) -- though you shouldn't need an accessor (getter) between two objects of the same class, but it couldn't hurt to add one (though I think you said you are limited by the assigned header file) for other classes to interact with.

Agni commented: my bad, thanks for correcting :) ... +2
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I believe (I had to try a little example) that it's float*

float a[2] = {4.0,5.7};
	float b[2] = {1.3,9.8};
	string label1 = "label1";
	string label2 = "label2";

	map<string, float *> mymap;

	mymap[label1] = a;
	mymap[label2] = b;
	cout <<mymap[label1][1]<<endl;

output is 5.7

metdos commented: Simple, clear and fast answer. Thanks :) +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's here:
(I helped him on the other post -- mcap, I think you got the abbreviated URL when you cut and pasted)

I think you should use std::list, and no pointers if it's not neccessary!

We can probably do some "duck typing" (go against the C++ grain for a second) on it and find it's an assignment

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Put some //code goes here tags around your source. Also, you can add to your old post you didn't have to start a new one.

Are you allowed to use an array for this? That's probably the easiest way. Create a temporary variable to hold the high and one to hold the low, set them to appropriate values. Walk along your array and check if the current number is higher than the highest you have(in your temporary variable), if so then replace your temporary variable with the current number which is now the highest.

int lowest;
int highest;
for loop
{
      if lowest > current
             lowest = current;
      if highest < current
              highest = current;
}

Also, use #include <iostream> instead of iostream.h

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I retooled your method a little bit:

void add_names()
{   //name *temp, *temp2;
    //temp = new name;
    name * prior = new name;// * temp;
    int ranking;
    int i=0;
    string male_name, female_name;
    ifstream in_stream("babynames2004.txt");
    
    //in_stream.open; //opens and loads names & ranks from file
    if (in_stream.fail())
   {
    cout << "File failed to open." << endl;
    cout << "Program will now close." << endl;
    system("PAUSE");
    exit(0);
   }
    
    in_stream >> ranking>>male_name >> female_name;
	
    
    prior = start_ptr;
    prior->rank = ranking;

    prior->boy_name = male_name;
    prior->girl_name = female_name;
    prior->nxt = NULL;
    
    name *temp;
	while(in_stream >> ranking >> male_name >> female_name)
    {
    
    temp = new name;
    prior->nxt = temp;
    
    temp->rank = ranking;
    temp->boy_name = male_name;
    temp->girl_name = female_name;
    temp->nxt = NULL;
    prior = temp;
    
    }
    temp->nxt = NULL;
    
    for (name * strt = start_ptr;strt->nxt !=NULL;strt=strt->nxt)
           cout<<strt->rank<<" "<<strt->boy_name<<endl;
}void add_names()
{   //name *temp, *temp2;
    //temp = new name;
    name * prior = new name;// * temp;
    int ranking;
    int i=0;
    string male_name, female_name;
    ifstream in_stream("babynames2004.txt");
    
    //in_stream.open; //opens and loads names & ranks from file
    if (in_stream.fail())
   {
    cout << "File failed to open." << endl;
    cout << "Program will now close." << endl;
    system("PAUSE");
    exit(0);
   }
    
    in_stream >> ranking>>male_name >> female_name;
	
    
    prior = start_ptr;
    prior->rank = ranking;

    prior->boy_name = male_name;
    prior->girl_name = female_name;
    prior->nxt = NULL;
    
    name *temp;
	while(in_stream >> ranking >> male_name >> female_name)
    {
    
    temp = new name;
    prior->nxt = temp;
    
    temp->rank = ranking;
    temp->boy_name = male_name;
    temp->girl_name = female_name;
    temp->nxt = NULL;
    prior = temp;
    
    }
    temp->nxt = NULL;
    
    for (name * strt = …
mcap61 commented: Saved my life on a project thanks so much +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Quoth the Dragon: gotoxy() is a function only supported by Turbo C and Turbo C++

I meant that your professor wants you to use these Borland functions :) so upgrade her/him to work with your Microsoft compiler

Salem commented: They should upgrade their professor to someone whio actually has a clue about something less than 20 years out of date +17
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

YW, sorry I didn't catch it in the first place. Never a prob, post back anytime :)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Scope. Your filename variable is out of scope by the time you're back up to main(). So either return it from headerfn() or pass it in by reference, or just put it back up in main(). Technically since your fin and fout are global (which they probably shouldn't be) you can open the file in headerfn() and it will be available elsewhere. But, I would recommend roping fin and fout into main and pass in the filename string by reference).

Nick Evan commented: Rep for helping in this monster-thread +11
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Because your input file has your names, then the scores for the name. What you have would work if the file only had names in it. Go back and grab your other post as you had the input down quite well in that one. I've gotta be off for a while, but I'll check back later. You've done a great job so far and you're really close to the end (unless your program has some hidden features you're not revealing hehe).

amishraa commented: Very helpful and patience enough to analyze and work through problems. He deserves a gold medal! :) +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Pop some code tags on there while you can still edit.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
for loop over your whole set
{
     cout <<firstname[row]  <<" "<<  lastname[row];  
     for (column 1 to 6)
           cout <<scores[row][column]<<" ";
     cout << total[row] <<" "<<progave[row]<<" " <<testavg[row] 
               <<courseavg[row];
    cout <<endl;     //put all your setw type stuff in place of the " "as 
                              //needed
}

since if you don't put a endl in there, it all comes out on the same line

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Do this to initialize your arrays: float progavg[7]={0}, testavg[7]={0}, progsum[7]={0}, testsum[7]={0};

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Nice! How much does the calculated average deviate from the hand calculation?

EDIT: I see what you mean something is undefined somewhere

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I had meant for you to write out the code for the testavg portion of this for loop. Don't display anything yet. Look at the second for loop. How does the row value change over those 3 column values? it doesn't.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
double progave[7], testave[7], progsum[7], testsum[7];
for (int row = 0;row<7;row++)
{ 
        for (int col = 0;col<3;col++)
            progsum[row] += scores[row][col];
        progave[row] = (double)progsum[row]/3;

        (now you can fill in the next one)
}

You had the code for the display method in the other thread...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Or put an if statment in

if (iterations greater than 1000 && it's Wednesday)
                cout <<"Super";

and set a breakpoint at the second line. I think the fancier versions of VS have conditional breakpoints but I don't believe the EEs do.

Of course the low-tech version would be to output relevant results to the terminal (and redirect output to a txt) or write to a file directly -- then use your favorite text editor to search for the conditions you seek.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

float colavg[b][6][/b]; Also in your second for loop you wrote row for the index and I think you meant col

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Are you having trouble with the calculation or the output? You already have the row and column totals, just divide by the total number (you'll have to cast the numerator (or both numerator and denominator) to double -- like rowaverage[i]=((double)rowtotal[i])/7; For the output it will be just like the one in the other program, for loop over the rows{ output names, for loop over scores, output average for the row} next row, etc, then on the final row print the column averages.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Just a couple of small changes:

Circle C1; //no () after a default constructor call
	//C1.setRadius();  not sending anything in so there's no point
         //requires a double to be passed in so not overloaded for void
	cout << "Here is the circle C1's data:\n";
   	cout << "Radius: " << C1.getRadius() << endl;
   	cout << "Diameter: " << C1.getDiameter() << endl;
   	cout << "Circumference: " << C1.getCircumference() << endl;
   	cout << "Area: " << C1.getArea() << endl;

	Circle C2(0.0);  //were trying to send in "double r" doesn't make sense for a call  (could have set r = 0.0; and Circle C2(r); )
richman0829 commented: This was lots of help; almost all done now. +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

just for kicks try renaming your file to lab11_2.cpp see if that's what it's complaining about (after you try putting the static part in because that is important) -- it really shouldn't make any difference but it's highlighting the .2 in the filename in red.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I don't know if this first part has anything to do with it, but were you writing your strings in another program, because the quotation marks on line 50 and the apostrophe on line 55 are the "curly" ones used by word processors and are interpreted differently by the compiler (as ASCII 147 and 148 for the quotes)

It's more likely a problem with your PI constant. Constants in classes need to be static http://www2.research.att.com/~bs/bs_faq2.html#in-class or an enum. So make it static const double PI = 3.1416;

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Never a prob. Good luck with it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you call Person::operator==(s) in the derived class and AND the results with your derived class comparison?

so like:

bool operator==(const Student& s) const
    {
    return (myStudentId == s.myStudentId && Person::operator==(s));
    }

EDIT: I did test it out and it seems to work.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I ran across this (pursuing it out of curiosity) http://services.aonaware.com/DictService/ I have never used it and I'm not sure what the licensing terms are.

ddanbe commented: He, great site! Even has C# code! +5
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can call it whatever you want in the function, but yes I meant back in main keep an intermediate variable of your average function output and then feed that back into your grade function. I was just saying don't put them all on the same line because I'm not 100% sure if the grade function will be called before the other comes back with the value.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Cause you don't need the () on a default constructor. It thinks you defining a function.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
if
 return X;
elseif
  return Y;
elseif
  return Z;

only one will be called -- actually you should probably have an else on that chain also)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Instead of

float total = scores[0][0]+scores[0][1]+scores[0][2]+scores[0][3]+scores[0][4]+scores[0][5];
    float pavg = (scores[0][0]+scores[0][1]+scores[0][2])/3.0;
    float tavg = (scores[0][3]+scores[0][4]+scores[0][5])/3.0;
    float cavg = pavg+cavg;

try

float total[6];  or go wild and double total[6];
double pavg[6];
double tavg[6];           //I forgot if there were 3 or 6 students
double cavg[6];
for (int i = 0;i<STUDENTS;i++)   or however many students you have now)
    {
      for (int j = 0;j<5;j++)
          total[i] += scores[i][j];
    
      pavg[i] = same thing (for loop over ones you want)
     tavg [i]= same thing (for loop over ones you want)
     cavg[i] = pavg[i]+cavg[i];
}

Then for display
for (int i = 0;i<STUDENTS;i++)
      { 
       cout<<name[i][0]<<" "<<name[i][1];
       for (over scores)
               cout <<scores[i][j]<<" ";
      cout<<total<<average1[i]<<average2[i]<<average3[i]<<endl;
}

I took some liberties but you get the idea.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Sorry to triple post

if ((Q1[i] < Q2[i] && Q3[i] && MidTerm[i] && Q4[i] && Q5[i] && Q6[i] && Final[i]) &&
(Q1[i] != Q2[i] && Q3[i] && MidTerm[i] && Q4[i] && Q5[i] && Q6[i] && Final[i]))

is one of those statements to which firstPerson was referring -- it needs to be if ((Q1[i] < Q2[i] && Q1[i]<Q3[i] && Q1[i] <MidTerm[i] && ....) && etc.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Within your block

for (i = 0; i < 6; ++i )
{
          if ( students >> studentid[i] >> fname[i] >> lname[i] >> Q1[i] >> Q2[i] >> Q3[i] >> MidTerm[i] >> Q4[i] >> Q5[i] >> Q6[i] >> Final[i])

you have cout << all your stuff
CalculateAverage() //prints out one average (no line break or spaces)
out << all your stuff //sends to file silently
CalculateAverage() //prints out the second avg

So bring back your average function that returns a double, tack that on the end of your << chain (for both cout and out, e.g cout << var1<<var2<< Final<<CalculateAverage()<<endl;) and you'll have your average once and getting sent to the right spots.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
for (int i = 0;i<3;i++)
	{	
                cout <<names[i][0]<<" "<<names[i][1]<<" ";
		for(int j = 0;j<6;j++)
		{
			cout <<scores[i][j]<<" ";
		}
		cout <<endl;
	}

You can't use << with the array, unfortunately.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's a bit too much hard coding for me but how about

int strcnt = 0;
	for (int i=0;i<3;i++)
	{
		fin>>names[strcnt][0];
		fin>>names[strcnt][1];
		strcnt++;
                
                //inner loop etc.
      }
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The {0,20} is a placeholder and format specifier for a variable that was in the other example you had. For example:

int i = 1;
char a = 'a';
double pi = 3.14159;
Console.WriteLine("{0} {1} {2}",i,a,pi);

prints out: 1 a 3.14145 (each placeholder is replaced by the value)

So for your application, you can just simply make it one string: Console.WriteLine("Year Rate Amount Interest New Amount"); or if you want the year in there Console.WriteLine("Year {0} Rate Amount Interest New Amount",year);

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Why not change calculateAverage to return a double (so your average isn't truncated) and call the function in place from your "out" processing.

double CalculateAvg (ifstream& students, string studentid[60], string fname[60], string lname[60], int Q1[60], int Q2[60], int Q3[60], int MidTerm[60], int Q4[60], int Q5[60], int Q6[60], int Final[60],int i)
{
    return ((Q1[i] + Q2[i] + Q3[i] + MidTerm[i] + Q4[i] + Q5[i] + Q6[i] + Final[i]) / 8);
   //scratch my earlier response, you want to pass in i to get which student to average
// and the fact that you were reading in stuff in this function was "using up" lines of your file		
}

and

out << left << setw(13) << studentid[i] << setw(12) << fname[i] << setw(8) << lname[i] << setw(7)<< Q1[i] << setw(7) << Q2[i] << setw(7) << Q3[i] << setw(7) << MidTerm[i] << setw(8)
<< Q4[i] << setw(7) << Q5[i] << setw(8) << Q6[i] << setw(8) << Final[i]<<CalculateAvg (students, id, fname, lname, Q1, Q2, Q3, MidTerm, Q4, Q5, Q6, Final,i);

That way you have the calculation the way you want it and can format the return value in whatever way you want.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Get rid of infile>>row>>col; on line 39, it's reading in 0,0 and throwing it out.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

OK, I gotcha now. Well you still need to assign something to the bacteria[row][col] for it to show up in your array.

while(infile>>row>>column)
           bacteria[row][col] = 1;

will work. But as part of your design considerations you need to decide what you want those cells to be -- is integer best, or boolean? In other words what will "store' the state of the system the best between iterations.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Is a 2D array the best choice here? You have more than one value corresponding to each "row" number?

infile>>row>>col;
    
     while(infile)
     {
     bacteria[row][col];
     infile>>row>>col;
     }
     infile.close();

should probably be something like

int i=0;
while(infile>>row>>column)
{
           bacteriaX[i] = row;
           bacteriaY[i] = column;
           i++;
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Compare each value to zero, if f(0) < 0 && f(1) > 0 then search in between them (so theoretically you could space your function values at say 5 apart or something and then zero in on it. 5->2.5->1.25 within one interval.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This time you don't need all that precision. Take the fixed and setprecision statements off of the cout(I only told you 7 digits last time so you could see error at 10^-6). P is missing zero by a minuscule amount and continuing. There may be other errors because the approx is off by about 1. Also, you should check your denominator in your Laguerre's calculation against zero to make sure that won't crash the program.
I'm not sure why changing the precision would affect the calculation?? aside from the output. One thing though that this brings up is that it is difficult if not impossible to use == with floats or doubles due to these conditions where you can be so close to zero and not quite zero. So you can do things like myvariable <= 0.00000000001 or something (or take the difference between your variable and an ideal myvariable - ideal < 0.000000001 etc.).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Summary of all of the above:
change poly to

void poly(vector<double> A, vector<double> & B, double x, double& p, double& px, double& pxx, int & degree);

(and if you need A for another segment of your program change it to a reference too)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That's not garbage, that's floating point for ya. Change line 84 (just for illustrative purposes) to cout << "The next midpoint, approximation is " <<fixed<<setprecision(7)<< x2 << endl; and include <iomanip>. Your answers had some roundoff when they were displayed and that roundoff is on the order of 10^-6 hence your "garbage."

btw, I understand your response from before, but until I used it my way I was getting that nothing had roots!

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Dang, I'd only seen the this thread is closed message.
I was hoping "they" would put something stronger in place because I can't stand the 4 year old nicely resolved and already complete threads with the "I want the C++ codez for [canonical pedagogical program here]" tacked on the end of it.
Well, my apologies for being a "day" late (and definitely a dollar short) on noticing that (but maybe it's good cause I got to air my grievance about resurrected threads).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Is that "this thread is over three months old" warning new(it's possible I totally missed it before)? Either way I like it!!

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
#define MAX 999   (no equals)

And you create all_names out of nowhere in two of your functions

It doesn't really matter _that_ much, but this is more of a C program than a C++ one :)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Parent class functions that need to be different than their parent class counterparts must be labeled virtual. This lets the compiler know that the method will be attached dynamically (i.e., depending on the type of the object at runtime). If I have a class called hasmotoroutside I can derive and create a car and a lawnmower from it, which can both be stored in a garage (or an array of hasmotoroutside objects) but when it comes to the start function of hasmotoroutside, it must be virtual because in the mower it consists of pullcord and the car it conisists of turnkey.

So really all you have to do is declare your virtual function with that keyword. It's important for things like destructors when if you allocate memory in a derived class you sure don't want the compiler to leak that memory if the parent's destructor were to step in.

Just remember the underlying assumption to all this. An array can hold objects (or pointers to objects) that have the same base class even if they are of a derived class.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Well, the way you have your for loop set up to see at which property the player resides, you are perhaps moving it to the last property regardless of where it started. Perhaps once a move is made you should break; from the for loop and proceed on to the next turn.