Problem1 Data Structures Create a vector of structs that rep

Problem-1: Data Structures Create a vector of structs that represents a database in which a professor might store information pertaining to his/her class. Every element in the vector represents information about one particular student. For every student, the professor wants to store: - Name (a string) - University ID (Number) - Quiz scores (a vector of five quiz scores) The vector variable which you should call student, might look like the following: student Name ID_No Quiz Scores Bob, Myers 784 100 95 0 87 100 Dez, Bryant 123 100 100 90 100 98 Tony, Romo 332 75 82 85 90 72 Each element in the vector is a struct with three fields (name, id_no, quiz scores). For example the third element of this data structure could be defined as follows: >> student(3) = struct(\'Name\',\'Tony, Romo\', \'Id_No\',332,\'Quiz_Scores\', [75 60 85 90 72]); Create a structure with at least 5 students (add two or more students to the above list of students). The professor would like to print the quiz average for each student. To accomplish this, create a function printAverage() that would take as input the student structure, calculate the averages, and print the student names and quiz averages. An example of calling the function is as follows: >> printAverage(student)
Name Average
Bob, Myers 76.4
Dez, Bryant 97.6
Tony, Romo 80.8

Solution

Find the below program:

#include<stdio.h>

#include<stdlib.h>

#include<stdbool.h>

#include<string.h>

struct student

{

char name[10];

int uni_id;

int score1, score2, score3, score4, score5;

struct student *next;

};

struct student *head = NULL;

struct student *curr = NULL;

struct student* add_to_list(char name[], int uni_id,int score1, int score2, int score3, int score4, int score5)

{

struct student *ptr = (struct student*)malloc(sizeof(struct student));

if(NULL == ptr)

{

printf(\"\ Node creation failed \ \");

return NULL;

}

if(NULL == head)

{

head = curr = ptr;

}

strcpy(ptr->name, name);

ptr->uni_id = uni_id;

ptr->score1 = score1;

ptr->score2 = score2;

ptr->score3 = score3;

ptr->score4 = score4;

ptr->score5 = score5;

ptr->next = NULL;

curr->next = ptr;

curr = ptr;

printf(\"Database created for student with name %s\ \", name);

return ptr;

}

int delete_list(void)

{

struct student *del_next = NULL;

struct student *del = head;

printf(\"\ Deleting list\ \");

while(del != NULL)

{

del_next = del->next;

free(del);

del = del_next;

}

return 0;

}

void printAverage(void)

{

struct student *ptr = head;

struct student *ptr_next;

printf(\"\ -------Printing list Start------- \ \");

while(ptr != NULL)

{

printf(\"Average score of student with name %s is %d\ \",ptr->name,(ptr->score1 + ptr->score2 + ptr->score3 + ptr->score4 + ptr->score5)/5);

ptr = ptr->next;

//ptr = ptr_next;

}

printf(\"\ -------Printing list End------- \ \");

}

int main(void)

{

int i = 0, ret = 0;

struct student *ptr = NULL;

add_to_list(\"name1\", 51, 1, 2, 3, 4, 5);

add_to_list(\"name2\", 52, 6, 7, 8, 9, 10);

add_to_list(\"name3\", 53, 11, 12, 13, 14, 15);

add_to_list(\"name4\", 54, 21, 22, 23, 24, 25);

add_to_list(\"name5\", 55, 31, 32, 33, 34, 35);

printAverage();

ret = delete_list();

if(ret != 0)

{

printf(\"\ delete failed\ \");

}

else

{

printf(\"\ delete passed \ \");

}

return 0;

}

Problem-1: Data Structures Create a vector of structs that represents a database in which a professor might store information pertaining to his/her class. Every
Problem-1: Data Structures Create a vector of structs that represents a database in which a professor might store information pertaining to his/her class. Every
Problem-1: Data Structures Create a vector of structs that represents a database in which a professor might store information pertaining to his/her class. Every

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site