Question

Introduction Your eighth assignment will consist of two programs, which will involve the use of simple classes. The source coExtra Classes The problem asks you to use many of the classes that have been discussed in the book. Unfortunately, these clas5) Essay This class should be derived from Pass FailActivity, instead of the class specified in the book. (Therefore, you canError Notation: Note that the fourth function listed in the scan of Problem 11 should be setFinal Exam ( ) instead of setPassResults If polymorphism works correctly in your program, it should print out the correct score and letter grade for parts (a)setPassFailExam: This function should accept the address of a FinalExam object as its argument. This object should already hoI need this in C++. This is all one question.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Working code implemented in C++ and appropriate comments provided for better understanding:

Here I am attaching code for these files:

  • main.cpp
  • Essay.cpp
  • Essay.h
  • FinalExam.cpp
  • FinalExam.h
  • CourseGrades.cpp
  • CourseGrades.h
  • GradedActivity.cpp
  • GradedActivity.h
  • PassFailExam.cpp
  • PassFailExam.h
  • PassFailActivity.cpp
  • PassFailActivity.h

Source code for main.cpp:

#include <iostream>
#include "GradedActivity.h"
#include "PassFailExam.h"
#include "FinalExam.h"
#include "CourseGrades.h"
using namespace std;

int main()
{
   // Create a GradedActivity object for the lab.
   GradedActivity lab(80);

   // Create a PassFailExam object. 50 questions,
   // 5 missed questions, minimum passing score is 70.
   PassFailExam pfexam(50, 5, 70);

   // Create an Essay object and set the different
   // types of points.
   Essay essay;
   essay.setGrammerPoints(25);
   essay.setSpellingPoints(15);
   essay.setLengthPoints(20);
   essay.setContentPoints(30);
   cout << essay.getScore () << endl;

   // Create a FinalExam object.
   FinalExam finalExam(50, 5);

   // Create a CourseGrades object.
   CourseGrades myGrades;

   // Store the grade items in the
   // CourseGrades object.
   myGrades.setLab(&lab);
   myGrades.setPassFailExam(&pfexam);
   myGrades.setEssay(&essay);
   myGrades.setFinalExam(&finalExam);

   // Print the grade information.
   myGrades.print();
   return 0;
}

Source code for Essay.cpp:

// Implementation file for the Essay class
#include <iostream>
#include "Essay.h"
using namespace std;

//******************************************
// setGrammerPoints member function *
//******************************************

void Essay::setGrammerPoints(double p)
{
   // Validate the points.
   if (p < 0 || p > 30)
   {
       // Invalid data
       cout << "Invalid number of grammar points.\n";
       // exit(EXIT_FAILURE);
       return;
   }

   // Assign the points.
   grammerPoints = p;
}

//******************************************
// setSpellingPoints member function *
//******************************************

void Essay::setSpellingPoints(double p)
{
   // Validate the points.
   if (p < 0 || p > 20)
   {
       // Invalid data
       cout << "Invalid number of spelling points.\n";
       // exit(EXIT_FAILURE);
       return;
   }

   // Assign the points.
   spellingPoints = p;
}

//******************************************
// setLengthPoints member function *
//******************************************

void Essay::setLengthPoints(double p)
{
   // Validate the points
   if (p < 0 || p > 20)
   {
       // Invalid data
       cout << "Invalid number of length points.\n";
       // exit(EXIT_FAILURE);
       return;
   }

   // Assign the points.
   lengthPoints = p;
}

//******************************************
// setContentPoints member function *
//******************************************

void Essay::setContentPoints(double p)
{
   // Validate the points.
   if (p < 0 || p > 30)
   {
       // Invalid data
       cout << "Invalid number of content points.\n";
       // exit(EXIT_FAILURE);
       return;
   }

   // Assign the points.
   contentPoints = p;
}

//*********************************************************
// getScore *
//*********************************************************

double Essay::getScore() const
{
   int totalPoints = grammerPoints + spellingPoints +
       lengthPoints + contentPoints;
   return totalPoints;
}

//*********************************************************
// getLetterGrade *
//*********************************************************

char Essay::getLetterGrade()
{
   // Add up all the points.
   score = getScore();

   // Return the letter grade as reported from
   // the base class function.
   return GradedActivity::getLetterGrade();
}

Source code for Essay.h:

// Specification file for the Essay class
#ifndef ESSAY_H
#define ESSAY_H
#include "GradedActivity.h"

class Essay: public GradedActivity {
private:
   double grammerPoints;   // To hold grammer points
   double spellingPoints;   // To hold spelling points
   double lengthPoints;   // To hold length points
   double contentPoints;   // To hold content points

public:
   // Default constructor
   Essay() {
       grammerPoints = 0.0;
       spellingPoints = 0.0;
       lengthPoints = 0.0;
       contentPoints = 0.0;
   }

   // Mutators
   void setGrammerPoints(double);
   void setSpellingPoints(double);
   void setLengthPoints(double);
   void setContentPoints(double);

   // Accessors
   double getGrammerPoints() const {
       return grammerPoints;
   }

   double getSpellingPoints() const {
       return spellingPoints;
   }

   double getLengthPoints() const {
       return lengthPoints;
   }

   double getContentPoints() const {
       return contentPoints;
   }

   virtual double getScore() const ;
   virtual char getLetterGrade() ;
};

#endif

Source code for FinalExam.cpp:

#include "FinalExam.h"

//********************************************************
// set function *
// The parameters are the number of questions and the *
// number of questions missed. *
//********************************************************

void FinalExam::set(int questions, int missed)
{
double numericScore; // To hold the numeric score

// Set the number of questions and number missed.
numQuestions = questions;
numMissed = missed;

// Calculate the points for each question.
pointsEach = 100.0 / numQuestions;

// Calculate the numeric score for this exm.
numericScore = 100.0 - (missed * pointsEach);

// Call the inherited setScore function to set
// the numeric score.
setScore(numericScore);

// Call the adjustScore function to adjust
// the score.
adjustScore();
}

//*****************************************************************
// Definition of Test::adjustScore. If score is within 0.5 points *
// of the next whole point, it rounds the score up and *
// recalculates the letter grade. *
//*****************************************************************

void FinalExam::adjustScore()
{
double fraction = score - static_cast<int>(score);

if (fraction >= 0.5)
{
// Adjust the score variable in the GradedActivity class.
score += (1.0 - fraction);
}
}

Source code for FinalExam.h:

#ifndef FINALEXAM_H
#define FINALEXAM_H
#include "GradedActivity.h"

class FinalExam : public GradedActivity
{
private:
int numQuestions; // Number of questions
double pointsEach; // Points for each question
int numMissed; // Number of questions missed
public:
// Default constructor
FinalExam()
{ numQuestions = 0;
pointsEach = 0.0;
numMissed = 0; }
  
// Constructor
FinalExam(int questions, int missed)
{ set(questions, missed); }

// Mutator functions
void set(int, int); // Defined in FinalExam.cpp
void adjustScore(); // Defined in FinalExam.cpp

// Accessor functions
double getNumQuestions() const
{ return numQuestions; }
  
double getPointsEach() const
{ return pointsEach; }

int getNumMissed() const
{ return numMissed; }
};

#endif

Source code for CourseGrades.cpp:

// Implementation file for the CourseGrades class
#include <iostream>
#include "CourseGrades.h"
using namespace std;

void CourseGrades::print() const
{
   // Display the lab score and grade.
   cout << "Lab score: "
       << grades[LAB]->getScore()
   << "\tGrade: "
       << grades[LAB]->getLetterGrade()
       << endl;

   // Display the pass/fail exm score
   // and grade.
   cout << "Pass/Fail Exm score: "
       << grades[PASS_FAIL_EXAM]->getScore()
   << "\tGrade: "
       << grades[PASS_FAIL_EXAM]->getLetterGrade()
       << endl;

   // Display the essay score and grade.
   cout << "Essay score: "
       << grades[ESSAY]->getScore()
   << "\tGrade: "
       << grades[ESSAY]->getLetterGrade()
       << endl;

   // Display the final exm score and grade.
   cout << "Final exm score: "
       << grades[FINAL_EXAM]->getScore()
   << "\tGrade: "
       << grades[FINAL_EXAM]->getLetterGrade()
       << endl;
}

Source code for CourseGrades.h:

#ifndef COURSE_GRADES_H
#define COURSE_GRADES_H
#include <iostream>
#include "GradedActivity.h"
#include "PassFailExam.h"
#include "FinalExam.h"
#include "Essay.h"
using namespace std;

// Constant for the number of grades
const int NUM_GRADES = 4;

// Constants for the subscripts
const int LAB = 0; // Lab score is at subscript 0
const int PASS_FAIL_EXAM = 1; // Pass/fail exm is at subscript 1
const int ESSAY = 2; // Essay is at subscript 2
const int FINAL_EXAM = 3; // Final exm is at subscript 3

class CourseGrades {
private:
   // Array of GradedActivity pointers to
   // reference the different types of grades
   GradedActivity *grades[NUM_GRADES];

public:
   // Default constructor
   CourseGrades() {
       for (int i = 0; i < NUM_GRADES; i++)
           grades[i] = nullptr;
   }

   // Mutators
   void setLab(GradedActivity *activity) {
       grades[LAB] = activity;
   }

   void setPassFailExam(PassFailExam *pfexam) {
       grades[PASS_FAIL_EXAM] = pfexam;
   }

   void setEssay(Essay *essay) {
       grades[ESSAY] = essay;
   }

   void setFinalExam(FinalExam *finalExam) {
       grades[FINAL_EXAM] = finalExam;
   }

   // print function
   void print() const;
};

#endif

Source code for GradedActivity.cpp:

#include "GradedActivity.h"

//******************************************************
// Member function GradedActivity::getLetterGrade *
//******************************************************

char GradedActivity::getLetterGrade()
{
char letterGrade; // To hold the letter grade

if (score > 89)
letterGrade = 'A';
else if (score > 79)
letterGrade = 'B';
else if (score > 69)
letterGrade = 'C';
else if (score > 59)
letterGrade = 'D';
else
letterGrade = 'F';

return letterGrade;
}

Source code for GradedActivity.h:

#ifndef GRADEDACTIVITY_H
#define GRADEDACTIVITY_H

// GradedActivity class declaration

class GradedActivity
{
protected:
double score; // To hold the numeric score
public:
// Default constructor
GradedActivity()
{ score = 0.0; }

// Constructor
GradedActivity(double s)
{ score = s; }

// Mutator function
void setScore(double s)
{ score = s; }

// Accessor functions
virtual double getScore()
{ return score; }

virtual char getLetterGrade() ;
};

#endif

Source code for PassFailExam.cpp:

#include "PassFailExam.h"

//********************************************************
// set function *
// The parameters are the number of questions and the *
// number of questions missed. *
//********************************************************
const int TOTAL_POINTS = 100.0;

void PassFailExam::set(int questions, int missed)
{
double numericScore; // To hold the numeric score

// Set the number of questions and number missed.
numQuestions = questions;
numMissed = missed;

// Calculate the points for each question.
pointsEach = TOTAL_POINTS / numQuestions;

// Calculate the numeric score for this exm.
numericScore = TOTAL_POINTS - (missed * pointsEach);

// Call the inherited setScore function to set
// the numeric score.
setScore(numericScore);
}

Source code for PassFailExam.h:

#ifndef PASSFAILEXAM_H
#define PASSFAILEXAM_H
#include "PassFailActivity.h"

class PassFailExam : public PassFailActivity
{
private:
int numQuestions; // Number of questions
double pointsEach; // Points for each question
int numMissed; // Number of questions missed
public:
// Default constructor
PassFailExam() : PassFailActivity()
{ numQuestions = 0;
pointsEach = 0.0;
numMissed = 0; }
  
// Constructor
PassFailExam(int questions, int missed, double mps) :
PassFailActivity(mps)
{ set(questions, missed); }

// Mutator function
void set(int, int); // Defined in PassFailExam.cpp

// Accessor functions
double getNumQuestions() const
{ return numQuestions; }
  
double getPointsEach() const
{ return pointsEach; }

int getNumMissed() const
{ return numMissed; }
};

#endif

Source code for PassFailActivity.cpp:

#include "PassFailActivity.h"

//******************************************************
// Member function PassFailActivity::getLetterGrade *
// This function returns 'P' if the score is passing, *
// otherwise it returns 'F'. *
//******************************************************

char PassFailActivity::getLetterGrade() const
{
char letterGrade;

if (score >= minPassingScore)
letterGrade = 'P';
else
letterGrade = 'F';
  
return letterGrade;
}

Source code for PassFailActivity.h:

#ifndef PASSFAILACTIVITY_H
#define PASSFAILACTIVITY_H
#include "GradedActivity.h"

class PassFailActivity : public GradedActivity
{
protected:
double minPassingScore; // Minimum passing score.
public:
// Default constructor
PassFailActivity() : GradedActivity()
{ minPassingScore = 0.0; }

// Constructor
PassFailActivity(double mps) : GradedActivity()
{ minPassingScore = mps; }

// Mutator
void setMinPassingScore(double mps)
{ minPassingScore = mps; }

// Accessors
double getMinPassingScore() const
{ return minPassingScore; }

char getLetterGrade() const;
};

#endif

Sample Output Screenshots:

> clang++-7 pthread -std=c++17 -o main courseGrades.cpp Essay.cpp FinalExam.cop GradedActivity.cpp PassFailActivity.cpp PassF

Hope it helps, if you like the answer give it a thumbs up. Thank you.

Add a comment
Know the answer?
Add Answer to:
I need this in C++. This is all one question. Introduction Your eighth assignment will consist...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • So on this assignment... I have the main.cpp file, the fan.cpp file, and the fan.h file...

    So on this assignment... I have the main.cpp file, the fan.cpp file, and the fan.h file created and open in Dev C++. However, every time I try to compile I get a series of undefined reference to errors. Any advice is much appreciated!!! (45 pts) Work Programming Exercise 9.2 (class Fan) in the textbook on page 367. Additional specifications: • Use separate header and implementation files. • The main program (not the functions) should display the values of Speed, On,...

  • In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a tes...

    In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a test grade (integer value) for each student in a class. Validation Tests are graded on a 100 point scale with a 5 point bonus question. So a valid grade should be 0 through 105, inclusive. Processing Your program should work for any...

  • C++ program Correctly complete the following assignment. Follow all directions. The main purpose is to show...

    C++ program Correctly complete the following assignment. Follow all directions. The main purpose is to show super and sub class relationships with an array of super media pointers to sub class objects and dynamic binding. The < operator will be overloaded in the super class so all subclasses can use it. The selection sort method will be in the main .cpp file because it will sort the array created in main. The final .cpp file, the three .h header class...

  • Need some help with this C++ code. Please screenshot the code if possible. Purpose: Demonstrate the...

    Need some help with this C++ code. Please screenshot the code if possible. Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of...

  • C++ Assignment: Create a class called FitnessMember that has only one variable, called name. The FitnessMember...

    C++ Assignment: Create a class called FitnessMember that has only one variable, called name. The FitnessMember class should have a constructor with no parameters, a constructor with a parameter, a mutator function and an accessor function. Also, include a function to display the name. Define a class called Athlete which is derived from FitnessMember. An Athlete record has the Athlete's name (defined in the FitnessMember class), ID number of type String and integer number of training days. Define a class...

  • *Python* INTRODUCTION: The goal of this programming assignment is to enable the student to practice object-oriented...

    *Python* INTRODUCTION: The goal of this programming assignment is to enable the student to practice object-oriented programming using classes to create objects. PROBLEM DEFINITION: Write a class named Employee that holds the following data about an employee in attributes: name, IDnumber, department, jobTitle The class should have 8 methods as follows:  For each attribute, there should be a method that takes a parameter to be assigned to the attribute. This is known as a mutator method.  For each...

  • Look at this partial class definition, and then answer questions a - b below: Class Book...

    Look at this partial class definition, and then answer questions a - b below: Class Book    Private String title    Private String author    Private String publisher    Private Integer copiesSold End Class Write a constructor for this class. The constructor should accept an argument for each of the fields. Write accessor and mutator methods for each field. Look at the following pseudocode class definitions: Class Plant    Public Module message()       Display "I'm a plant."    End Module...

  • C++ assignment help! The instructions are below, i included the main driver, i just need help...

    C++ assignment help! The instructions are below, i included the main driver, i just need help with calling the functions in the main function This assignment will access your skills using C++ strings and dynamic arrays. After completing this assignment you will be able to do the following: (1) allocate memory dynamically, (2) implement a default constructor, (3) insert and remove an item from an unsorted dynamic array of strings, (4) use the string class member functions, (5) implement a...

  • Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment...

    Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of 100 accounts. Use an array of pointers to objects for this. However, your...

  • can someone help with this? need to use c++. The aim of this homework assignment is...

    can someone help with this? need to use c++. The aim of this homework assignment is to practice writing classes. This homework assignment will help build towards project I, which will be to write a program implementing Management of Rosters System. For this assignment, write a class called Student. This class should contain information of a single student. This information includes: last name, first name, standing, credits gpa, date of birth, matriculation date. For now you can store date of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT