To develop in C++ Course Grades In a course, a teacher gives the following tests
ID: 3725645 • Letter: T
Question
To develop in C++
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:
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. (See
Programming Challenge 6 for the Essay class. If you have not completed Programming
Challenge 6, use a GradedActivity object instead.) 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.
Explanation / Answer
As per your requirement the below one is solution please follow it
main.cpp
#include <iostream>
#include "GradedActivity.h"
#include "PassFailExam.h"
#include "FinalExam.h"
#include "CourseGrades.h"
#include "Essay.h"
using namespace std;
int main()
{
GradedActivity lab(80);
PassFailExam pfexam(50, 5, 70);
Essay essay;
essay.setGrammarPoints(25);
essay.setSpellingPoints(15);
essay.setLengthPoints(20);
essay.setContentPoints(30);
FinalExam finalExam(50, 5);
CourseGrades myGrades;
myGrades.setLab(lab);
myGrades.setPassFailExam(pfexam);
myGrades.setEssay(essay);
myGrades.setFinalExam(finalExam);
myGrades.print();
return 0;
}
CourseGrades.h
#ifndef COURSEGRADES_H
#define COURSEGRADES_H
#include "GradedActivity.h"
#include "PassFailExam.h"
#include "FinalExam.h"
#include "Essay.h"
#include <iomanip>
#include <iostream>
class CourseGrades : public Essay,
public FinalExam,
public PassFailExam,
public GradedActivity
{
private:
int grades[4];
public:
void setLab(GradedActivity &l)
{ grades[0] = GradedActivity::getLab(); }
void setPassFailExam(PassFailExam &pf)
{ grades[1] = PassFailExam::getPassFail(); }
void setEssay(Essay &e)
{ grades[2] = Essay::getEssay(); }
void setFinalExam(FinalExam &fe)
{ grades[3] = FinalExam::getFinal(); }
void print() const
{ std::cout << grades[0] << ", " << grades[1] << ", " << grades[2] << ", " << grades[3]; }
};
#endif
Essay.h
#ifndef ESSAY_H
#define ESSAY_H
class Essay
{
protected:
int essay;
public:
Essay();
void setGrammarPoints(int g)
{ essay += g; }
void setSpellingPoints(int s)
{ essay += s; }
void setLengthPoints(int l)
{ essay += l; }
void setContentPoints(int c)
{ essay += c; }
int getEssay()
{ return essay; }
};
Essay::Essay()
{
essay = 0;
}
#endif
FinalExam.h
#ifndef FINALEXAM_H
#define FINALEXAM_H
class FinalExam
{
protected:
int final;
public:
FinalExam();
FinalExam(int e, int w);
int getFinal()
{ return final; }
};
FinalExam::FinalExam()
{
final = 0;
}
FinalExam::FinalExam(int e, int w)
{
final = e - w;
}
#endif
GradedActivity.h
#ifndef GRADEDACTIVITY_H
#define GRADEDACTIVITY_H
class GradedActivity
{
protected:
int lab;
public:
GradedActivity();
GradedActivity(int gA);
int getLab()
{ return lab; }
};
GradedActivity::GradedActivity()
{
lab = 0;
}
GradedActivity::GradedActivity(int gA)
{
lab = gA;
}
#endif
PassFailExam.h
#ifndef PASSFAILEXAM_H
#define PASSFAILEXAM_H
class PassFailExam
{
protected:
int pfExam;
public:
PassFailExam();
PassFailExam(int t, int d, int p);
int getPassFail()
{ return pfExam; }
};
PassFailExam::PassFailExam()
{
pfExam = 0;
}
PassFailExam::PassFailExam(int t, int d, int p)
{
int passfail;
passfail = (t - d) / t;
if(passfail > p)
{ pfExam = 100; }
else
{ pfExam = 0; }
}
#endif
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.