Parallel arrays - Error.

Hi! Task; Create a class of student grades and create 3 arrays (above mentioned arrays). Ask user to input the grade scores for the 5 objects, and then print the objects scores and grades (converted score to letter grade) in all 5 subjects!
I chose to make 4 arrays to also include the object names, here is the current code but I'm getting the error invalid use of non static data member Student::score, Student::grade...etc.. from this location.
What am I doing wrong?


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
 MAIN
#include <iostream>
#include <string>
#include "StudentGrades.h"





int main()
{

Student one("Pacachuti", 42);
Student two("Orjatar",21);
Student three("Rendem", 19);
Student four("Chakkaron", 25);
Student five("Tukktukk", 26);

int i;

for (int i = 0; i < 5; i++) {

        std::cout << "Enter student ID: ";
        std::cin >> Student::studentName[i];
		std::cin >> Student::score[i];
		std::cout << "Enter mathematics score: ";
		std::cin >> Student::score[i];
		std::cout << "Enter Swedish score: ";
		std::cin >> Student::score[i];
		std::cout << "Enter English score ";
		std::cin >> Student::score[i];
		std::cout << "Enter History score: ";
		std::cin >> Student::score[i];
		std::cout << "Enter Physics score: ";
		std::cin >> Student::score[i];

	}

    for ( int i = 0; i < 5; i++)
   	 {
   	    std::cout << Student::studentName[i] << "\t";  // \t = tab character
   	    std::cout << Student::courses[i] <<"\t");
   	    std::cout << Student::score[i] << "\t");
   	    std::cout << Student::grade[i];

   	 }


	for (int i = 0; i < 5; i++)
	{
		Student::grade[i] = Student::CalculateGrade(score[i]);
	}
}
header
#ifndef STUDENTGRADES_H_INCLUDED
#define STUDENTGRADES_H_INCLUDED

#include <iostream>
#include <string>

class Student {
public:

// Variables

int age;


//Array variables
std::string  courses[5] = { "Mathematics","Swedish","English","History","Physics" };
int score[5];
char grade[5];
std::string studentName[5];

//constructor
Student();
//overload constructor
Student(std::string, int);

//destructor
~Student();

//Function for calculating grade
char CalculateGrade(const int);

void printOut();



};


#endif // STUDENTGRADES_H_INCLUDED


2nd CPP
#include <iostream>
#include "StudentGrades.h"


Student::Student() {
}

Student::Student(std::string name, int age){

}

Student::~Student() {
}

char Student::CalculateGrade(const int gScore) {
	char grade;
	if (gScore > 95)
		return = 'A';
	else if (gScore  > 90)
		return 'B';
	else if (gScore > 80)
		grade 'C';
	else if (gScore > 70):P
		return 'D';
	else if (gScore > 60)
		return = 'E';
	else
		return= 'F';
    }






Desperately need some help here please!
Last edited on
This makes no sense - std::cin >> Student::studentName[i];

I don't know what you expect this line of code to do. What are you trying to do?


Haha, ups... was trying to store the cin input in the studentName array. Im obviously way off and this should be pretty simple, but my bran is completely fried currently. :/
Your studentName array appears to be an array of five strings, inside a Student object.

Are you expecting every student to have five names? If not, you need to go back to the start and think about what you're trying to do and why you have this Student class.

Last edited on
Topic archived. No new replies allowed.