Class inheritance from another class.

Pages: 123
main.cpp :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Ashton Dreiling
//Essay exercise program
#include <iostream>
#include "Essay class.h"
#include <string>
#include <stdlib.h>
#include <iostream> // (***) Forgot


const int NUM_FOR_CAL1=0;

using namespace std;

void userInput(double &grammar, double &spelling, double &CL, double &content);

int main ()
{
   // Some variables
    double grmmr;
    double splling;
    double correctlength;
    double con;
    double scr;
    string grde;
    userInput(grmmr, splling, correctlength, con);

    Essay essayObject(grmmr, splling, correctlength, con); // (***) Essay not EssayClass 
    // Displaying the scores that were inputed
    cout << "The recorded scores are:" << endl;
    cout << "Grammar : " << essayObject.getGrammar()  << endl; // (***) essayObject.getGrammar()
    cout << "Spelling : " << splling << endl;
    cout << "Correct Length : " << correctlength << endl;
    cout << "Content : " << con << endl;

   cout << "Total : " << grmmr + splling + correctlength + 2 + con << endl; // (***) "correctlength + 2" not "correctlength 2"

  // essayObject.addScore();
  // essayObject.findGrade(); // (***) The two functions don't exist
   cout << endl;
   cout << "The grade for this essay is : " << "Not yet handled" << endl; // The function essayObject.getGrade() does not exist

    system("Pause");
    return 0;
}//end main

void userInput(double &grmmr, double &splling, double &correctlenght, double &con)
{

    //input from user to enter points
    cout << "Enter the points for an essay." << endl;
    cout << "Grammar (must be 30 or less points)." << endl;
    cin >> grmmr;
    while (grmmr>30 || grmmr<NUM_FOR_CAL1)
    {
        cout << "Grammar must be 30 or less points." << endl;
        cin >>grmmr;
    }//end while loop
    cout << "Spelling (must be 20 or less points)." << endl;
    cin >> splling;
    while(splling>20 || splling<NUM_FOR_CAL1)
    {
        cout << "Spelling must be 20 or less points." << endl;
        cin>>splling;
    }//end while loop
    cout << "Correct length (must be 20 or less points)." << endl;
    cin>>correctlenght;
    while(correctlenght>20 || correctlenght<NUM_FOR_CAL1)
    {
        cout << "Correct length must be 20 or less points." << endl;
        cin >> correctlenght;
    }//end while loop
    cout << "Correct content (must be 30 or less points)." << endl;
    cin>>con;
    while(con>30 || con<NUM_FOR_CAL1)
    {
        cout << "Content must be 30 or less points." << endl;
        cin >> con;
    }//end while loop
}// end user input 
It should compile for now but if you have problems ask me
Here is the working program :
The header :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//Ashton Dreiling
//Essay header
#ifndef ESSAY_CLASS_H_INCLUDED
#define ESSAY_CLASS_H_INCLUDED
#include <string>

using namespace std;

class Essay
{

//private fields to hold data
private:
    double grammar;
    double spelling;
    double correctLength;
    double content;

    double total; //  (***) A variable is needed
	string grade;

//public methods for outside code
public:
    Essay(double G, double S, double corlen, double C)
    {
        grammar = G;
        spelling = S;
        correctLength = corlen;
        content = C;
    }//end EssayClass constructor

    void setGrammar(double aGrammar)
    {
        grammar=aGrammar;
    }

    double getGrammar()
    {
        return grammar;
    }

    double setSpelling(int aSpelling)
    {
        spelling=aSpelling;
    }

	void addScore() //  (***) A function is needed
	{
		total = grammar + spelling + correctLength + content;
	}

	void findGrade()  // (***) A function is required
	{
		if(total >= 90) grade = "A";
		else if(total >= 80) grade = "B";
		else if(total >= 65) grade = "C";
		else if(total >= 50) grade = "D";
		else if(total < 50) grade = "F";
	}

	string getGrade()  // (***) A function is required
	{
		return grade;
	}

    double getSpelling()
    {
        return spelling;
    }

    void setCorrectLength(double aCorrectLength)
    {
        correctLength=aCorrectLength;
    }

    double getCorrectLength()
    {
        return correctLength;
    }

    void setContent(double aConent)
    {
        content=aConent;
    }

    double getContent()
    {
        return content;
    }

    void setScore() //  (***) Empty function, we do nothing
    {
    }

    void displayPoints()
    {

    }
};

class GradedActivity : public Essay
{
private:
    double score;
    string mygrade;
public:
    double getScore()
    {
        return score;
    }
    void setScore( double score2 )
    {
        score = score2;
    }
    string getGrade()
    {
        if(score >= 95)
            mygrade ="A+";
        else if(score >= 90)
            mygrade = "A";
        else if(score >= 75)
            mygrade = "B";
        else if(score >= 60)
            mygrade = "C";
        else if(score >= 45)
            mygrade = "D";
        else if(score < 45)
            mygrade = "F";
        return mygrade;
    }
};

#endif // ESSAY_CLASS_H_INCLUDED 
main.cpp :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Ashton Dreiling
//Essay exercise program
#include <iostream>
#include "Essay class.h"
#include <string>
#include <stdlib.h>
#include <iostream>


const int NUM_FOR_CAL1=0;

using namespace std;

void userInput(double &grammar, double &spelling, double &CL, double &content);

int main ()
{
   // Some variables
    double grmmr;
    double splling;
    double correctlength;
    double con;
    string grde;
    userInput(grmmr, splling, correctlength, con);

    Essay essayObject(grmmr, splling, correctlength, con);
    // Displaying the scores that were inputed
    cout << "The recorded scores are:" << endl;
    cout << "+ Grammar : " << essayObject.getGrammar()  << endl;
    cout << "+ Spelling : " << splling << endl;
    cout << "+ Correct Length : " << correctlength << endl;
    cout << "+ Content : " << con << endl;

   cout << "+ Total : " << grmmr + splling + correctlength + con << endl; // (***) "correctlength + 2" should be "correctlength"

	essayObject.addScore();
	essayObject.findGrade();

   cout << endl;
   cout << "The grade for this essay is : " << essayObject.getGrade() << endl;

    system("Pause");
    return 0;
}//end main

void userInput(double &grmmr, double &splling, double &correctlenght, double &con)
{

    //input from user to enter points
    cout << "Enter the points for an essay." << endl;
    cout << "Grammar (must be 30 or less points) : ";
    cin >> grmmr;
    while (grmmr>30 || grmmr<NUM_FOR_CAL1)
    {
        cout << "Grammar must be 30 or less points. Enter again : ";
        cin >>grmmr;
    }//end while loop

    cout << "Spelling (must be 20 or less points) : ";
    cin >> splling;
    while(splling>20 || splling<NUM_FOR_CAL1)
    {
        cout << "Spelling must be 20 or less points. Enter again : ";
        cin>>splling;
    }//end while loop

    cout << "Correct length (must be 20 or less points) : ";
    cin>>correctlenght;

    while(correctlenght>20 || correctlenght<NUM_FOR_CAL1)
    {
        cout << "Correct length must be 20 or less points. Enter again : ";
        cin >> correctlenght;
    }//end while loop

    cout << "Content (must be 30 or less points). : ";
    cin>>con;
    while(con>30 || con<NUM_FOR_CAL1)
    {
        cout << "Content must be 30 or less points. Enter again : ";
        cin >> con;
    }//end while loop

	cout << endl;
}// end user input 
Do we need to use the class GradedActivity? What do we use this class for?
Do get the score and the grade. Yes, we do.
> Do get the score and the grade. Yes, we do.
That is not clear enough.

What do we use this class GradedActivity for?
Where is your assignment question?
What is this? class GradedActivity : public Essay { /* ... */ };
Every graded activity is an essay of some kind?

Shouldn't it be (as specified in the UML diagram):
there are different kinds of graded activities; one of them is an essay?
class Essay : public GradedActivity { /* ... */ };
@JLBorges
Essay points to GradedActivity... meaning that class GradedActivity inherits from class Essay (maybe)?
Good catch.

Also, that's all I know. I'm having a hard time figuring that out myself, system.

But I know we use it to get the score and the grade.

Which means we're supposed to be calling it somewhere.
Yes. It does.
But if class Essay inherits from class GradedActivity... the function setScore() will have no parameter (according to the diagram)...

So it is wrong maybe?
closed account (z05DSL3A)
closed account 5a8Ym39o6, your lack of knowledge and experience is showing again.
> Your lack of knowledge and experience is showing again.
We are just discussing how to solve the problem.
Sorry I'm not much help Wolf, I'm a beginner here.
closed account (z05DSL3A)
FBHSIE, you have nothing to be sorry about, closed account is the one who is getting a bad reputation for giving bad advice.
If you want choose "GradedActivity inherits Essay class", that is. Now you can use GradedActivity class.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//Ashton Dreiling
//Essay header
#ifndef ESSAY_CLASS_H_INCLUDED
#define ESSAY_CLASS_H_INCLUDED
#include <string>

using namespace std;


class Essay
{

//private fields to hold data
private:
    double grammar;
    double spelling;
    double correctLength;
    double content;

    double total;

//public methods for outside code
public:
    Essay(double G, double S, double corlen, double C)
    {
        grammar = G;
        spelling = S;
        correctLength = corlen;
        content = C;
    }//end EssayClass constructor

    void setGrammar(double aGrammar)
    {
        grammar=aGrammar;
    }

    double getGrammar()
    {
        return grammar;
    }

    double setSpelling(int aSpelling)
    {
        spelling=aSpelling;
    }

	void addScore() //  (***) A function is needed
	{
		total = grammar + spelling + correctLength + content;
	}

    double getSpelling()
    {
        return spelling;
    }

    void setCorrectLength(double aCorrectLength)
    {
        correctLength=aCorrectLength;
    }

    double getCorrectLength()
    {
        return correctLength;
    }

    void setContent(double aConent)
    {
        content=aConent;
    }

    double getContent()
    {
        return content;
    }

    double getTotal()
    {
        return total;
    }

    void setScore(double score) {}

    void displayPoints()
    {

    }
};


class GradedActivity : public Essay
{
private:
    double score;
    string mygrade;
public:
	GradedActivity(Essay essay) : Essay(essay) {}
    double getScore()
    {
        return score;
    }
    void setScore( double score2 )
    {
        score = score2;
    }

	void findGrade()
	{
        if(getTotal() >= 95) mygrade ="A+";
		else if(getTotal() >= 90) mygrade = "A";
		else if(getTotal() >= 80) mygrade = "B";
		else if(getTotal() >= 65) mygrade = "C";
		else if(getTotal() >= 50) mygrade = "D";
		else if(getTotal() < 50) mygrade = "F";
	}

	string getGrade()
    {
        return mygrade;
    }
};




#endif // ESSAY_CLASS_H_INCLUDED 
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Ashton Dreiling
//Essay exercise program
#include <iostream>
#include "Essay class.h"
#include <string>
#include <stdlib.h>
#include <iostream>


const int NUM_FOR_CAL1=0;

using namespace std;

void userInput(double &grammar, double &spelling, double &CL, double &content);

int main ()
{
   // Some variables
    double grmmr;
    double splling;
    double correctlength;
    double con;
    string grde;
    userInput(grmmr, splling, correctlength, con);

    Essay essayObject(grmmr, splling, correctlength, con);
    // Displaying the scores that were inputed
    cout << "The recorded scores are:" << endl;
    cout << "+ Grammar : " << essayObject.getGrammar()  << endl;
    cout << "+ Spelling : " << splling << endl;
    cout << "+ Correct Length : " << correctlength << endl;
    cout << "+ Content : " << con << endl;

   cout << "+ Total : " << grmmr + splling + correctlength + con << endl;

	essayObject.addScore();

	GradedActivity thisStudent(essayObject); // (***) How GradedActivity is declared
	thisStudent.findGrade();

   cout << endl;
   cout << "The grade for this essay is : " << thisStudent.getGrade() << endl;

    system("Pause");
    return 0;
}//end main

void userInput(double &grmmr, double &splling, double &correctlenght, double &con)
{

    //input from user to enter points
    cout << "Enter the points for an essay." << endl;
    cout << "Grammar (must be 30 or less points) : ";
    cin >> grmmr;
    while (grmmr>30 || grmmr<NUM_FOR_CAL1)
    {
        cout << "Grammar must be 30 or less points. Enter again : ";
        cin >>grmmr;
    }//end while loop

    cout << "Spelling (must be 20 or less points) : ";
    cin >> splling;
    while(splling>20 || splling<NUM_FOR_CAL1)
    {
        cout << "Spelling must be 20 or less points. Enter again : ";
        cin>>splling;
    }//end while loop

    cout << "Correct length (must be 20 or less points) : ";
    cin>>correctlenght;

    while(correctlenght>20 || correctlenght<NUM_FOR_CAL1)
    {
        cout << "Correct length must be 20 or less points. Enter again : ";
        cin >> correctlenght;
    }//end while loop

    cout << "Content (must be 30 or less points). : ";
    cin>>con;
    while(con>30 || con<NUM_FOR_CAL1)
    {
        cout << "Content must be 30 or less points. Enter again : ";
        cin >> con;
    }//end while loop

	cout << endl;
}// end user input 
@Grey Wolf
Sometimes I can't do my best because sometimes I text using my mobile phone.
closed account (z05DSL3A)
closed account, The UML diagram clearly shows Essay inherits from GradedActivity, JLBorges had already said this before your 'solution'.

Even now you are saying "If you want choose..." rather than 'my bad, I got it wrong...'
Pages: 123