Classes and arrays

Hey, I've been given a question which requires me to make a class and make use of it. They haven't given much detail so was hoping someone could please help.

I need to make a class called Module which handles information regarding my assignments for a specific module.

Now this is what I have so far:

#include <iostream>

using namespace std;

class Module
{
public:
void setModules(string module1, string module2, string module3, string module4, string module5);
void setMarks(int aMark1, int aMark2);
int updateMarks();
void calcSemesterMark(double & semesterMark);
void display(double & semesterMark);
Module();

private:
string modules[5], module;
int mark1, mark2, semesterMark;
};

int main()
{
Module modules[5];
Module m;
double semesterMark = 0;
int mark2;

cout << "Semester Marks:" << endl;
cout << "================" << endl << endl;

modules[0].setMarks(50, 55);
modules[1].setMarks(90, 85);
modules[2].setMarks(77, 60); //sets the value for each module
modules[3].setMarks(84, 76);
modules[4].setMarks(66, 99);

for (int j = 0; j < 1; j++)
{
for (int i = 0; i < 5; i++)
{
modules[j].setModules("cos1512", "mat1512", "inf1520", "cos1521", "inf1505");
modules[j].updateMarks();

//Values are set to 2 decimal places
cout.precision(2);
cout.setf(ios::fixed);


modules[i].calcSemesterMark(semesterMark);

}
modules[j].display(semesterMark);
}
return 0;
}

//Calculates the semester mark and returns the value
void Module::calcSemesterMark(double & semesterMark)
{
double assign1, assign2, total;

assign1 = (mark1 / 100.00) * (30 / 100.00);
assign2 = (mark2 / 100.00) * (70 / 100.00);

total = assign1 + assign2;

semesterMark = total * 100;

}

//Updates the mark for cos1512 by 5%
int Module::updateMarks()
{
for (int i = 0; i < 5; i++)
{
if (modules[i] == "cos1512")
mark2 = mark2 + 5;
}
return mark2;
}

//Displays the semester marks and modules to the screen
void Module::display(double & semesterMark)
{
for (int i = 0; i < 5; i++)
{
cout << modules[i] << ": " << semesterMark << "%" << endl;
}
}

//Initialises the array with the modules
void Module::setModules(string module1, string module2, string module3, string module4, string module5)
{
modules[0] = module1;
modules[1] = module2;
modules[2] = module3;
modules[3] = module4;
modules[4] = module5;
}

//Initialises the marks
void Module::setMarks(int aMark1, int aMark2)
{
mark1 = aMark1;
mark2 = aMark2;
}

//Constructor
Module::Module()
{
module = "";
mark1 = 0;
mark2 = 0;
semesterMark = 0;
}

The output is:

cos1512: 89.10%
mat1512: 89.10%
inf1520: 89.10%
cos1521: 89.10%
inf1505: 89.10%

but I need the output to be:

cos1512: 57.00
mat1512: 86.50%
inf1520: 65.10%
cos1521: 78.40%
inf1505: 89.10%

It seems to be only displaying the last mark and I'm not sure why. Any help would be appreciated!
Is a Module supposed to represent a group of modules or a single module? Looking at the definition of Module, one can't really tell. You have an array of 5 strings (modules) and a single string module (which is never used outside of an assignment in the constructor) and space two store 2 marks and the semester mark. Presumably you would want to store those marks for each module.

Your display method outputs the same semester mark for all 5 modules strings, which again, suggests that your Module is a group of modules and that it isn't at the same time as there is only room for one semester mark.

Then in main you create an array of 5 Module objects, which means you now have 36 std::string objects in total and room for 10 marks and 5 semester marks. Should you really have that many strings floating around?
OK, it must represent a specific module. I got rid of the single string(module), didn't need it. Yes I would like to store two(2) marks for each module.

How would I make my class Module represent a single module? Would I have to change my setModules member function?
Topic archived. No new replies allowed.