Question

Part 1: Implement Essay.h and demonstrate the Essay class The Essay class is derived from the GradedActivity class presented in chapter 15. The Essay class determines the grade a student receives on an essay. The students 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 Please follow these steps 1. Download GradedActivity.h, GradedActivity.cpp, and Essay.h from Moodle 2. Implement Essay.h by writing Essay.cpp. That is, provide bodies for 4 mutators and one virtual function void setGrammerPoints (double) void setSpellingPoints (double) void setLengthPoints (double) void setContentPoints (double) virtual char getLetterGrade) The file Essay.cpp should only contain those function bodies and you are NOT allowed to change anything in the files downloaded from Moodle. The details of getLetterGrade implementation will be discussed in class. 3. Write a program called demo.cpp: create an Essay object called report by using default constructor prompt and get input from user (e.g. an English professor) the grammar, spelling, correct length, and content points of the students essay, i.e. report set the reports grammar points, spelling points, correct length points, and content points according to the input data display the grade of the reportHave the following files in the folder: Essay.cpp demo.cpp Screen shot of a test run of demo.cpp

this is the essay.h file

#1fndef ESSAY H #define ESSAY H 4 #include GradedActivity.h 6 class Essay : public GradedActivity 8 private: double grammerPoints; double spellingPoints; double lengthPoints; double contentPoints; //To hold grammer points // To hold spelling points // To hold length points //To hold content points 12 13 14 public: 15 16 /Default constructor Essay() f grammerPoints 0.0; spellingPoints0.0 lengthPoints - 0.0; contentPoints 0.0; 18 Mutators void setGrammerPoints(double); void setSpellingPoints (double); void setLengthPoints (double); void setContentPoints(double); 20 21 23 24 25 26 27 28 29 30 31 32 Accessors double getGrammerPoints () const f return grammerPoints; h double getSpellingPoints() const f return spellingPoints; h double getLengthPoints() const f return lengthPoints; h 34 35 36 37 38 39 40 41 #endif double getContentPoints() const f return contentPoints; h virtual char getLetterGrade();this is the gradedActivity.h file

1 #1fndef GRADEDACTIVITY_A 2 #define GRADEDACTIVITYH 4 // GradedActivity class declaration 6 class GradedActivity 8 protected: 10 public: double score; // To hold the numeric score /Default constructor GradedActivity() f score-0.0; h 13 14 15 /Constructor GradedActivity(double s) { score = s; } Mutator function f score - s; } 17 18 void setScore (double s) 20 21 /Accessor functions double getScore () const 23 24 25 26 27 28 29 #endif f return score; > virtual char getLetterGrade() const;this is the gradeActivity.cpp file

|#include 2 | GradedActivity.h 4 // Member function GradedActivity::getLetterGrade 7 char GradedActivity::getLetterGrade () const char letterGrade; // To hold the letter grade if (score 89) letterGrade A else if (score > 79) 13 else if (score > 69) letterGrade C else if (score > 59) letterGrade D 15 18 else 20 21 return letterGrade; 23Can someone help me write the code for this in c++. I'm really struggling with this. If you can include comments and a screenshot of the test run it would be greatly appreciated

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

Note : code in bold is implemented as asked in the question

-------------------------------------

// Implementation file for the GradedActivity class

#include "GradedActivity.h"

//******************************************************

// Member function GradedActivity::determineGrade *

//******************************************************

char GradedActivity::getLetterGrade() const

{

char letterGrade;

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;

}

----------

demo

------------------------

#include <iostream>

#include "Essay.h"

using namespace std;

int main()

{

Essay essay;

double contentPoints;

double spellingPoints;

double lengthPoints;

double grammerPoints;

cout<<"Please give content points(Max 30): ";

cin>>contentPoints;

cout<<"Please give spelling points(Max 20): ";

cin>>spellingPoints;

cout<<"Please give length points(Max 20): ";

cin>>lengthPoints;

cout<<"Please give grammer points(Max 30): ";

cin>>grammerPoints;

essay.setContentPoints(contentPoints);

essay.setGrammerPoints(grammerPoints);

essay.setLengthPoints(lengthPoints);

essay.setSpellingPoints(spellingPoints);

cout<<"Your grade is:"<<essay.getLetterGrade()<<endl;

system("PAUSE");

return 0;

}

------------

graded.h

// Specification file for the GradedActivity class
#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; }

GradedActivity(double s)
{ score = s; }

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

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

char getLetterGrade() const;
};

#endif

---------

essay.h

---------

#ifndef ESSAY_H

#define ESSAY_H

#include "GradedActivity.h"

class Essay: public GradedActivity

{

private:

double grammerPoints;

double spellingPoints;

double lengthPoints;

double contentPoints;

public:

Essay(){

grammerPoints=0.0;

spellingPoints=0.0;

lengthPoints=0.0;

contentPoints=0.0;

}

void setGrammerPoints(double);

void setSpellingPoints(double);

void setLengthPoints(double);

void setContentPoints(double);

double getGrammerPoints()const {return grammerPoints;}

double getSpellingPoints()const {return spellingPoints;}

double getLengthPoints()const {return lengthPoints;}

double getContentPoints()const {return contentPoints;}

virtual char getLetterGrade();

};

#endif

-----------

essay.cpp

// Implementation file for the GradedActivity class

#include "essay.h"

//Implementing mutator functions

void Essay::setGrammerPoints(double points){

grammerPoints=points;

}

void Essay::setSpellingPoints(double points){

spellingPoints=points;

}

void Essay::setLengthPoints(double points){

lengthPoints=points;

}

void Essay::setContentPoints(double points){

contentPoints=points;

}

// implementing getLetterGrade() vitual function.

//This function needs to be modified as will be explained in your class.

// We have implemented this as it should be

//comment if you need upgradation and provide material for this function

char Essay::getLetterGrade(){

char letterGrade;

int score=grammerPoints+spellingPoints+lengthPoints+contentPoints;

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;

}

---------

output :

Please give content points (Max 30: 25 Please give spelling points (Max 20): 15 Please give length points (Max 20) 15 lease give grammer points (Max 3): 25 Your grade is:B Press any key to continue . . .

Please give content points (Max 30: 25 Please give spelling points (Max 20): 15 Please give length points (Max 20) 15 lease give grammer points (Max 3): 25 Your grade is:B Press any key to continue . . .

Add a comment
Know the answer?
Add Answer to:
this is the essay.h file this is the gradedActivity.h file this is the gradeActivity.cpp file Can...
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
  • C++ Lab 9B Inheritance Class Production Worker Create a project C2010Lab9b; add a source file Lab...

    C++ Lab 9B Inheritance Class Production Worker Create a project C2010Lab9b; add a source file Lab9b.cpp to the project. Copy and paste the code is listed below: Next, write a class named ProductionWorker that is derived from the Employee class. The ProductionWorker class should have member variables to hold the following information: Shift (an integer) Hourly pay rate (a double) // Specification file for the ProductionWorker Class #ifndef PRODUCTION_WORKER_H #define PRODUCTION_WORKER_H #include "Employee.h" #include <string> using namespace std; class ProductionWorker...

  • Design an Essay class that extends the GradedActivity class presented in the chapter 10 of textbook....

    Design an Essay class that extends the GradedActivity class presented in the chapter 10 of textbook. The Essay class should determine the grade a student receives for an essay. 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 Demonstrate the class in a simple program. Example Run run: Term paper: Grammar points: 25.0 Spelling points: 18.0...

  • I need help implementing class string functions, any help would be appreciated, also any comments throughout...

    I need help implementing class string functions, any help would be appreciated, also any comments throughout would also be extremely helpful. Time.cpp file - #include "Time.h" #include <new> #include <string> #include <iostream> // The class name is Time. This defines a class for keeping time in hours, minutes, and AM/PM indicator. // You should create 3 private member variables for this class. An integer variable for the hours, // an integer variable for the minutes, and a char variable for...

  • please write the code in C++ 2 Base class File 3 Derived class PDF 3.1 Class...

    please write the code in C++ 2 Base class File 3 Derived class PDF 3.1 Class declaration • The class PDF inherits from File and is a non-abstract class 1. Hence objects of the class PDF can be instantiated. 2. To do so, we must override the pure virtual function clone) in the base class • The class declaration is given below. • The complete class declaration is given below, copy and paste it into your file. . It is...

  • Question 2 - Programming Exercise 1. Make a directory for this lab and change into it....

    Question 2 - Programming Exercise 1. Make a directory for this lab and change into it. 2. Copy files using the following command: cp/net/data/ftp/pub/class/115/ftp/cpp/Inheritance/Exercise.cpp Exercise.cpp Finish the program so that it compiles and runs. The instructions are contained in the C++ file. Your completed program should generate output similar to the following: TwoD default constructor This program asks for the coordinates of two points in 3D space and calculates their distance. Please enter the xyz coordinates for the first point:...

  • Here are the files I've made so far: /********************* * File: check05b.cpp *********************/ #include &lt...

    Here are the files I've made so far: /********************* * File: check05b.cpp *********************/ #include <iostream> using namespace std; #include "money.h" /**************************************************************** * Function: main * Purpose: Test the money class ****************************************************************/ int main() {    int dollars;    int cents;    cout << "Dollar amount: ";    cin >> dollars;    cout << "Cents amount: ";    cin >> cents;    Money m1;    Money m2(dollars);    Money m3(dollars, cents);    cout << "Default constructor: ";    m1.display();    cout << endl;    cout << "Non-default constructor 1: ";    m2.display();    cout << endl;   ...

  • /* FILE: ./shapes7/shape.h */ #include <iostream> using std::ostream; class shape{ int x,y; public: shape( ) {...

    /* FILE: ./shapes7/shape.h */ #include <iostream> using std::ostream; class shape{ int x,y; public: shape( ) { x=y=0;} shape(int xvalue, int yvalue); void setShape(int new_x, int new_y); void setX(int new_x); void setY(int new_y); int getX( ) const; int getY( ) const; virtual void move(int x, int y) = 0; virtual void shift(int dx, int dy) = 0; virtual void draw( ) = 0; virtual void rotate(double r) = 0; virtual void print(ostream&)const; friend ostream & operator<<(ostream & os, const shape& s);...

  • Today assignment , find the errors in this code and fixed them. Please I need help...

    Today assignment , find the errors in this code and fixed them. Please I need help with find the errors and how ro fixed them. #include <iostream> #include <cstring> #include <iomanip> using namespace std; const int MAX_CHAR = 100; const int MIN_A = 90; const int MIN_B = 80; const int MIN_C = 70; double getAvg(); char determineGrade(double); void printMsg(char grade); int main() { double score; char grade; char msg[MAX_CHAR]; strcpy(msg, "Excellent!"); strcpy(msg, "Good job!"); strcpy(msg, "You've passed!"); strcpy(msg, "Need...

  • J Inc. has a file with employee details. You are asked to write a C++ program...

    J Inc. has a file with employee details. You are asked to write a C++ program to read the file and display the results with appropriate formatting. Read from the file a person's name, SSN, and hourly wage, the number of hours worked in a week, and his or her status and store it in appropriate vector of obiects. For the output, you must display the person's name, SSN, wage, hours worked, straight time pay, overtime pay, employee status and...

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