My program is compiling fine but my issue is with the output. The grades are not correct and the counters are not working either. If anyone can help that would be great.

//stud.cxx
#include "stud.h"

studType::studType(int idVal, float exam1Val, float exam2Val, float exam3Val)
//*********************************************
{
  id = idVal;
  exam1 = exam1Val;
  exam2 = exam2Val;
  exam3 = exam3Val;

}

studType::studType()
//*********************************************
{
  id = -111;
  exam1 = -100;
  exam2 = -100;
  exam3 = -100;
}

void studType::readRd(ifstream& inFile)
//*********************************************
{
  inFile >> id >> exam1 >> exam2 >> exam3;
}

void studType::writeRd(ofstream& outFile)
//*********************************************
{
  outFile.setf(ios::fixed);
  outFile.setf(ios::showpoint);
  outFile.precision(2);
  outFile << id << setw(10) << exam1 << setw(10) << exam2 << setw(10)
          << exam3 << setw(10) << avg;
}

void studType::findAvg(studType& rd)
{
  avg = float(exam1 + exam2 + exam3) / float(3);
}

bool studType:: validRd(studType& rd)
{
  const int MAXEXAM = 100.00;
  const int MINEXAM = 0.00;
  const int MINID = 111;
  const int MAXID = 999;

  if(id >= MINID && id <= MAXID && exam1 >= MINEXAM && exam1 <= MAXEXAM &&
     exam2 >= MINEXAM && exam2 <= MAXEXAM && exam3 >= MINEXAM && exam3 <= MAXEXAM)
    return true;
  else
    return false;
}

float studType::findMax(studType& rd)

{

  if((exam1 || exam2 || exam3) > max)
    {
      if(exam1 >= exam2 && exam1 >= exam3)
        max = exam1;
      if(exam2 >= exam1 && exam2 >= exam3)
        max = exam2;
      if(exam3 >= exam1 &&  exam3 >= exam2)
        max = exam3;
    }
  else
    return max;
}


float studType::findMin(studType& rd)
//*********************************************

{
  if(exam1 || exam2 || exam3 < min)
    {
      if(exam1 <= exam2 && exam1 <= exam3)
        min = exam1;
      if(exam2 <= exam1 && exam2 <= exam3)
        min = exam2;
      if(exam3 <= exam1 && exam3 <= exam2)
        min = exam3;
    }
  else
    return min;
}


void studType::printMax(ofstream& outFile, studType rd)
//**********************************************************

{
  if(max > 0.00 && max < 100.00)
    outFile << "Max Valid Exam:" << max << endl;
  else
    outFile << "NO VALID MAX!" << endl;
}


void studType::printMin(ofstream& outFile, studType rd)
//********************************************************
{
  if(min < 100.00 && min > -100.00)
    outFile << "Min Valid Exam:" << min << endl;
  else
    outFile << "NO VALID EXAMS!" << endl;
}

void studType::printInvalidDataMsg(ofstream& outFile)
//********************************************************
{
  outFile.setf(ios::fixed);
  outFile.setf(ios::showpoint);
  outFile.precision(2);
  outFile << id << setw(10) << exam1 << setw(10) << exam2 << setw(10)
          << exam3 << setw(30) << "~~ Invalid Data ~~";
}
//stud.h
#include <fstream>
#include <iostream>
#include <iomanip>

using namespace std;

const int MAXEXAM = 100.00;
const int MINEXAM = 0.00;
const int MINID = 111;
const int MAXID = 999;

class studType
{
  public:
    studType(int idVal, float exam1Val, float exam2Val, float exam3Val);
    studType();
    void readRd(ifstream& inFile);
    void writeRd(ofstream& outFile);
    void findAvg(studType& rd);
    bool validRd(studType& rd);
    void setRd(int idVal, float examVal);
    void printInvalidDataMsg(ofstream& outFile);
    float findMax(studType& rd);
    float findMin(studType& rd);
    void printMax(ofstream& outFile, studType rd);
    void printMin(ofstream& outFile, studType rd);

  private:
  int id;
  float exam1;
  float exam2;
  float exam3;
  float avg;
  float max;
  float min;
};
//extStud.h
#include <fstream>
#include <iostream>
#include <iomanip>

const int MAXEXAM2 = 100.00;
const int MINEXAM2 = 0.00;
const int MAXID2 = 999;
const int MINID2 = 111;

using namespace std;

class extStudType
{
  public:

    void readRd(ifstream& inFile);
    void invalidId(ofstream& outFile);
    void printHeading(ofstream& outFile);
    void findAvg(extStudType& extStud);
    void findGrade(extStudType extStud);
    void printGrade(ofstream& outFile);
    void printGradeStats(ofstream& outFile);

  private:
  int id;
  float exam1;
  float exam2;
  float exam3;
  float avg;
  int aCount;
  int bCount;
  int cCount;
  int dCount;
  int fCount;
  char grade;
};
//extStud.cxx
#include "extStud.h"

void extStudType::readRd(ifstream& inFile)
{
  inFile >> id >> exam1 >> exam2 >> exam3;
}

void extStudType::invalidId(ofstream& outFile)
{
  if(id <= MINID2 || id >= MAXID2)
    outFile << "~Invalid Id~" << endl;

}

void extStudType::printHeading(ofstream& outFile)
{
  outFile << "A's" << setw(6) << "B's" << setw(6) << "C's" << setw(6)
          << "D's" << setw(6) << "F's" << setw(6) << endl;
  outFile << left << "--" << setw(6) << "--" << setw(6) << "--"
          << setw(6) << "--" << setw(6) << "--" << setw(6) << endl;
}

void extStudType::findAvg(extStudType& extStud)
{
  avg = float(exam1 + exam2 + exam3) / float(3);
}

void extStudType::findGrade(extStudType extStud)
{
  int aCount = 0;
  int bCount = 0;
  int cCount = 0;
  int dCount = 0;
  int fCount = 0;

  if(avg <= 100.00 && avg >= 90.00)
    {
      grade == 'A';
      ++aCount;
    }
  else
    if(avg < 90.00 && avg >= 80.00)
      {
        grade = 'B';
        ++bCount;
      }
  else
    if(avg < 80.00 && avg >= 70.00)
      {
        grade = 'C';
        ++cCount;
      }
  else
    if(avg < 70.00 && avg >= 60.00)
      {
        grade = 'D';
        ++dCount;
      }
  else
    if(avg < 60.00)
      {
        grade = 'F';
        ++fCount;
      }

}

void extStudType::printGrade(ofstream& outFile)
{
  outFile << setw(7) << grade << endl;
}

void extStudType::printGradeStats(ofstream& outFile)
{
  outFile << aCount << setw(6) << bCount << setw(6) << cCount << setw(6)
          << dCount << setw(6) << fCount << setw(6) << endl;

}
#include "stud.h"
#include "extStud.h"

int main()
{
  ifstream inFile;
  ofstream outFile;
  inFile.open("in.data");
  outFile.open("out.data");

  if(inFile.fail() || outFile.fail())
    {
      outFile << "Input file or output file opening failed" << endl;
    }
  outFile << "*~< Student Exam Report >~*" << endl;
  outFile << "Id" << setw(10) << "Exam1" << setw(10) << "Exam2"
          << setw(10) << "Exam3" << setw(10) << "AVG" << setw(10) << "GRADE" << endl;
  outFile << "--" << setw(10) << "-----" << setw(10) << "-----"
          << setw(10) << "-----" << setw(10) << "---" << setw(10) << "-----" << endl;

  studType rd;
  extStudType extStud;
//  extStud.readRd(inFile);
  rd.readRd(inFile);
  while(inFile)
    {

      if(rd.validRd(rd))
        {
          rd.findAvg(rd);
          extStud.findAvg(extStud);
          rd.findMax(rd);
          rd.findMin(rd);
          extStud.findGrade(extStud);
          rd.writeRd(outFile);
          extStud.printGrade(outFile);
        }
      else
        {
          rd.printInvalidDataMsg(outFile);
          extStud.invalidId(outFile);
        }
      rd.readRd(inFile);
    }
  outFile << " " << endl;
  rd.printMax(outFile, rd);
  rd.printMin(outFile, rd);
  outFile << " " << endl;
  extStud.printHeading(outFile);
  extStud.printGradeStats(outFile);
  outFile << " " << endl;
  outFile << "*< end >*" << endl;

  return 0;
}

My program is compiling fine but my issue is with the output. The grades are not correct and the counters are not working either.

You'll get more help if you tell us what grades you expect to see, not just that they're "not correct." What output are you expecting? But first, what input are you feeding your program? It's looking for " in.data " but you haven't included that here.

The code is not "compiling fine," at least using GCC. I see three warnings in my compiler output; they all indicate areas in your code that need some attention. Always, always pay attention to your compiler warnings; they usually point at something weird going on.

In extStud.cxx, extStudType::findGrade :

grade == 'A';

I'm sure you meant grade = 'A'; there.

In stud.cxx : Both findMax and findMin don't always return a value. Look at your if / else statements; do you see why?

Also, in findMax :

if((exam1 || exam2 || exam3) > max)

This is not how to use an if statement to test multiple conditions. Try this:

if((exam1 > max) || (exam2 > max) || (exam3 > max))

Same goes for findMin .

Sorry I forget to put up the input and output samples, here they are. Thank you for your help.

Input:
111 75 80 70
222 91 91 92
110 0 0 87.5

Output:
*~< Student Exam Report >~*

Id Exam1 Exam2 Exam3 AVG Grade
111 75.00 80.00 70.00 75.00 C
222 91.00 91.00 92.00 91.33 A
110 0.00 0.00 87.50 ~~ Invalid data! ~~ Id is invalid

Max Valid Exam: 92.00
Min Valid Exam: 70.00

As Bs Cs Ds Fs
1 0 1 0 0

*< end >*

The problems I am still having is the printing of the grades in the report and at the bottom, finding and printing the min exam score, and the invalid id print out. If you have any input on what should be changed that would be very helpful. Thanks

The telltale sign of a student programmer is a statement like

if(id >= MINID && id <= MAXID && exam1 >= MINEXAM && exam1 <= MAXEXAM &&
exam2 >= MINEXAM && exam2 <= MAXEXAM && exam3 >= MINEXAM && exam3 <= MAXEXAM)
    return true;
else
    return false;

Which is mostly unreadable.
Split the statement into multiple IFs and return false if any IF is FALSE. If they are all good, return TRUE.

Alright thank you, what should I do to help correct my other errors?

The errors that I am still getting are the invalid id message is printing for every invalid data even if the id is correct. The grades are not printing out correctly either, every grade is a F. Also the grade counters are not working at all either they are giving random numbers like 0 41976350 -44000068032767. I was wondering what needs to be done to correct these things, I have done everything that I can think of/know how to do.

The errors that I am still getting are the invalid id message is printing for every invalid data even if the id is correct. The grades are not printing out correctly either, every grade is a F. Also the grade counters are not working at all either they are giving random numbers like 0 41976350 -44000068032767. I was wondering what needs to be done to correct these things, I have done everything that I can think of/know how to do.

Sounds like you've made some changes; we'll need to see them to help with what's left... please post the updated files. Maybe as attachments this time; it's easier for us than copying/pasting everything.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.