Search code examples
c++header-filesimplementation

C++ programming project header/implementation files


So i am practicing header files and implementation files for c++ and i cannot seem to display the letter grade for this program. Everything else is working as it should and displaying the correct data except for the letter grade. I have been trying to figure it out and i think it may be something so simple that i am missing but i need an extra set of eyes. i would really appreciate the help!


//Main program
   
#include <iostream>
#include <string>
#include "studentType.h"

using namespace std;

int main()
{
    studentType student;
    studentType newStudent("Brain", "Johnson", '*', 85, 95, 3.89);

    student.print();
    cout << "***************" << endl << endl;

    newStudent.print();
    cout << "***************" << endl << endl;

    return 0;
}


Header File:

#include <string>

using namespace std;


class studentType
{
    private:
        string firstName;
        string lastName;
        int grade;
        int average;
        char courseGrade;
        int testScore;
        int progScore;
        double GPA;

    public:
        studentType(string fn = "", string ln = "", char courseGrade = '*', int tscore = 0, int pscore = 0, double gpa = 0);
        
        string getFirstName() const; 
        string getLastName() const;
        int getGrade();
        char getCourseGrade() const;
        int getTestScore() const;
        int getProgScore() const;
        double getGPA() const;
        

        void setFirstName(string fn);
        void setLastName(string ln);
        void setGrade();
        void setCourseGrade(char courseGrade);
        void setTestScore(int tscore);
        void setProgScore(int pscore);
        void setGPA(double gpa);
        void print();
        
};


Implementation file:

#include <iostream>
#include <string>
#include <iomanip>
#include "studentType.h"

using namespace std;


studentType::studentType(string fn, string ln, char courseGrade, int tscore, int pscore, double gpa)
{
  firstName = fn;
  lastName = ln;
  courseGrade = courseGrade;
  testScore = tscore;
  progScore = pscore;
  GPA = gpa;
}


string studentType::getFirstName() const
{
  return firstName;
}

string studentType::getLastName() const
{
  return lastName;
}

int studentType::getGrade()
{
  return grade;
} 

char studentType::getCourseGrade() const      
{
  return courseGrade;
}

int studentType::getTestScore() const        
{
  return testScore;
}

int studentType::getProgScore() const  
{
return progScore;
}

double studentType::getGPA() const       
{
return GPA;
}


void studentType::setFirstName(string fn)
{
  firstName = fn;
}

void studentType::setLastName(string ln)
{
  lastName = ln;
}

void studentType::setGrade()
{
  int average = (testScore + progScore) / 2;
  
  
  if(average >= 90){
    courseGrade = 'A';
  }
  else if(average >= 80){
    courseGrade = 'B';
  }
  else if(average >= 70){
    courseGrade = 'C';
  }
  else if(average >= 60){
    courseGrade = 'D';
  }
  else{
    courseGrade = 'F';
  }

}

void studentType::setCourseGrade(char courseGrade)
{
  courseGrade = courseGrade;
}

void studentType::setTestScore(int tscore)
{
  testScore = tscore;
}

void studentType::setProgScore(int pscore)
{
  progScore = pscore;
}

void studentType::setGPA(double gpa)
{
  GPA = gpa;
}



void studentType::print()
{
  cout << "Name: " << firstName << " " << lastName << endl;
  cout << "Grade: " << courseGrade << endl;
  cout << "Test Score: " << testScore << endl;
  cout << "Programming Score: " << progScore << endl;
  cout << "GPA: " << GPA << endl;
}

I think it has something to do with the constructor like adding my grade() function but to be honest my brain is fried and i just need some help i have been staring at this for way to long...


Solution

  • You are never calling setGrade(). Maybe you should call it in the class's constructor?