The instructions appear to suggest you keep a global list of up to 15 students.
1 2 3
|
constexpr int MAX_NUM_DE_ESTUDIANTES = 15;
Estudiante estudiantes[MAX_NUM_DE_ESTUDIANTES];
int NumDeEstudiantes = 0;
| |
I think a similar pattern could be used for the list of subject matter:
1 2 3
|
constexpr int MAX_NUM_DE_MATERIAS = 15;
Materia materias[MAX_NUM_DE_MATERIAS];
int NumDeMaterias = 0;
| |
Now, to ADD a student, for example, you just need to check that you aren’t at your max, and then get the information from the user:
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
|
void AgregaEstudiante()
{
// Make sure there is room for the new student’s information
if (NumDeEstudiantes >= MAX_NUM_DE_ESTUDIANTES)
{
std::cout << "No puede agregar más de " << MAX_NUM_DE_ESTUDIANTES << " estudiantes.\n";
return;
}
// Get the new student’s information from the user
std::cout << "Apellido? ";
std::cin.getline( estudiantes[NumDeEstudiantes].apellido, TAM );
std::cout << "Nombre de pila? ";
...
std::cout << "ID? ";
std::cin >> estudiantes[NumDeEstudiantes].id;
std::cin.ignore( std::numeric_limits <std::streamsize> ::max(), '\n' );
...
// Number of students’ information has increased
NumDeEstudiantes += 1;
}
| |
For option three, the user should type in a course name and some piece of information to identify a student (ID? names?). If the user does not type something in correctly, reject it (and make him choose to try from the main menu again).
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
|
void InscribirEstudiante()
{
std::string s;
int m, e;
// Ask for a course name
std::cout << "Elige curso: ";
getline( std::cin, s );
// Find the course
for (m = 0; m < NumDeMaterias; m++)
if (s == materias[n].ObtenerNombre())
break;
if (m == NumDeMaterias)
{
std::cout << "No existe tal curso\n";
return;
}
// Ask for a student name/id/whatever
std::cout << "Elige estudiante por whatever: ";
...
// Find the student
for (e = 0; e < NumDeEstudiantes; e++)
if (e == estudiantes[e].whatever)
break;
if (e == NumDeEstudiantes)
{
std::cout << "No existe tal estudiante.\n";
return;
}
materias[m].agregaEstudiante( @estudiantes[e] );
}
| |
Each course should have more than one student. Make sure you have an array:
1 2 3 4 5 6 7 8 9
|
class Materia
{
...
private:
...
Estudiante* lista_de_estudiantes[MAX_NUM_DE_ESTUDIANTES];
int num_de_estudiantes;
...
| |
Make sure to construct your Materia with an empty list (num_de_estudiantes = 0). The method to add a student to a course is very much the same as the method to add a student to your global list of students, except now you only need to assign a pointer to the student's datos in the global list:
1 2 3 4 5 6 7 8 9 10 11
|
void Materia.agregaEstudiante( Estudiante* estudiante )
{
if (num_de_estudiantes >= MAX_NUM_DE_ESTUDIANTES)
{
std::cout << "El curso se llenó. No puede agregar más estudiantes.\n";
return;
}
lista_de_estudiantes[num_de_estudiantes] = estudiante;
num_de_estudiantes += 1;
}
| |
This isn’t the only way to do this kind of thing. You could also maintain a std::vector of students, or pointers to students. You could new[] and delete[] a list of students (which would be a worse pain than using an array). You could maintain a linked list of students.
I suspect your assignment will allow for using an array (or a vector, if you can).
Finally, to display a course and the list of students attached is just iterating over that particular course’s array of students:
1 2 3 4 5 6 7 8
|
void Materia.mostrarinfo()
{
std::cout << "Curso: " << nombremateria << "\n";
std::cout << "Profesor: " << profesor << "\n";
std::cout << "Estudiantes matriculados:\n";
for (int n = 0; n < num_de_estudiantes; n++)
lista_de_estudiantes[n].mostrardatos();
}
| |
The examples I have given you should help you to write code that works. Good luck!