List is mean structure or class

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

current coding
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
class Course{
private:
	//string studentName;
	string courseCode;
	string courseName;
	int credit;
	int numOfStudent;
	//string studentID;
	//double studentMarks;
public:

	Course();
	
	void setStudentName( string );
	string getStudentName();

	void setCourseCode( string );
	string getCourseCode();

	void setCourseName( string );
	string getCourseName();

	void setCredit( int );
	int getCredit();

	void setNumOfStudent( int );
	int getNumOfStudent();

	void setStudentID( string );
	string getStudentID();

	void setStudentMarks( double );
	double getStudentMarks();
};


I'm new to here , i don't really get what is the list mean , isn't mean use structure or?
I think how you're doing it in your code is right--the commented areas.

Aceix.
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.

Hope all goes well :)
Last edited on
err @ideasman

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?

1
2
3
4
5
6
7
struct Student{
string stuName;
string stuID;
double stuMarks;
};

Student theStudent[30];
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.
my tutor always not enough time to explain to me, that's why i ask some seniors at here.

by the way , if i using struct inside a class

how i access the structure of the class?
if the structure in private data
It is a member of your class so you can access it.


You can use the dot operator to access member of the struct.

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
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.

Good Luck !!
Last edited on
Topic archived. No new replies allowed.