Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Course Grades In a course, a teacher gives the following tests and assignments:

ID: 3812367 • Letter: C

Question

Course Grades
In a course, a teacher gives the following tests and assignments:
• A lab activity that is observed by the teacher and assigned a numeric score.
• A pass/fail exam that has 10 questions. The minimum passing score is 70.
• An essay that is assigned a numeric score.
• A final exam that has 50 questions.

Write a class named CourseGrades . The class should have a member named grades that is an array of GradedActivity pointers. The grades array should have four elements, one for each of the assignments previously described. The class should have the following member functions:

The student’s essay score can be up to 100, and is determined in the following manner:

• Grammar: 30 points
• Spelling: 20 points
• Correct length: 20 points
• Content: 30 points


setLab : This function should accept the address of a GradedActivity object as its argument. This object should already hold the student’s score for the lab activity. Element 0 of the grades array should reference this object.


setPassFailExam : This function should accept the address of a PassFailExam object as its argument. This object should already hold the student’s score for the pass/fail exam. Element 1 of the grades array should reference this object.


setEssay : This function should accept the address of an Essay object as its argument. This object should already hold the student’s score for the essay. Element 2 of the grades array should reference this object.


setPassFailExam : This function should accept the address of a FinalExam object as its argument. This object should already hold the student’s score for the final exam. Element 3 of the grades array should reference this object.


print : This function should display the numeric scores and grades for each element in the grades array.


Demonstrate the class in a program. This is C++ focusing on inheritance. Please read the instruction carefully, and don't post handwriting code.

Explanation / Answer

CourseGrades.h

#include <string>
#include <vector>

namespace course { class GradedActivity; }
namespace course { class Essay; }
namespace course { class FinalExam; }

namespace course
{

   class CourseGrades
   {
   private:
       std::vector<GradedActivity*> grades;
       static int NUM; //grades array having four elements

   public:
       CourseGrades();
       virtual void setLab(GradedActivity *lab);
       virtual void setPassFailExam(PassFailExam *pfe);
       virtual void setEssay(Essay *essay);
       virtual void setFinalExam(FinalExam *fe);
       virtual std::string print();
   };
}

CourseGrades.cpp

#include "CourseGrades.h"
#include "GradedActivity.h"
#include "Essay.h"
#include "FinalExam.h"

namespace course
{

int CourseGrades::NUM = 4;
CourseGrades::CourseGrades()
   {
       grades = std::vector<GradedActivity*>(NUM);
   }

   void CourseGrades::setLab(GradedActivity *lab)
   {
       grades[0] = lab;
   }

   void CourseGrades::setPassFailExam(PassFailExam *pfe)
   {
       grades[1] = pfe;
   }

   void CourseGrades::setEssay(Essay *essay)
   {
       grades[2] = essay;
   }

   void CourseGrades::setFinalExam(FinalExam *fe)
   {
       grades[3] = fe;
   }

   std::string CourseGrades::print()
   {
       std::string result = L"";
       result = std::string(L"Lab Score: ") + grades[0]->getScore() + std::string(L", Grade: ") + grades[0]->getGrade() + std::string(L" ") + std::string(L"Pass/Fail Exam Score: ") + grades[1]->getScore() + std::string(L" Grade: ") + grades[1]->getGrade() + std::string(L" ") + std::string(L"Essay Score: ") + grades[2]->getScore() + std::string(L", Grade: ") + grades[2]->getGrade() + std::string(L" ") + std::string(L"Final Exam Score: ") + grades[3]->getScore() + std::string(L" Grade: ") + grades[3]->getGrade() + std::string(L" ");
       return result;
   }
}

CourseGradesDemo.cpp

#include "CourseGrades.h"
#include "Essay.h"
#include "FinalExam.h"

namespace course
{
   class CourseGradesDemo{
   void main(std::vector<std::string> &args)
   {
       CourseGrades *courseGrades = new CourseGrades();
       Lab *lab = new Lab();
       PassFailExam *passFailExam = new PassFailExam(70);
       Essay *essay = new Essay();
       FinalExam *finalExam = new FinalExam(50, 10);
       lab->setScore(85);
       passFailExam->setScore(17);
       essay->setScore(25,18,17,20);
       finalExam->setScore(40);
       courseGrades->setLab(lab);
       courseGrades->setPassFailExam(passFailExam);
       courseGrades->setEssay(essay);
       courseGrades->setFinalExam(finalExam);
       std::cout << courseGrades->print();
   }
   }
}

Essay.h

#include "GradedActivity.h"

namespace course
{
   class Essay : public GradedActivity
   {
   private:
       double grammar = 0;
       double spelling = 0;
       double correctLength = 0;
       double content = 0;

   public:
       virtual void setScore(double gr, double sp, double len, double cnt);
   private:
       void setGrammar(double g);
       void setSpelling(double s);
       void setCorrectLength(double c);
       void setContent(double c);
   public:
       virtual double getGrammar();
       virtual double getSpelling();
       virtual double getCorrectLength();
       virtual double getContent();
       virtual double getScore() override;
   };

}

Essay.cpp

#include "Essay.h"

namespace course
{
   void Essay::setScore(double gr, double sp, double len, double cnt)
   {
       setGrammar(gr);
       setSpelling(sp);
       setCorrectLength(len);
       setContent(cnt);

       GradedActivity::setScore(this->getScore());
   }

   void Essay::setGrammar(double g)
   {
       if (g <= 30.0)
       {
           grammar = g;
       }
       else
       {
           grammar = 0.0;
       }
   }

   void Essay::setSpelling(double s)
   {
       if (s <= 20.0)
       {
           spelling = s;
       }
       else
       {
           spelling = 0.0;
       }
   }

   void Essay::setCorrectLength(double c)
   {
       if (c <= 20.0)
       {
           correctLength = c;
       }
       else
       {
               correctLength = 0.0;
       }
   }

   void Essay::setContent(double c)
   {
       if (c <= 30)
       {
           content = c;
       }
       else
       {
           content = 0.0;
       }
   }

   double Essay::getGrammar()
   {
       return grammar;
   }

   double Essay::getSpelling()
   {
       return spelling;
   }

   double Essay::getCorrectLength()
   {
       return correctLength;
   }

   double Essay::getContent()
   {
       return content;
   }

   double Essay::getScore()
   {
       return grammar + spelling + correctLength + content;
   }
}

FinalExam.h

#include "GradedActivity.h"

namespace course
{

   class FinalExam : public GradedActivity
   {
   private:
       int numQuestions = 0;
       double pointsEach = 0;
       int numMissed = 0;

   public:
       FinalExam(int questions, int missed);
       virtual double getPointsEach();
       virtual int getNumMissed();
   };
}

FinalExam.cpp

#include "FinalExam.h"

namespace course
{
   FinalExam::FinalExam(int questions, int missed)
   {
       double numericScore;
       numQuestions = questions;
       numMissed = missed;
       pointsEach = 100.0 / questions;
       numericScore = 100.0 - (missed * pointsEach);
       setScore(numericScore);
   }

   double FinalExam::getPointsEach()
   {
       return pointsEach;
   }

   int FinalExam::getNumMissed()
   {
       return numMissed;
   }
}

GradedActivity.h

namespace course

{
   class GradedActivity
   {
   private:
       double score = 0;

   public:
       virtual void setScore(double s);
       virtual double getScore();
       virtual wchar_t getGrade();
   };
}

GradedActivity.cpp

#include "GradedActivity.h"

namespace course
{
   void GradedActivity::setScore(double s)
   {
       score = s;
   }

   double GradedActivity::getScore()
   {
       return score;
   }

   wchar_t GradedActivity::getGrade()
   {
       wchar_t letterGrade;
       if (score >= 90)
       {
           letterGrade = L'A';
       }
       else if (score >= 80)
       {
           letterGrade = L'B';
       }
       else if (score >= 70)
       {
           letterGrade = L'C';
       }
       else if (score >= 60)
       {
           letterGrade = L'D';
       }
       else
       {
           letterGrade = L'F';
       }
       return letterGrade;
   }
}