-1

Here I've made a derived class called Essay, from the base class GradedActivity. I've made an object of the Essay class in main called object. When I wrote object.setGrammar(grammarPts) in main(), I'd hoped to feed what the score is to be held in the variable grammar in the setGrammar() function. What am I doing wrong? Thanks! I get one error:

99 8 F:\lab6part3.cpp [Error] request for member 'setGrammar' in 'object', which is of non-class type 'Essay(float, float, float, float)'

#include <iostream>

using namespace std;


//class gradedactivity (page 900)
class GradedActivity
{
protected: 

double score;

public: 
//default constructor
GradedActivity()
{
score = 0.0;
}
//parameterized constructor
GradedActivity(double s)
{
score = s;
}

setScore(double s)
{
score = s;
}

double getScore() const
{
return score;
}

char getLetterGrade() const;
};

class Essay : public GradedActivity
{
private:

float grammar;
float spelling;
float length;
float content;

public:

Essay(float g, float s, float l, float c)
{
setGrammar(g);
setSpelling(s);
setLength(l);
setContent(c);
}

void  setGrammar(float);
float getGrammar();
void  setSpelling(float);
float getSpelling();
void  setLength(float);
float getLength();
void  setContent(float);
float getContent();
};

void Essay::setGrammar(float g)
{
grammar = g;
}
float Essay::getGrammar() {return grammar;}

void  Essay::setSpelling(float s)
{
spelling = s;
}
float Essay::getSpelling() {return spelling;}

void  Essay::setLength(float l)
{
length = l;
}
float Essay::getLength() {return length;}

void  Essay::setContent(float c)
{
content = c;
}
float Essay::getContent() {return content;}

int main()
{ 
float grammarPts;

cout << "How many points, out of 30, did the student get for grammar?";
cin  >> grammarPts;

Essay object;
object.setGrammar(grammarPts);

return 0;
}
Ben
  • 111
  • 2
  • 9
  • 1
    Can you please afford extra few bytes on your hard drive and use indentation? – LogicStuff Mar 06 '16 at 19:49
  • In this Example, I don't see a reason why you need inheritance with GradedActivity. At least in this peace of code, there's no real usage. – Joel Mar 06 '16 at 19:52
  • You missed `void` before `setScore` and that `Essay` does not have a default constructor generated. – LogicStuff Mar 06 '16 at 19:52
  • Right now I'm hitting the spacebar 4x for each line of code on here. That's why I'm not indenting, sorry. Is there a quicker way to add code? – Ben Mar 06 '16 at 20:16
  • @Joel The reason for the seemingly unnecessary inheritance is because I was given the GradedActivity class in the assignment and am probably supposed to be using the score somehow in my essay class. Thanks. – Ben Mar 06 '16 at 20:23

1 Answers1

0

This could just be because you never defined a default constructor for Essay.

Anyway, I defined a default constructor and your code runs fine so that might be the issue. https://ideone.com/yNxV8N

NickLamp
  • 862
  • 5
  • 10