jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Don't just read the names, read the names and the data all at once. Take the loop from the prior post and make it rows to 7. It works.

First0 Last0 54 34 65 34 43 23
First1 Last1 76 54 34 54 23 87
First2 Last2 87 67 45 65 87 67
First3 Last3 45 76 87 65 45 65
First4 Last4 34 65 76 87 56 87
First5 Last5 76 56 78 98 78 67
First6 Last6 87 67 76 87 78 67

was the file I made to test it

1234567890123456789012345678901234567890123456789012345678901234567890
----------------------------------------------------------------------
Student Name        Total     Program   Test      Course    Grade
                    Points    Average   Average   Average
----------------------------------------------------------------------
First0 Last0       253     51.00     33.33     42.17
First1 Last1       328     54.67     54.67     54.67
First2 Last2       418     66.33     73.00     69.67
First3 Last3       383     69.33     58.33     63.83
First4 Last4       405     58.33     76.67     67.50
First5 Last5       453     70.00     81.00     75.50
First6 Last6       462     76.67     77.33     77.00

output is off by a couple of columns but I didn't put a setw in for name

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
for(int i=0; i<count; i++)
   {
  if (highest<num[i])
    highest=num[i];
    highestindex = i;    
}

But remember you may need to add 1 to highestindex before you output it since your text file probably starts with 1. rather than 0.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Does this loop look at all familiar?? (create a names 2D array, change the rows from 4 to 7)

for (int row =0; row<4; row++){
    for(int col=0; col<2; col++)
    fin>>names[row][col];
    for(int col=0; col<6; col++)
    fin>>scores[row][col];
    }// end of outer for

Also you had two ifstreams declared when you meant to have 1 ifstream and 1 ofstream. Make those changes, and add names[row][0] and names[row][1] to your cout, add a matching fout statement and you are good to go.

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

Do you have: average = getAverageGrade(grades, count); back in main()?
(you are trying to send it into your output function but if you haven't returned it to main properly from the getAvgGrade then it will contain garbage)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think the most logical place to put it is right at the very end. If you needed to do it where you print your header you'll have to pass them all in but if you don't need to do it, don't bother.

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

Thanks DS, I totally glossed over it...

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

i goes out of scope (disappears) after your for loop has finished. Divide by count instead

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Swap lines 3 and 5, so you're summing over the rows first and change line 4 to col instead of row. Draw a quick diagram on a piece of paper to see the proper order.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's complaining about line 4 -- if you used row as the loop variable in another for, by the time it exits (you close the brace or you have a single statement for) the variable disappears. Either put a counter to keep track of rows (called rowctr or something) along with the for loop or somehow encompass you column calculation within another larger for loop which steps over rows.

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

Never a prob. Good luck with it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
// William Byrd II

#include <iostream>
#include <string>
using namespace std;

class Person
{
public:
    Person(const string name)
    {
    myName = name;
    }
    
    bool operator==(const Person& p) const
    {
	return (myName == p.myName);
    }

private:
    string myName;
};

// declares Student class as publicly inheriting from the Person class
class Student : public Person 
{
public:
    // implemented constructor for the Student class
    Student(const string name,
            const int studentId)
    : Person( name )
    {
        myStudentId = studentId;
    }
            
    // implemented overloaded equality operator Student class member function
    bool operator==(const Student& s) const
    {
    return (myStudentId == s.myStudentId && Person::operator==(s));
        //since we want a boolean anyway we don't need the if/else
    }

private:
    int myStudentId;
};

int main()
{
    Student app1( "William Byrd II", 8765309 );
    Student app2( "William Byrd II", 8765309 );
    
    // test overloaded == operator for Student class
    cout << "app1" << ( ( app1 == app2 ) 
        ? " == " : " != " ) << "app2"
        << " according to the overloaded == operator\n";
    
    cin.get();  //changed this from your system call
    return 0;
}

I had forgotten to mention that I fleshed out your base class == sorry about that

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

Never a prob.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You don't have a setw call in front of your calculateaverage. It's possible your grade, since it is left biased is bumping up against the average. Otherwise you can pop a few spaces in between with <<" "<< along your cout chain

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

yes and putting return 'A'; etc. within your statements

if (avgstore > 90)
    return 'A';
else if (avgstore >80)
    return 'B';
...
else
    return 'F';
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, and your function should return a char. Sry was trying to make sure you got things in the right place in main()

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

pop in a variable to get that value for use in the subsequent function call

double avgstore;
..... Q6[i] << setw(8) << Final[i] << (avgstore = CalculateAvg (students, id, fname, lname, Q1, Q2, Q3, MidTerm, Q4, Q5, Q6, Final, i));
     cout <<calcGrade(avgstore);   (try it tacked onto the end of the first cout just in case, I wasn't sure if it would be evaluated in the right order)

same for out <<

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster


Alternative approach?

We tried to start OP down that path but she preferred this method (closer to class requirement?)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

void getProbsPerSet(int probsPerSet) should be void getProbsPerSet(int & probsPerSet) to pass in the reference to your variable. The way you had it your cin >> value was falling into the vortex. There are a lot of things in the rest of it that I'm not honestly sure what you are doing but this way you can start to debug those when you have a number of problems with which to work

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I was talking about you using cin >> in the beginning. It is incorrect. cin.get(s,80) is how you get your characters into the array and has nothing to do with the functions.

I'm saying write your functions as if they were for testing one character at a time. Send in the character, your "telephone book" is scanned for it, return which ever results necessary. In the main program, your loop will then send in another and repeat.

As you had it, sending in s[] was incorrect, since if you were sending in the entire array it would be just s. The s[] is in the declaration and definition of the function only.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

First grab a peek at cin.get() http://www.cplusplus.com/reference/iostream/istream/get/ to see how to get those characters into that char array.

Secondly, you have to make some design decisions. Will your functions process the characters (which in your code they must devine on their own with no indicies) being fed into them one by one or the whole string? I think you want to choose one by one, it keeps the messy array from bouncing around and if you wanted to put in just 'A' to your functions one day you can.

So, use a for loop to march through your string in main, sending the chars (and chars alone) to your functions, so s. Next, clear out the s[] junk from the functions and just treat it for a char s. Compare it with your string and once it matches return the upper or lowercase character only.

Back in main I did this

for (int i = 0;s[i] !='\0';i++) 
 {
	if ( is_upper (s[i]) )
            cout <<s[i]<<"The lowercase equivalent is: "<<to_lower ( s[i] )<<endl;
        //your other fun here
}

so displaying it char by char next to the original. Change that up if you need it to meet your spec.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The code from post #4 ran on my machine and produced an output file.

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

Then use your existing void function definition, change the return type of the function to double and instead of cout, return the value that you get for the average.

(not that you want to overhaul everything but in another post user "fbody" was recommending putting all the scores for one student in one array (or as one row of a 2D array) -- my take would be that way you could find the lowest member and its index, zero that one out and divide by 7 instead of 8)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Children cant access fields of the parent class. Add accessor and mutator methods to Animal to allow access to these fields from the children.

I reserve the right to be wrong (lol) but aren't these public members OP is trying to access via public inheritance?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Since your classes are really pointers you need the -> operator to dereference and dot them (*A.member() is the same as A->member() )

(also, instead of iostream.h #include<iostream> and instead of stdlib.h #include<cstdlib> and <ctime> in place of time.h -- these are the standard headers you should be using -- unless you're really attached to pre 1998 for some reason)

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

My code is readable if you plug it into a compiler of some sort, but it isn't readable within the confines of the forum for some reason.

If this happens, copy and paste to notepad (or another plain text), save the notepad file, and copy and paste from there.

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

I should have tested it further, apologies. I thought I had it but it kept crashing after the word was entered

It's not exactly what you want but it requires an enter press after "lolsup" is entered

private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter)
                if (textBox1.Text.Contains("lolsup"))
                {

                    textBox1.Text += "\r\nClient: Hey";
                    textBox1.SelectionStart = textBox1.Text.Length;
                    textBox1.ScrollToCaret();
                }

        }
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

Just take away the <=10 and substitute in <10, going less than or equal to will overstep your array.

Also, you can accomplish the first part with just the loop variables (no need for n) ;)

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

I meant to ask before but didn't, why is names a 2D array? I'd just make it 1D and dump that second for loop for(int col=0; col<3; col++) .

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

put a do-while loop around the whole thing, prompting the user at the end

string response;
do
{
      //your code here
      response = Console.ReadLine();
}(while response != "Yes" && response !="yes") ;
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

use fin >> and since you know the order of the line (1 string, 6 numbers, 1 string, 6 numbers, etc.) make a nested for loop (rows and then columns) to put them in their proper variables.

P.S. It doesn't matter too much, but if you are going to do that color thing at least put it back to the way it was or do away with it altogether.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Shouldn't line 32 just be p = i+p; (or p+=i; )? That way you put your interest into principal and iterate again.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
char c = 'A';
char d = c ^ 0x20;  //'a'
char e = d ^ 0x20; //'A' again

The regular OR only works in one direction(from upper to lower)
also you could just add or subtract 32 from the char if it's easier.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try yourtextbox.Text +="Your new line of text here \r\n"; That gives you a carriage return and newline, and do this for every line that you add.