you are to implement a class named Course. A Course class should be able to keep the course code, course name, credits, the number of students enrolled, a list of students’ id, and a list of students’ marks. You can assume that a maximum of 30 students may enrol in a course
I would have a class for a student as well, which would contain their m_FirstName, m_Last Name, m_Credit, m_Id . It is a convention to have member variables start with m_
The CStudent class is acting like a record of data as in a database.
I also name my classes with a leading C as in CStudent or CCourse.
Now it isn't a good idea to have public get / set functions for each member variable - you might as well make all the member variables public !! You could have one set function that sets all the member variables at once. And another function that does output like printing for example. I would also have a NewStudent function in the CCourse class.
Edit: You should also have a constructor that initialises variables such m_Count.
For your actual question, by list they mean a data structure to store multiple objects in. You could use the STL <list> , but for this you could just use a STL <vector> which is just like an array, but it automatically resizes itself. That is probably the easiest thing to do.
Look at the reference page, top left of this page for examples on how to use vectors.
The vector you put all the CStudent objects into should be a member of the CCourse class.
i didn't not learn vector before since my class haven't teach until that part .
so still got other way?
@aceix because the question wanted me to use maximum 30 of student.
so how could i declare maximum 30 array for student ?
for my concept i think structure will do? or still got other way?
I think that in your assignment the list means an array of 30 elements. The elements indeed can be nodes of the list or can be "simple" elements of the array.
You should ask your tutor what did he mean saying about list.
const STULISTSIZE = 30;
Student StudentList[STULISTSIZE];
StudentList[1].stuName = "Fred";
//using cin
int count;
for (count = 0;count < STULISTSIZE; count++) {
cout << "Input Student name " << endl;
cin >>StudentList[count].stuName;
//similar for the other members
}
cout << "Student name is " << StudentList[1].stuName;
//to output all of them
for (count = 0;count < STULISTSIZE; count++) {
cout << "Student name is " << StudentList[count].stuName;
//similar for the other members
}
The most important thing is you need to make an object of the class type in the main function. You then call that objects functions to interact with it.
Members of classes can be accessed with the dot operator as well. So you might have in main:
1 2 3 4 5 6 7 8 9 10
CCourse TheCourse;
//after all the info has been input
int count;
for (count = 0;count < STULISTSIZE; count++) {
cout << cout << "Student name is "
cout << TheCourse.StudentList[count].stuName << endl;
}
This all assumes that everything is public, but you are going to have member functions that do the input / output, so your code will look different. These examples are so you can see how to access member variables in a basic sense - you can adapt that suit your class definitions, by implementing member functions properly.