Middleterm-exam - Cấu trúc dữ liệu và giải thuật | Trường Đại học Bách khoa Hà Nội

  1. Enter a new profile of student (ID, name, scores of Math, Physics, Chemistry) and add this new profile to the end of the link list, then print all profile as the same format as part 1. Re-enter profile if the student ID exists. Tài liệu được sưu tầm, giúp bạn ôn tập và đạt kết quả cao. Mời bạn đọc đón xem!
Midterm Exam
Data Structure and Algorithm – Basic Lab
(150 minutes)
I/ Problem
A student database is stored in a text file as follows:
File content Meaning
3
HS001
Nguyen Van A
8 7 9
HS002
Tran Van B
6 6 8
….
Number of students
Student ID
Student name
Math, physics, chemistry scores
Lets write a C program to do the following tasks:
1. (2p) Enter database filename, read its content, and store the student profile in a
single link list, then print the result as follows:
ID Name Math Physics Chemistry
-----------------------------------------------------
HS001 Nguyen Van A 8 7 9
HS002 Tran Van B 6 6 8
-----------------------------------------------------
2. (2p) Enter a new profile of student (ID, name, scores of Math, Physics,
Chemistry) and add this new profile to the end of the link list, then print all profile
as the same format as part 1. Re-enter profile if the student ID exists.
3. (2đ) Enter a student ID, remove the corresponding profile from the list and print
all profiles. Re-enter if there is no such id in the list.
4. (2đ) Enter two student ids, swap their positions in the list then print all profiles.
Re-enter if one of the two ids is not in the list.
5. (2đ) Enter a number n, find students who have total score greater or equal n, print
all profile of those students.
Requirements:
(1) Using the following data structure for storing student profile in the link list:
struct StudentNode {
char id[10];
char name[50];
double toan, ly, hoa;
struct StudentNode *next;
};
typedef struct StudentNode *StudentDB;
(2) Write whole program in a single file, name it with your name and id as the following
example:
Name Nguyen Huu Duc
Student ID: 123456
ducnh_123456.c
The program would be implementing the following functions:
/* Read from file */
StudentDB read_db(char *filename);
/* Make a new node */
struct StudentNode* make_node(char *id, char *name, double toan, double
ly, double hoa);
/* Append a new node to the end of the list */
StudentDB append_std(StudentDB db, struct StudentNode *st);
/* Find a node by ID */
struct StudentNode *find_by_id(studentDB db, char *id);
/* Remove a node */
StudentDB remove_std(StudentDB db, char *id);
/* Swap two nodes */
StudentDB swap_std(StudentDB db, struct StudentNode *b1, struct
StudentNode *b2);
/* Print a student profile */
void print_std(struct StudentNode *s);
/* Print all profiles */
void print_db(StudentDB db);
II/ Process
8.30 Introduce the examination
8.45 Start the examination
11.15 End of the examination.
All students should upload their code to Files/MidtermExam.
NO EARLY UPLOAD ALLOWED!!!!
11.20 Teacher downloads all codes from Files/MidtermExam
Late upload codes are not accepted.
Teacher will evaluate codes by compiling (no extra libraries) and then run
with several test cases. Score will be given corresponding to the correct
ones.
Results will be announced to Teams after few days.
| 1/3

Preview text:

Midterm Exam
Data Structure and Algorithm – Basic Lab (150 minutes) I/ Problem
A student database is stored in a text file as follows: File content Meaning 3 Number of students HS001 Student ID Nguyen Van A Student name 8 7 9
Math, physics, chemistry scores HS002 Tran Van B 6 6 8 ….
Lets write a C program to do the following tasks:
1. (2p) Enter database filename, read its content, and store the student profile in a
single link list, then print the result as follows: ID Name Math Physics Chemistry
----------------------------------------------------- HS001 Nguyen Van A 8 7 9 HS002 Tran Van B 6 6 8
-----------------------------------------------------
2. (2p) Enter a new profile of student (ID, name, scores of Math, Physics,
Chemistry) and add this new profile to the end of the link list, then print all profile
as the same format as part 1. Re-enter profile if the student ID exists.
3. (2đ) Enter a student ID, remove the corresponding profile from the list and print
all profiles. Re-enter if there is no such id in the list.
4. (2đ) Enter two student ids, swap their positions in the list then print all profiles.
Re-enter if one of the two ids is not in the list.
5. (2đ) Enter a number n, find students who have total score greater or equal n, print all profile of those students. Requirements:
(1) Using the following data structure for storing student profile in the link list: struct StudentNode { char id[10]; char name[50]; double toan, ly, hoa; struct StudentNode *next; };
typedef struct StudentNode *StudentDB;
(2) Write whole program in a single file, name it with your name and id as the following example: Name Nguyen Huu Duc Student ID: 123456  ducnh_123456.c
The program would be implementing the following functions: /* Read from file */
StudentDB read_db(char *filename); /* Make a new node */
struct StudentNode* make_node(char *id, char *name, double toan, double ly, double hoa);
/* Append a new node to the end of the list */
StudentDB append_std(StudentDB db, struct StudentNode *st); /* Find a node by ID */
struct StudentNode *find_by_id(studentDB db, char *id); /* Remove a node */
StudentDB remove_std(StudentDB db, char *id); /* Swap two nodes */
StudentDB swap_std(StudentDB db, struct StudentNode *b1, struct StudentNode *b2); /* Print a student profile */
void print_std(struct StudentNode *s); /* Print all profiles */ void print_db(StudentDB db); II/ Process 8.30 Introduce the examination 8.45 Start the examination 11.15 End of the examination.
All students should upload their code to Files/MidtermExam. NO EARLY UPLOAD ALLOWED!!!! 11.20
Teacher downloads all codes from Files/MidtermExam
Late upload codes are not accepted.
Teacher will evaluate codes by compiling (no extra libraries) and then run
with several test cases. Score will be given corresponding to the correct ones.
Results will be announced to Teams after few days.