Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Description: The purpose of this assignment is to provide practice programming using structs and pointers in C language. Your program will accept user input and

Description:

The purpose of this assignment is to provide practice programming using structs and pointers in C language. Your program will accept user input and store it in a dynamic array of structs. First, you will define a structure to describe a student. Your program will prompt the user for the initial size of the array. It will then allocate memory from the heap for an array called StudentArray. Once this is done, your program will allow the user to enter data for as many students as s/he wishes. If the user wishes to add more students than the initial size of the array will allow, you will use calls to malloc() and memcpy() to increase the size of the array so that the user can continue to add more students. See the instructions below for specific details.

Specifications:

Define a struct appropriate for holding student information. At minimum, this should include a Student ID Number (an integer), Last Name (a string containing no more than 20 characters), a First Name (a string containing no more than 20 characters) and a GPA (a floating point value). Ask the user for the number of students, and use this number as the initial size of your StudentArray. (Hint: for easier testing, use a small number, such as two or three.) Allocate an appropriate amount of memory from the heap to create a dynamic array (named StudentArray) of Student structs, large enough to hold the number of students entered by the user.

Provide a menu that allows the user to choose among the following options:

Add a student to StudentArray - This will prompt the user to enter information about the student (ID Number, Last Name, First Name, GPA), and save this in the next uninitialized element in StudentArray.

Print the current list of students - This will print all elements of each initialized Student struct)

Quit the program

Create a void function called "ResizeArray" to be used whenever the number of students to be added to StudentArray would exceed the current bounds of the array. ResizeArray() should have the following parameters:

The address of the pointer to the first element of the StudentArray

The address of the current number of elements in the StudentArray

Each call to ResizeArray should double the size of the existing StudentArray, and change the current number of elements. The user should not be aware that the size of the array is changing. Rather, s/he should simply be allowed to keep adding students until s/he is done, and ResizeArray should be called (transparently to the user) whenever the number of students to be added would exceed the bounds of the array so that the user may add as many students as s/he likes. If by any chance all heap memory is exhausted, an appropriate error message should be issued to the user, and the program will exit. Make sure you test your function by adding more students than originally requested at the start of your program.

Other Specifications:

You may NOT use realloc() for this assignment.

With the exception of those specifically disallowed, use whatever functions, parameters and return statements you wish to organize your code and ensure that it works correctly.

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

Step: 3

blur-text-image

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

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

Explain the various methods of job evaluation

Answered: 1 week ago

Question

Differentiate Personnel Management and Human Resource Management

Answered: 1 week ago

Question

Describe the functions of Human resource management

Answered: 1 week ago

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago