HI guys..
i need some help in linking two structures..
basically it means
There's a course in a college where there are several course sections in it. Students can enroll in the course sections.. but they are limited to 4 course sections per course.
i have done the structures and have assigned pointers for them, but i just don't know how to link them, so i can add students to the course sections and the course sections to the course..
help pls..Code:#include <iostream> using namespace std; struct Course { char courseNumber[6]; char title[20]; int creditHour; Course *CourseNxt; }; struct CourseSection { char sectionNumber [20]; int startTime; int startDate; int roomNumber; CourseSection *CourseSectionNxt; }; struct Student { char name [30]; char studentId [30]; char major [30]; Student *StudentNxt; }; struct Node { Student stud; CourseSection cs; Node *NodeNxt; }; Course *course_ptr = NULL; Course *course_current; CourseSection *courseSection_ptr = NULL; CourseSection *courseSection_current; Student *stu_ptr; Student *stu_current; Node *node_ptr; Node *node_current; void addNewCourse(); void displayCourse(); void addNewCourseSection(); int main() { int input; menu: cout<<"[1] ADD a Course"; cout<<"\n[2] ADD a Course Section"; cout<<"\n[3] DELETE a record"; cout<<"\n[4] SEARCH by student number"; cout<<"\n[5] DISPLAY a Course"; cout<<"\n[6] SORT by name"; cout<<endl; cout<<"what's your choice?"; cin>>input; switch(input) { case 1: addNewCourse(); goto menu; break; case 2: addNewCourseSection(); goto menu; break; case 5: displayCourse(); goto menu; break; } system("pause"); return 0; } void addNewCourse() { Course *temp, *temp2; temp = new Course; cout<<"Course Number:"<<flush; cin>>temp->courseNumber; cout<<"Title:"<<flush; cin>>temp->title; cout<<"Credit Hours:"<<flush; cin>>temp->creditHour; temp->CourseNxt = NULL; if (course_ptr == NULL) { course_ptr = temp; course_current = course_ptr; } else { temp2 = course_ptr; // We know this is not NULL - list not empty! while (temp2->CourseNxt != NULL) { temp2 = temp2->CourseNxt; // Move to next link in chain } temp2->CourseNxt = temp; } } void displayCourse() { Course *temp; temp = course_ptr; cout << endl; if (temp == NULL) cout << "The list is empty!" << endl; else { while (temp != NULL) { // Display details for what temp points to cout<< "Course Number: "<<temp->courseNumber<<endl;;; cout<< "Course Title: "<<temp->title<<endl;; cout<< "Credit Hours:"<<temp->creditHour<<endl;; if (temp == course_current) cout << " <-- Current node"; cout << endl; temp = temp->CourseNxt; } cout << "End of list!" << endl<<endl; } } void addNewCourseSection() { CourseSection *temp, *temp2; temp = new CourseSection; cout<<"Course Section Number:"<<flush; cin>>temp->sectionNumber; cout<<"startTime:"<<flush; cin>>temp->startTime; cout<<"startDate:"<<flush; cin>>temp->startDate; cout<<"Room Number:"<<flush; cin>>temp->roomNumber; temp->CourseSectionNxt = NULL; if (courseSection_ptr == NULL) { courseSection_ptr = temp; courseSection_current = courseSection_ptr; } else { temp2 = courseSection_ptr; // We know this is not NULL - list not empty! while (temp2->CourseSectionNxt != NULL) { temp2 = temp2->CourseSectionNxt; // Move to next link in chain } temp2->CourseSectionNxt = temp; } }



LinkBack URL
About LinkBacks



