left of '.setScore' must have class/struct/union

Hi everyone!
I have been having problems with my program where I am supposed to calculate the total essay score. I was wondering why the listed error in the title shows up, along with another error which says "expression must have class type"? Here is the code from all three files:

(GradedActivity.h)

#ifndef GRADEDACTIVITY_H
#define GRADEDACTIVITY_H

//This is the class declaration for Graded Activity
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;
}g;
#endif

(GradedActivity.cpp)

#include "GradedActivity.h"

//This is the member function GradedActivity::getLetterGrade
char GradedActivity::getLetterGrade() const
{
char letterGrade; //This holds the letter Grade

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;
}

(Essay.cpp)
#include <iostream>
#include "GradedActivity.h"
using namespace std;

//This is the essay class
class Essay
{

double grammar;
double spelling;
double length;
double content;

//These are public members
public:
Essay()
{
grammar = 0.0;
spelling = 0.0;
length = 0.0;
content = 0.0;

}
void inital()
{
double gram = 0.0;
double spel = 0.0;
double leng = 0.0;
double cont = 0.0;
//Enter values here
cin >> gram;
cin >> spel;
cin >> leng;
cin >> cont;

//if statement containing mutator function
if (gram <= 30 && spel <= 20 && leng <= 20 && cont <= 30)
{
grammar = gram;
spelling = spel;
length = leng;
content = cont;
}
else
{
cout << "There was invalid input in one of the categories." << endl;
return;
}
}
double totalEssayScore()
{
return (grammar + spelling + length + content);
}
};

//The main function
int main()
{
Essay a;
char g;
cout << "Enter the values recieved for the grammar, spelling, correct length, and content sections: " << endl;
a.inital();
double total = a.totalEssayScore();
if (total >= 0 && total <= 100)
{
cout << "The numeric score for the essay is: " << total << endl;
g.setScore(total);
}
else
{
cout << "The score cannot be determined." << endl;
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int main()
{
	Essay a;
	char g;
	cout << "Enter the values recieved for the grammar, spelling, correct length, and content sections: " << endl;
	a.inital();
	double total = a.totalEssayScore();
	if (total >= 0 && total <= 100)
	{
		cout << "The numeric score for the essay is: " << total << endl;
		/*->*/ g.setScore(total);
	}
	else
	{
		cout << "The score cannot be determined." << endl;
	}
	return 0;
}


Your trying to use a char like a class name declaration(like Essay) I think you meant to declare it as GradedActivity g;

Also when entering values, you can do: cin >> gram >> spel >> leng >> cont; just a small thing but makes things neater.
Last edited on
Topic archived. No new replies allowed.