Note that there are some explanatory texts on larger screens.

plurals
  1. POHow would you go about solving this? Old-Fashion Student/Course/School Code. Here's my approach:
    primarykey
    data
    text
    <p>I'm just curious if my way of thinking is incorrect. Would my way of thinking work, or would I need pointers/references in my code? How would you approach this? I'm just rough-sketching at this point. Look at my comments for my concerns. Mainly curious as to if I should use pointers, and how to reference classes in my Student class.</p> <p>Shortened Example Problem: Make a program that lets you: 1.) Create/Delete a Student from School 2.) Create/Delete a Course from school 3.) Add/Remove a student from a Course 4.) Print a list of students in a course 5.) Print a list of courses a student is in.</p> <pre><code>class Student { public: string name; int id; Student(){};//Default Construct Student(int idin,string namein) { id=idin; name=namein; } void PrintClasses() { //Umm... I can't create a Class Vector yet because Class is declared under this.. Hmm... Not sure on this part. } }; class Class { public: int id; string name; Student students_in_class; //Is this the right way to store students in the class? Class(){};//Default Constructor Class(int idin, string namein) { id=idin; name=namein; } void PrintStudents() { for (i=0;i&lt;students_in_class.size();i++) { cout&lt;&lt;students_in_class.id&lt;&lt;'\n'; } } }; class School { public: Vector&lt;Student&gt; studentlist; Vector&lt;Class&gt; classlist; //This is where you do everything. void StudentAdd(int id,string name) { //Adds a student to the school Student mystudent=Student(id,name); studentlist.push_back(mystudent); } void StudentAdd2Course(int student_id,int course_id) { for (i=0;i&lt;classlist.size();i++) { if(classlist[i].id==course_id) { //Correct Class ID Found. Now find student Id for (int j=0;j&lt;studentlist.size();j++) if(studentlist[j].id==student_id) classlist[i].students_in_class.push_back(studentlist[j]);//Push Student in class list } } } void StudentRemoveFromCourse(int student_id,int course_id) { for (i=0;i&lt;classlist.size();i++) { if(classlist[i].id==course_id) { //Correct Class ID Found. Now find student Id for (int j=0;j&lt;studentlist.size();j++) if(studentlist[j].id==student_id) classlist[i].students_in_class.erase(studentlist[j]);//Push Student in class list } } } //Other functions like create class, delete class, etc }; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload