Write a menu based program to maintain student records. Your program should take
ID: 3721744 • Letter: W
Question
Write a menu based program to maintain student records. Your program should take the following inputs: 1. Student ID (any value between 1000 to 1100) – NO DUPLICATES 2. Student first name (max. 20 characters) 3. Student last name, (max. 20 characters) 4. Student scores (float/double), eg. 85.4 5. Zip code (may be a string) You have to create a structure Student with above information. Then create a Binary Search Tree where each node in the BST contains a Student. Note1: Student ID (left child) < Student ID (parent) < Student ID (right) Your program should be able to take records of a minimum of 5 students. After taking the records, you should provide 7 functionalities to the user. 1. Print records – prints records of all students. 2. Add a new record-take a new record from the user for a new student. Create a node for the new student and add it to the BST (Student ID value must satisfy the BST property as provided in Note1). 3. Delete record(s) – to delete a record, ask for the last name of the student from the user. If there are multiple students with same last name, you must delete all of their records (you have to delete corresponding nodes and adjust the BST accordingly). 4. Search by Zip code – prints records of all students with a given zip code. 5. Search by score range – take two scores max, min; and then print records of all students who have scores between [max, min] (inclusive). 6. Find the median score – compute the median score and print it. Also, print how many students are above this median score (do not forget to sort the values in the nodes to compute median). 7. Exit the program – terminate on a specific input from the user. Let that specific input be an integer of value 0.
I would like to see what y'all do for this to compare to mine, but I am especially having trouble with the delete function.
Explanation / Answer
//Student Records
#include<stdio.h>
#include<stdlib.h>
//Structure for Student
typedef struct
{
int sid;
char fName[20];
char lName[20];
float score;
char zipcode[6];
}Student;
//Structure for Node
typedef struct node *nd;
struct node
{
Student stu;
nd left;
nd right;
}Node;
//Pre declaration of Functions
void inputStud(nd *);
bool treeEmpty(nd *);
void deleteNode(nd *);
void editStud(nd *);
void viewAll(nd);
//nd searchNode(nd *,nd *,char[]);
void search1(nd *,char[]);
//Main Function
void main()
{
int choice,c;
bool e;
nd root = NULL;
do
{
clrscr();
printf("1. Add New Student Record ");
printf("2. Edit Student Record ");
printf("3. View Specific Record ");
printf("4. Display All ");
printf("5. Delete Student Record ");
printf("6. Exit ");
printf("Pick your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: inputStud(&root);
break;
case 2: editStud(&root);
break;
case 3: viewAll(root);
getch();
break;
case 4: viewAll(root);
getch();
break;
case 5: deleteNode(&root);
break;
case 6: printf(" You select to exit from the program.");
exit(0);
default : printf("Please select a valid option");
}
}while (choice != 6);
}
//Insert Student Record
void inputStudent(nd *root)
{
nd t, t1, temp;
int id;
char lname[20];
char fname[20];
float sc;
char zc[6];
STUD st;
printf("Enter Student ID: /n");
scanf("%d",&id);
printf("Enter Student's Last Name: /n");
gets(lname);
printf("Enter Student's First Name: /n");
gets(fname);
printf("Enter Student's Zip Code: /n");
gets(zc);
printf("Enter Student's QPA: /n");
scanf("%f", &sc);
st.sid = id;
strcpy(st.lName, lname);
strcpy(st.fName, fname);
strcpy(st.zipcode, zc);
st.score=sc;
temp = malloc(sizeof(NODE));
temp -> stu = st;
temp -> left = NULL;
temp -> right = NULL;
if (*root == NULL)
{
*root = temp;
}
else
{
t = *root;
while (t != NULL)
{
t1 = t;
if (strcmp(temp -> stu.sid,t -> stu.sid)==0)
t = t -> left;
else
t = t -> right;
}
if (strcmp(temp -> stu.sid,t1 -> stu.sid) < 0)
t1 -> left = temp;
else
t1 -> right = temp;
}
t1 = NULL;
t = NULL;
temp = NULL;
return;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.