Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


Assignment 2 Self-referential structures, structures, pointer arrays

In this assignment you are going to implement a customized data structure and then implement a self- referential data structure.

Question 1 pointer arrays, structures in C (80 pts)

Subject: Structures, array of pointer to structures. The purpose of this exercise is to help you get         better understanding of some fundamental concepts in C that we covered after midterm. These include array of pointers, structures, pointer to structures, dynamic memory allocation, formatted IO.

Specification:  in this exercise you are going to develop a simple database management system for a fitness club.

The system maintains records for members of a fitness club.  Each record contains name, age,       height, and current Body Mass Index (BMI), and the weight group (e.g., underweight, normal,       overweight) based on BMI.  If a member’s weight info has been updated, then a history of weight groups is maintained.

Body mass index, or BMI, is a number based on a person’s weight and height. It is a way to help  figure out if a person is at a healthy weight for his/her height. In general, the higher the number, the more body fat a person has. BMI is often used as a screening tool to decide if a person’s         weight might be putting him/her at risk for health problems.

Download file a2DB.c to start off.   Study the provided codes.

The database maintains a collection of member records. Each member record is naturally implemented as a structure, and contains the following information fields:

•    name of type  char [], which represents the patient’s name

•    int age, which represents the patient’s age

•    int height, which represents the member’s height (in cm)

•    float BMI, which represents the member’s Body mass index (BMI)

•    status of type  char [], which represents the member’s weight group bases on BMI.

Programmatically, the database maintains an array of pointers to record structs, as shown in the Figure below.

Figure 1 Main database: Array of pointers to record (structure)

The program will provide several basic functionalities:

•    Accepting entry of a new member record into the current database, and generating weight group information for the member.

•    Displaying all records in the current database

•    Removing an existing member’s record in the current database

•    Updating weight info of an existing member, and generating new weight group for the member

•    Sorting the records in the current database

•    Clearing the current database

Specifically, the program keeps on prompting the user with the following menu, until q or Q is chosen, which terminates the program.

The program should fulfill the following functionalities (some have been implemented for you):

•    Keeps on prompting and responding to user inputs. Valid input includes N/n, D/d,   U/u,

C/c, R/r, S/s and Q/q. Displays error messages for other inputs as shown below.

(This has been implemented for you.)

red 325 % gcc a2DB.c

red 326 % a.out

(N)ew record (S)ort database (Q)uit

(R)emove record (C)lear database *Case Insensitive*

(U)pdate record (D)isplay database

choose one: x

not a valid input !

(N)ew record (S)ort database (Q)uit

(R)emove record (C)lear database *Case Insensitive*

(U)pdate record (D)isplay database

choose one: sort

not a valid input!

(N)ew record (S)ort database (Q)uit

(R)emove record (C)lear database *Case Insensitive*

(U)pdate record (D)isplay database

choose one:

•    When the users enters n or N, which represents New record, the program further prompts the user to enter a new member record into the database. The function reads in member’s name,    age, height (in cm) and weight (in kg). It then calculates BMI and the corresponding weight          group for the new member. The function then creates a new member record and inserts the       new record into the database (i.e., the pointer array).

The BMI is calculated with formula BMI = kg/m2 where kg is a person’s weight in kilograms and m2 is the person‘s height in meters squared.

The weight group is categorized as follows:

BMI

< 18.5

18.5 - 24.999

25.0 – 29.999

30.0 – 34.999

35.0 – 39.999

≥40.0

Weight group

Underweight

Normal weight

Overweight

Obese class I

Obese class II

Obese class III

•    When the user enters d or D, displays the current database of (all) patient records.

•    When the user enters c or C, clear the current database (partially implemented).

Sample inputs/outputs involving n/N and d/D and   c/C are shown below.

|    (N)ew record

(R)emove record

(U)pdate record |

|    (S)ort database

(C)lear database

(D)isplay

database |

|

(Q)uit

*Case Insensitive*

|

choose one: d

===============================

========== 0 records ==========

|    (N)ew record

(R)emove record

(U)pdate record |

|    (S)ort database

(C)lear database

(D)isplay database |

|

(Q)uit

*Case Insensitive*

|

choose one: n

name: Judy Sue

age: 30

height (cm): 162

weight (kg): 56

|    (N)ew record

(R)emove record

(U)pdate record |

(S)ort database

(C)lear database

(D)isplay database

(Q)uit

*Case Insensitive*

choose one: d

===============================

name:   Judy Sue

age:    30


height: 162

BMI:    21.3

status: Normal

========== 1 records ==========