Question

In: Computer Science

In C++ Design an Essay class that is derived from the GradedActivity class: class GradedActivity{ private:...

In C++

Design an Essay class that is derived from the GradedActivity class: class GradedActivity{ private: double score; public: GradedActivity() {score = 0.0;} GradedActivity(double s) {score = s;} void setScore(double s) {score = s;} double getScore() const {return score;} char getLetterGrade() const; }; 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; } The Essay class should determine the grade a student receives on an essay. The student's essay score can be up to 100, and is made up of four parts: Grammar: up to 30 points Spelling: up to 20 points Correct length: up to 20 points Content: up to 30 points The Essay class should have a double member variable for each of these sections, as well as a mutator that sets the values of these variables. It should add all of these values to get the student's total score on an Essay. Demonstrate your class in a program that prompts the user to input points received for grammar, spelling, length, and content, and then prints the numeric and letter grade received by the student.

Solutions

Expert Solution

Thanks for the question.


Below is the code you will be needing Let me know if you have any doubts or if you need anything to change.


Thank You !


===========================================================================

#include<iostream>
using namespace std;


class GradedActivity{
private: double score;
public:
GradedActivity() {
score = 0.0;
}
GradedActivity(double s) {
score = s;
}
void setScore(double s) {
score = s;
}
double getScore() const {
return score;
} char getLetterGrade() const;
};
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;
}

class Essay:public GradedActivity{
  
   private:
       double grammar;
       double spelling;
       double length;
       double content;
      
   public:
       Essay(): GradedActivity(0){
          
       }
       Essay(double gr, double sp, double le, double con):GradedActivity(gr+sp+le+con),
       grammar(gr), spelling(sp), length(le), content(con){
          
       }
       void setGrammar(double score){
           grammar=score;
           GradedActivity::setScore(grammar+spelling+length+content);
       }
       void setSpelling(double score){
           spelling=score;
           GradedActivity::setScore(grammar+spelling+length+content);
       }
       void setLength(double score){
           length=score;
           GradedActivity::setScore(grammar+spelling+length+content);
       }
       void setContent(double score){
           content=score;
           GradedActivity::setScore(grammar+spelling+length+content);
       }
  
};

int main(){
  
   Essay essay = Essay(15,10,10,10);
  
   cout<<"Total Score: "<<essay.getScore()<<", Letter Grade: "<<essay.getLetterGrade()<<endl;
   essay.setGrammar(30);
   essay.setLength(20);
   essay.setContent(30);
   cout<<"Total Score: "<<essay.getScore()<<", Letter Grade: "<<essay.getLetterGrade()<<endl;
  
}

===================================================================

C:\Users\User\Documents\Untitled5.cpp - [Executing] - Dev-C++ 5.11 File Edit Search View Project Execute Tools AStyle Window Help TDM-GCC 4.9.2 64-bit Release (globals) Untitled5.cpp 34 else f letterGrade = 'F'; } return letterGrade 35 C:Users\User\DocumentsUntitled5.exe 36 Total Score: 45, Letter Grade: F Total Score: 90, Letter Grade: A 37 38 39 E class Essay: public GradedActivity{ 40 private: double grammar double spelling; double length; double content; 41 Process exited after 0.01062 seconds with return value 0 Press any key to continue 42 43 44 45 46 public: Essay() GradedActivity (0) { 47 48F 49 50 } Essay(double gr, double sp, double le, double con):GradedActivity(gr+sp+ grammar (gr), spelling(sp), length(le), content(con){ 51 52 53 } void setGrammar (double score) 54 55E 56 grammar score; setScore(grammar+spelling+length+content); } void setSpelling(double score){ spelling=score; setScore(grammar+spelling+length+content) 57 58 59 60 61 HCompiler Resources dh Compile Log Debug Find Results Close Errors: 0 Warnings o Output Filename: C:\Users\User\Documents\Untitled5.exe Abort Compilation Output Size: 1.83531l093597412 MiB Compilation Time: 1.86s


Related Solutions

Design an Essay class that is derived from the GradedActivity class: class GradedActivity{ private: double score;...
Design an Essay class that is derived from the GradedActivity class: class GradedActivity{ private: double score; public: GradedActivity() {score = 0.0;} GradedActivity(double s) {score = s;} void setScore(double s) {score = s;} double getScore() const {return score;} char getLetterGrade() const; }; 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)...
If a class A implements interface I1 and class C and D are derived from class...
If a class A implements interface I1 and class C and D are derived from class A, a variable of type I1 can be used to hold references of what type of objects? which one is correct 1. A, C, and D 2. A and D
1. In c++, Class D is derived from class B. The class D does not contain...
1. In c++, Class D is derived from class B. The class D does not contain any data members of its own . Does the class D require constructor? If yes, why? Explain with the help of a code example. 2. State true or false, giving proper reasons[3,5] (a) Virtual functions are used to create pointer to base class. (b) A pointer to base class cannot be made to point to objects of derived class. (c) Defining a derived class...
C++ Code Vehicle Class The vehicle class is the parent class of a derived class: locomotive....
C++ Code Vehicle Class The vehicle class is the parent class of a derived class: locomotive. Their inheritance will be public inheritance so reflect that appropriately in their .h files. The description of the vehicle class is given in the simple UML diagram below: vehicle -map: char** -name: string -size:int -------------------------- +vehicle() +setName(s:string):void +getName():string +getMap():char** +getSize():int +setMap(s: string):void +getMapAt(x:int, y:int):char +~vehicle() +operator−−():void +determineRouteStatistics()=0:void The class variables are as follows: • map: A 2D array of chars, it will represent the...
C++ Code Vehicle Class The vehicle class is the parent class of the derived class: dieselLocomotive....
C++ Code Vehicle Class The vehicle class is the parent class of the derived class: dieselLocomotive. Their inheritance will be public inheritance so reect that appropriately in their .h les. The description of the vehicle class is given in the simple UML diagram below: vehicle -map: char** -name: string -size:int -------------------------- +vehicle() +getSize():int +setName(s:string):void +getName():string +getMap():char** +setMap(s: string):void +getMapAt(x:int, y:int):char +~vehicle() +operator--():void +determineRouteStatistics()=0:void The class variables are as follows: map: A 2D array of chars, it will represent the map...
In c++, when dealing with inheritance in a class hierarchy, a derived class often has the...
In c++, when dealing with inheritance in a class hierarchy, a derived class often has the opportunity to overload or override an inherited member function. What is the difference? and which one is the better?
Class object in C++ programming language description about lesson base class and derived class example.
Class object in C++ programming language description about lesson base class and derived class example.
3. write a program that uses a class called "garment" that is derived from the class...
3. write a program that uses a class called "garment" that is derived from the class "fabric" and display some values of measurement. 20 pts. Based on write a program that uses the class "fabric" to display the square footage of a piece of large fabric.           class fabric            {                private:                    int length;                    int width;                    int...
7.3 (The Account class) Design a class named Account that contains: ■ A private int data...
7.3 (The Account class) Design a class named Account that contains: ■ A private int data field named id for the account. ■ A private float data field named balance for the account. ■ A private float data field named annualInterestRate that stores the current interest rate. ■ A constructor that creates an account with the specified id (default 0), initial balance (default 100), and annual interest rate (default 0). ■ The accessor and mutator methods for id, balance, and...
Programming Exercise Implement the following class design: class Tune { private:    string title; public:   ...
Programming Exercise Implement the following class design: class Tune { private:    string title; public:    Tune();    Tune( const string &n );      const string & get_title() const; }; class Music_collection { private: int number; // the number of tunes actually in the collection int max; // the number of tunes the collection will ever be able to hold Tune *collection; // a dynamic array of Tunes: "Music_collection has-many Tunes" public: // default value of max is a conservative...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT