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