i have 10 students, each student is associated with 5 courses and the section of course, i want to do this in array, please help regarding this. thanks.
for example
john
book1 A
book2 A
book3 C
book4 D
book5 B

marry
book1 C
book2 B
book3 A
book4 B
book5 B

Recommended Answers

All 2 Replies

If you have not yet studied structures then declare two arrays, one for 10 student names and the other for the sections. This assumes the names book1, book2, etc never change, so there's no point in storing those strings. If, however, those names can be different for each student then this array won't work because it can't store the names.

char student_sections[10][5][1];
char student_names[10][20];

A more robust solution would be to use a structure and make an array of structures.

struct course
{
   char name[8];
   char section;
};

struct student
{
   char name[20];
   struct course courses[5];
}

struct student students[10];

I'd create a class or structure for a course, then a class for a student that has a vector (or array if you so choose) of courses. Finally, I'd create a vector (or array if you so choose) of students and be good to go.

class Course
{
    ...
};

class Student
{
    Course _courses[5]; // Since you asked for arrays
    ...
};

Student students[10]; // Since you asked for arrays
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.