This assignment will give you practice with linked lists. You are to write the f
ID: 3664209 • Letter: T
Question
This assignment will give you practice with linked lists. You are to write the functions in the file list.c that allows you to manage the student record. Starter code (list.h, node.h, list.c, main.c) is provided along with this description (You need to create a project). Your program should maintains student academic records using a linked list. The fields of the student_rec structure are as follows: ID (This should be unique) First Name Last Name Address Email Phone_Number GPA The program shall be menu driven. This means that the actions that the user can do with the program is govern by choosing an option. The menu shall look like this: Student Records 1. Add student Academic Record. 2. Edit student first name. 3. Delete student record. 4. View student record (by last name). 5. View all student records. 6. Exit (You have to delete all the records first). For the edit and delete the record of a particular student, you should search for the student based on his/her ID. The main program has been written for you and is called main.c. The main program asks the user to select his/her option from the main menu, which isin the main program. Your main program includes also two header files (node.h, list.h). node.h includes the structure of the student record, while list.h includes the prototypes for all the functions that are called in the main programs (main.c). Your program should keep track of all the students’ records using a linked list. I am requiring you to use my pointer of type struct student_recwhich is called ptr_student defined in node.h. All the functions’ prototypes in list.h should be defined in list.c. You should write these functions’ definitionsin list.c.Note that you can add more functionsin list.c if needed. When your code is in good shape, you can use the main program to compile, run your project and make sure it works properly. In terms of correctness, your program must exhibit the behavior as indicated in commands of list.c and list.h. In terms Of style, I will be grading on your use of comments, good variable names, consistent indentation and good coding style to implement these operations.
Explanation / Answer
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#define M 10
#define FLUSH while(getchar() != ' ')
typedef struct
{
int StudentID[10];
char Fname[50];
char Lname[30];
char midIn[2];
char Course[20];
float QPA [3];
char address[50];
}Student;
void menu(char *);
void addRec(Student stud[], int cnt);
void editIn(Student stud[], int cnt);
void deleteStudRec(Student stud[], int cnt);
void viewIn(Student stud[], int cnt);
void viewAll(Student stud[], int cnt);
void exit1(char *answer);
int main(void)
{
Student stud[M];
char choice;
int cnt=0;
char answer= 'n';
do
{
menu(&choice);
switch(choice)
{
case '1':
system("cls");
if (cnt < M)
{
addRec(stud, cnt);
cnt++;
}
else
printf(" NO MORE SPACE FOR NEW STUDENT RECORD");
break;
case 'a':
case 'A':
system("cls");
editIn(stud, cnt);
break;
case '2':
system("cls");
editIn(stud, cnt);
break;
case '3':
system("cls");
viewIn(stud, cnt);
break;
case '4':
system("cls");
viewAll(stud, cnt);
break;
case '5':
exit1(&answer);
if(answer=='Y' || answer=='y')
;
break;
default:
;
}
} while(answer == 'N' || answer == 'n');
printf(" Thank you.");
getch();
return 0;
}
void menu(char *choice)
{
char ch;
system("cls");
printf(" Student Records");
printf(" 1. Add student personal info and scores");
printf(" a. Edit student first name");
printf(" 2. View student record (by last name)");
printf(" 3. View all student records");
printf(" 4. Exit");
printf(" Choice: ");
scanf("%c", &ch);
*choice=ch;
}
void addRec(Student stud[], int count)
{
printf("ADD STUDENT PERSONAL INFORMATION");
FLUSH;
printf(" Last name: ");
gets(stud[count].Lname);
//FLUSH;
printf("First name: ");
gets(stud[count].Fname);
printf("Middle Initial: ");
gets(stud[count].midIn);
printf("Address: ");
gets(stud[count].address);
getch();
}
void editIn(Student stud[], int count)
{
int i, res;
char ln[20], fn[40];
FLUSH;
printf("EDIT STUDENT PERSONAL INFORMATION");
if(count == 0)
{
printf(" NO RECORDS AVAILABLE");
getch();
}
else
{
printf(" Last Name: ");
gets(ln);
for(i=0; i<count; i++)
{
res= strcmp(ln, stud[i].Lname);
if(res==0)
{
FLUSH;
printf("%s, %s %s ", stud[i].Lname, stud[i].Fname, stud[i].midIn);
printf(" First name: ");
gets(fn);
strcpy(stud[i].Fname, fn);
printf(" Successful. Firstname has been changed to %s", stud[i].Fname);
getch();
break;
}
}
if(res!=0)
{
printf(" RECORD NOT FOUND.");
getch();
}
}
}
void viewIn(Student stud[], int count)
{
int i, res;
char ln[20];
FLUSH;
printf("VIEW STUDENT RECORD");
if(count == 0)
printf(" NO RECORDS AVAILABLE");
else
{
printf(" Last Name: ");
gets(ln);
//FLUSH;
for(i=0; i<count; i++)
{
res= strcmp(ln, stud[i].Lname);
if(res==0)
{
printf(" %s, %s %s", stud[i].Lname, stud[i].Fname, stud[i].midIn);
printf(" Lastname: %s", stud[i].Lname);
printf(" Firstname: %s", stud[i].Fname);
printf(" Middle Initial: %s", stud[i].midIn);
printf(" Address: %s", stud[i].address);
//FLUSH;
}
}
if (res != 0)
printf(" RECORD NOT FOUND.");
}
getch();
}
void viewAll(Student stud[], int count)
{
int i;
printf("VIEW ALL STUDENT RECORDS");
if(count == 0)
printf(" NO RECORDS AVAILABLE");
else
{
for(i=0; i<count; i++)
{
printf(" %s, %s %s %s", stud[i].Lname, stud[i].Fname, stud[i].midIn, stud[i].address);
}
}
getch();
}
void exit1(char *answer)
{
char a;
FLUSH;
printf(" Exit? [Y/N]: ");
scanf("%c", &a);
*answer=a;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.