Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I really need some help ASAP!! please please (C LANGUAGE ONLY!!!) in regards to dynamic memory allocation Problem: A school offers certain number of courses.

I really need some help ASAP!! please please (C LANGUAGE ONLY!!!) in regards to dynamic memory allocation

Problem: A school offers certain number of courses. A course can have one or more sections. A section can have one or more students (assume that a student cannot enroll in multiple sections of the same course). A student has to do a certain number of assignments in the course. In order to pass the course, the average score of the assignment has to be >=70.

2 //# of Test cases to process t<=25)

3 //# of Courses for test case 1 (c<=500) cs1 //name Of Course 1 (CS1), a string, (cn<=20), all lower case, single word 2 //# of Sections for course 1, (s<=10), single (+) int. 3 4 //# of Students (st<=10),# of Assignments (m<=20) 101

john 70 60.5 95.2 50.6 // id lname scores //ID of student:(id<=500,000) (+)integer //Last name of student: (lname<=20) string, Lower Case, single Word //Score of student (m<=100) (+)

float # 102

tyler 80 60.5 95.2 66.6 103

nusair 70 60.5 85.2 50.6 2 3 //no. of students and assignments for sec2 of course 1

(cs1) 105

edward 90.5 60.5 98.2 104 alan 40 60.5 95.2 math2 //name of course 2 3 //number of sections for course 2 (math2) 2 2 //no. of students and assignments for sec1 of course 2 (math2) 101 john 95.2 53.6 103 nusair 86.2 56.6 2 3 //no. of students and assignments for sec2 of course 2 (math2) 105 edward 90.5 60.5 98.2 104 alan 40 60.5 95.2 3 2 //no. of students and assignments for sec3 of course 2 (math2)) 110 kyle 90.5 98.2 108 bob 45 85.2 109 smith 75.5 65.9 physics3 //name of course 3 1 //number of sections of course 3 4 2 //num of students and assignments for sec1 of course3 (physics3) 105 edward 60.5 98.2 104 alan 40.5 95.2 108 bob 55 85.2 109 smith 65.5 68.9 2//num of courses for test case2. The following lines are for test case2 cs1 //name of course 1 2 //number of sections for course 1 (CS1) 2 3 //no. of students and assignments for sec1 of course 1 (cs1) 102 habib 90.5 60.5 98.2 101 mohamed 40 60.5 95.2 4 3 //num of students and assignments for sec2 of course 1 (cs1) 104 manha 85.5 60.5 95.2 102 habib 80 60.5 95.2 103 hussain 70 60.5 85.2 109 ali 78.0 63.5 85.5 physics2 //name of course 2 3 //number of sections for course 2 (physics2) 2 2 //num of students and assignments for sec1 of course 2 (physics2) 101 mohamed 95.2 53.6 103 hussain 86.2 56.6 2 3 //num of students and assignments for sec2 of course 2 (physics2) 105 aziz 90.5 60.5 98.2 104 manha 40 60.5 95.2 3 2 //num of students and assignments for sec3 of course 2 (physics2) 110 ahmed 90.5 98.2 108 hasan 45 85.2 109 nadia 75.5 65.9 Output: //(course_name)(pass_count)(list_of_averages_section, separated by space)(id)(lname)(avg_score, two decimal places) test case 1 cs1 2 70.41 74.15 105 edward 83.07 math2 5 72.90 74.15 76.72 110 kyle 94.35 physics3 2 71.12 105 edward 79.35 test case 2 cs1 5 74.15 76.38 102 habib 83.07 physics2 5 72.90 74.15 76.72 ahmed 94.35 >

Code should implement at least the following functions: a. course *read_courses(FILE *fp, int *num_courses): This function takes a file pointer and reference of an integer to track how may courses the file has. Then it reads the data for an entire test case and return the allocated memory for all the courses (including sections) for a test case. Note that you can call other functions from this function as needed. b. student **read_sections(FILE *fp, int num_students[], int num_scores[], int num_sections): This function takes the file pointer, references of two arrays, one for number of students, and one for number of scores for a course. The function also takes an integer that indicates the number of sections the course has. The function reads all the data for all the sections of a course, fill-up the num_students and num_scores array of the course and returns 2D array of students that contains all the data for all the sections of a course. A good idea would be calling this function from the read_course function. c. void process_courses(course *courses, int num_courses): This function takes the array of courses produced and filled by all the courses of a test case and also takes the size of the array. Then it displays the required data in the same format discussed in the sample output. You can write and use more functions in this process as you wish. d. void release_courses( course *courses, int num_courses): This function takes the array of courses produced and filled by all the courses of a test case and also takes the size of the array. Then it free up all the memory allocated within it. You can create more function as needed to ease the process Structure: typedef struct student{ int id; char *lname; float *scores; //stores scores of the student. Size is taken from num_scores array.float std_avg; //average score of the student (to be calculated) }student; typedef struct course{ char *course_name; int num_sections; student **sections;//stores array of student arrays(2D array). Size is num_sections; int *num_students;//stores array of number of students in each section. Size is num_sections; int *num_scores; //stores array of number of assignments in each section. Size is num_sections; } course;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions

Question

Understand the roles of signs, symbols, and artifacts.

Answered: 1 week ago

Question

Know the three main dimensions of the service environment.

Answered: 1 week ago