Question

In: Computer Science

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) {
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

I have created a class Essay with 4 double data members which store the values of the points received by the student for grammar,spelling,length and content as gram,spel,length and content respectively. The constructor initializes the values of all the data members to zero. The function init() takes input from the user and checks if the scores in different parts of the essay are below the limits, that is, grammar up to 30 points, spelling up to 20 points, length up to 20 points, and content up to 30 points. If the limits are met then the values are stored in the variables of the object, else a "Invalid values" prompt is generated. totalscore() function returns the total score of the student by adding all the values of gram,spel,length and content.

In the main function, the user is prompted to enter the points received for various parts in the essay. The object 'a' calls the init() function to check and store the inputs. If its valid then the numeric score is displayed and the letter grade is calculated by passing the total score obtained from 'a.totalscore()' into the setScore() function which is called using the GradeActivity class object 'g'. This sets the value of the score variable and then the same object is used to call the getLetterGrade() function which gives us the letter grade of the student. Then we print the letter grade.

If the inputs are not valid then the user will get two messages:

"The entered values are invalid"

"Please enter valid inputs".


Related Solutions

Consider the following class: import java.util.Scanner; public class MyPoint { private double x; private double y;...
Consider the following class: import java.util.Scanner; public class MyPoint { private double x; private double y; public MyPoint() { this(0, 0); } public MyPoint(double x, double y) { this.x = x; this.y = y; } // Returns the distance between this MyPoint and other public double distance(MyPoint other) { return Math.sqrt(Math.pow(other.x - x, 2) + Math.pow(other.y - y, 2)); } // Determines if this MyPoint is equivalent to another MyPoint public boolean equals(MyPoint other) { return this.x == other.x &&...
Consider the following class: import java.util.Scanner; public class MyPoint { private double x; private double y;...
Consider the following class: import java.util.Scanner; public class MyPoint { private double x; private double y; public MyPoint() { this(0, 0); } public MyPoint(double x, double y) { this.x = x; this.y = y; } // Returns the distance between this MyPoint and other public double distance(MyPoint other) { return Math.sqrt(Math.pow(other.x - x, 2) + Math.pow(other.y - y, 2)); } // Determines if this MyPoint is equivalent to another MyPoint public boolean equals(MyPoint other) { return this.x == other.x &&...
I. Design and code a class Rectangle that has the following properties: Two private members double...
I. Design and code a class Rectangle that has the following properties: Two private members double length and width A constructor that accepts two parameters for the private members Default constructor that sets both members to 0 Setters/getters for each private member Method area() that returns the area of the rectangle Method Perim() that returns the perimeter of the rectangle Method toString that return the param as a String Method Add that accepts a Rectangle and returns a rectangle with...
COMPLETE JAVA CODE public class Point2 { private double x; private double y;    /** *...
COMPLETE JAVA CODE public class Point2 { private double x; private double y;    /** * Create a point with coordinates <code>(0, 0)</code>. */ public Point2() { complete JAVA code this.set(0.0, 0.0); COMPLETE CODE }    /** * Create a point with coordinates <code>(newX, newY)</code>. * * @param newX the x-coordinate of the point * @param newY the y-coordinate of the point */ public Point2(double newX, double newY) { complete Java code this.set(newX, newY); }    /** * Create a...
A incomplete definition of a class Temperature is given below: public class Temperature { private double...
A incomplete definition of a class Temperature is given below: public class Temperature { private double value[] = {36.5, 40, 37, 38.3}; } [6] (i) Copy and put it in a new class. Write a method toString() of the class, which does not have any parameters and returns a string containing all the values separated by newlines. When the string is printed, each value should appear on a line in the ascending order of their indexes. Copy the content of...
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
java code ============ public class BankAccount { private String accountID; private double balance; /** Constructs a...
java code ============ public class BankAccount { private String accountID; private double balance; /** Constructs a bank account with a zero balance @param accountID - ID of the Account */ public BankAccount(String accountID) { balance = 0; this.accountID = accountID; } /** Constructs a bank account with a given balance @param initialBalance the initial balance @param accountID - ID of the Account */ public BankAccount(double initialBalance, String accountID) { this.accountID = accountID; balance = initialBalance; } /** * Returns the...
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...
Consider the following statements: #include #include class Temporary { private: string description; double first; double second;...
Consider the following statements: #include #include class Temporary { private: string description; double first; double second; public: Temporary(string = "", double = 0.0, double = 0.0); void set(string, double, double); double manipulate(); void get(string&, double&, double&); void setDescription(string); void setFirst(double); void setSecond(double); }; Write the definition of the member function set() so that the instance variables are set according to the parameters. Write the definition of the constructor so that it initializes the instance variables using the function set() Write...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT