Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Could you please do part c?! In a high school, students\' information is kept in

ID: 3571919 • Letter: C

Question

Could you please do part c?!

In a high school, students' information is kept in a binary tree. Each student's name, GPA, and contact information is stored in a leaf node. So, we have one leaf node per student. To store information for a new student, or to retrieve information of a student, we follow the following rule: at each node of the tree, depending on the value of a parameter, we have to move to the left or to the right. As an example, at root, if the student's last name starts with A, B, ..., or M, we move to the left, otherwise we move to the right. At the second level, if the second letter in students last name is A, B, ..., or M, we move to the left, otherwise we move to the right. At the third level, if the student's father's annual income is higher than 60K we move to the left, otherwise we move to the right, etc. The rules have been designed carefully, such that each student's leaf node can be uniquely identified. In other words, it is not possible to store information of two students in a same leaf node. At the very last level of the tree, if student is a girl we move to the left and if the student is a boy we move to the right. Here is the structure of each node: struct node {string name; string contact; float GPA; node * left; node * right;}; Write a C++ function that takes a pointer to the root of the tree and returns number of students in the high school: int cntStudents(node * root); Write a C++ function that takes a pointer to the root of the tree and returns number of girls: int cntGirls(node * root); Write a C++ function that takes a pointer to the root of the tree and returns the average GPA of all the boys. float avgGPABoys(node * root);

Explanation / Answer

float avgGPABoys(node *root){
   static count=0;
   if(root->right->left==null && root->right->right==null){
       count++;
       return gpa;
   }else{
       return (avgGPABoys(root->left)+avgGPABoys(root->right))/count;
   }
}