finish the code of TODO: struct Student { unsigned int sid; // id is an unique…
- User
finish the code of TODO: struct Student { unsigned int sid; // id is an unique identifier of the Student (e.g., 39) char name[MAX_TITLE]; // title is a description of the Course (e.g., History) unsigned int ranks_count; // The total number of star_ranks on existing // courses the student did until now Student *next; // The pointer pointing to the next Student };
struct StarRank { unsigned int star; // The star-ranking the student gave to that course Student *student; // The pointer showing to the struct of the student that // made the star_rank StarRank *next; // The pointer pointing to the StarRanks struct };
// A sorted linked list represents a shopping cart, sorted by item->id struct Course { unsigned int course_id; // course_id is an unique identifier of the Course // (e.g., History) char name[MAX_TITLE]; // The course name int stars_count[MAX_RANKING_STARS]; // The count of stars from 1 (lowest) to // MAX_RANK (highest rank) of the course StarRank *star_rank_head; // The pointer pointing to the StarRanks struct }; bool add_star_rank(Student *&student_head, unsigned int sid, Course **&course_array, unsigned int course_id, const unsigned int num_courses, int star) { // TODO: Write code to implement add_star_rank // use error cout carefully int i = 0; if (!search_course(course_array, course_id, num_courses, i)) { return false; }
Student *stt = nullptr; Student *edd = nullptr; if (!search_student(student_head, sid, stt, edd)) { return false; }
return true; }
- Assistant
bool add_star_rank(Student *&student_head, unsigned int sid, Course **&course_array, unsigned int course_id, const unsigned int num_courses, int star) { int i = 0; // Search for the course with the specified course_id if (!search_course(course_array, course_id, num_courses, i)) { cout << "Course not found." << endl; return false; }
// Search for the student with the specified sid Student *student = nullptr; Student *prev_student = nullptr; if (!search_student(student_head, sid, student, prev_student)) { cout << "Student not found." << endl; return false; }
// Create a new StarRank node StarRank *new_star_rank = new StarRank; new_star_rank->star = star; new_star_rank->student = student; new_star_rank->next = nullptr;