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

// Q1 : add (66% of specifications) // This function is used to insert a new stu

ID: 3795686 • Letter: #

Question

 // Q1 : add (66% of specifications) // This function is used to insert a new student into the list. // Your list should be sorted alphabetically by name, so you need to search for the correct index to add into your list. // If a student already exists with the same name, then those students should be sorted by roll_number. // Do not allow for the same student to be added to the list multiple times. (same name and same roll_number(same roll number cannot happen)). // If the student already exists on the list, return 0. If the student is added to the list, return 1. // // NOTE: You must convert the string "genderValueString to an enum type and store it in the list. This will be tested. // (You must store all of the required information correctly to pass all of the test cases) // NOTE: You should not allow for the same student to be added twice, you will lose points if you do not account for this. // (That means that dogs on the list are allowed to have the same name but not same roll number). // You are not required to use pointer operations for your list but you may do so if you'd like.  // 'list' is passed to this function for automated testing purposes only, it is global. int add(char* name, char* genderValueString, char* standard, int roll_number, float tuition_fee, struct student* list) {     return 0; }  // Q2 : search (33% of specifications) // This function is used to search for a student on the list and returns the standard of that student // You will need to compare the search keys: name and roll_number, with the stored name and roll_number. // If the student exists in the list, return a String containing the standard of the requested dog. // If the student does not exist on the list, return NULL char* search(char* name, int roll_number, struct student* list) {     return NULL; } 

Explanation / Answer

struct student
{
char name[50];
char genderValueString;
char standard[50];
int roll_number;
float tution_fee;
struct student * next;
};

struct student *studlist = NULL;

int add(char* name, char* genderValueString, char* standard, int roll_number, float tuition_fee, struct student* list)
{
struct student * next = studlist; // saving head
int count = 0;
int checkGeneration = 1;

struct student *temp = (student *)malloc(sizeof(struct student));
strcpy(temp->name, name);
strcpy(temp->genderValueString, genderValueString);
   strcpy(temp->standard, standard);
temp->roll_number = roll_number;
temp->tuition_fee = tuition_fee;

if (next == NULL) {
temp->next = next;
studlist = temp;
return 1;
}

while (next != NULL) {
if (strcmpi(next->name, name) == 0 && next->roll_number == roll_number) {
return 0;
}
next = next->next;
}

next = studlist; // restore head
struct student * prev = NULL;
while (next != NULL) {
if ( strcmpi(next->name, name) > 0 || (strcmpi(next->name, name) == 0 && next->roll_number > roll_number) ) {

temp->next = next;
if (prev != NULL)
prev->next = temp;
if (next == studlist)
studlist = temp;
next = temp;
return 1;
}
if (next->next == NULL) {
next->next = temp;
temp->next = NULL;
return 1;
}
prev = next;
next = next->next;
}
return 0;
}

char* search(char* name, int roll_number, struct student* list)
{
   struct student * next = studlist; // saving head
   struct student * prev = NULL;
while (next != NULL) {
if ((strcmpi(next->name, name) == 0 && next->roll_number > roll_number) == 0) {
           return next->standard;
}
prev = next;
next = next->next;
}
return NULL;
}