Question
Write a program called student_class.c that keeps track of students in a class. The program uses the following struct: typedef struct { int studentID; char
Write a program called student_class.c that keeps track of students in a class.
The program uses the following struct:
typedef struct { int studentID; char name[20]; } Student;
To keep track of students in the class, you will create an array of Student structures. This array must be dynamically allocated. Use malloc to initially allocate enough space for 2 students. If a new student needs to be entered into the class (beyond the two initial students), you will need to use realloc to increase the size of the array to accomodate the new student. A class has a maximum of 5 students. The program prompts the user to enter students. If the user does not want to enter more students, they would enter -1 for the student ID.
The following are examples of how the program would behave:
$ ./student_class Enter student 1 ID: 1234
Enter student 1 name: Alice
Enter student 2 ID: -1
Thank you. You have 1 student(s) in the class.
$ ./student_class Enter student 1 ID: 1234
Enter student 1 name: Alice Enter student 2 ID: 345
Enter student 2 name: Bob
Enter student 3 ID: 678
Enter student 3 name: John
Enter student 4 ID: -1
Thank you. You have 3 student(s) in the class.
$ ./student_class Enter student 1 ID: 1234
Enter student 1 name: Alice
Enter student 2 ID: 345
Enter student 2 name: Bob
Enter student 3 ID: 678
Enter student 3 name: John
Enter student 4 ID: 98
Enter student 4 name: Nancy
Enter student 5 ID: 100
Enter student 5 name: Natalie
You have reached the maximum capacity of the class. You currently have 5 registered s tudents.
Your program must not have any memory leaks. You are encouraged to divide up your program into functions for better modularity. You are encouraged to create a header file that contains your function prototypes, as needed
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started