Aug 7, 2016 at 5:19am UTC
I'm trying to follow my professors UML diagram ------->
http://prntscr.com/c2kqnh
I currently have this header written up trying to make GradedActivity inherit from Essay, but I am not putting it together correctly. I was hoping for some guidance?
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
//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;
//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 aGrammer)
{
grammar=aGrammar;
}
double getGrammar()
{
return grammar;
}
double setSpelling(int aSpelling)
{
spelling=aSpelling;
}
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(double s)
{
setScore=s;
}
void displayPoints()
{
}
};
class GradedActivity
{
private :
double score;
public :
double getScore()
{
return score;
}
string getGrade()
{
return grade;
}
};
#endif // ESSAY_CLASS_H_INCLUDED
Last edited on Aug 7, 2016 at 5:19am UTC
Aug 7, 2016 at 5:42am UTC
Hm, well we don't use const for this or std, so I'm a bit confused what you're doing. : )
Aug 7, 2016 at 5:47am UTC
Please use a different image hosting website. I can't see anything.
Aug 7, 2016 at 5:48am UTC
You are using std!
What do you think this is?
using namespace std;
And the const is just good practice. In your case you should ignore it.
Both of these details are unimportant for what you are trying to do.
Aug 7, 2016 at 5:54am UTC
Last edited on Aug 7, 2016 at 5:54am UTC
Aug 7, 2016 at 6:05am UTC
What I mean is we don't use std:: in our code besides when we use using namespace std.
We never learnt anything about it. We were just told to include that namespace.
Unless you're just educating me.
Aug 7, 2016 at 6:07am UTC
I'm trying to educate you.
I'm just saying that std:: and using namespace std; are basically equivalent. I'm not saying you should be doing "std::". I think you should stick to "using namespace std;". I'm just saying they're the same thing.
Aug 7, 2016 at 6:09am UTC
Oh. Alright. Haha. Thank you!
Aug 7, 2016 at 6:17am UTC
You have to evaluate the grade based on "score".
For example :
if(score >= 95) return "A+";
if(score >= 90) return "A";
if(score >= 75) return "B";
if(score >= 60) return "C";
if(score >= 45) return "D";
if(score < 45) return "F";
Last edited on Aug 7, 2016 at 6:18am UTC
Aug 7, 2016 at 6:54am UTC
Note : in the class Essay, the function setScore() has no parameter.
I am looking forward to further details of your assignment.
Aug 7, 2016 at 6:56am UTC
This was all we were given to help us. Our professor simply told us to follow the UML diagram.
Aug 7, 2016 at 7:42am UTC
Alright, here you go.
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
//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;
//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;
}
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(double s)
{
score=s;
}
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
This is main
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
// Ashton Dreiling
//Essay exercise program
#include <iostream>
#include "Essay class.h"
#include <string>
#include <stdlib.h>
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);
EssayClass essayObject(grmmr, splling, correctlength, con);
// Displaying the scores that were inputed
cout << "The recorded scores are:" << endl;
cout << "Grammar : " << essayObject. << endl;
cout << "Spelling : " << splling << endl;
cout << "Correct Length : " << correctlength << endl;
cout << "Content : " << con << endl;
cout << "Total : " << grmmr + splling + correctlength 2+ con << endl;
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)." << 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
These are errors
https://s8.postimg.org/ft66skrsl/Screenshot_30.png
Last edited on Aug 7, 2016 at 7:54am UTC