/* TCP1231 - Computer Programing I Project * Program: Finding student's detail & database * Written by: ===================================================================== NAME ID TUTORIAL SESSION ===================================================================== 1) Low Chee Tat 1001150277 TTM116 2) Lim Chin Fei 1001122952 TTM116 3) Low Suet Cheng 1001120877 TTM116 4) Ng Siaw Yen 1001157775 TTM116 5) Eileen Hang Chiew Mei 1001133187 TTM119 ===================================================================== */ #include #include #include #include #include struct Date{ int day; int month; int year; }; typedef struct{ char name[30]; char id[11]; struct Date dob; char gender[7]; char subcode1[8]; char subcode2[8]; char subcode3[8]; }STUDENTS; STUDENTS students[40]; FILE *file1; void intro(); void prog1(); void prog2(); void prog3(); void prog4(); void prog5(); void no_data(); void file_error(); void print_names(); void invalid_data(); void date_sorting(); void print_details(); void calc_date(int, char); int a,b,i,j; void intro() { printf(" ...WELCOME TO THIS PROGRAM... \n" " THIS PROGRAM WILL HELP YOU TO FIND OUT A STUDENT'S DETAILS EASILY\n" " \n" " THIS PROGRAM IS REGISTERED TO: \n" " POLYNOMIAL TECHNOLOGIES LTD. \n" " \n" " ...ENJOY YOURSELF WHILE USING THIS PROGRAM... "); delay(10000); clrscr(); delay(500); printf(" " " " " " " " " " " " " " " " " " " " " " " " " " " " " L "); delay(500); printf(" O "); delay(500); printf(" A "); delay(500); printf(" D "); delay(500); printf(" I "); delay(500); printf(" N "); delay(500); printf(" G "); for(i=0;i<5;i++) { delay(500); printf("."); } clrscr(); } void main() { int prog; clrscr(); intro(); start: textcolor(YELLOW); cprintf("\nμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμ\r\n"); printf(" 1. Retrieves student's details based on ID or name.\n" " 2. Sorts database based on student's ID/name/age.\n" " 3. Lists student's details based on subject codes.\n" " 4. Shows the most senior or most junior student.\n" " 5. Lists Male or Female students separately.\n" " 6. Exits this program.\n"); cprintf("μμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμμ\r\n"); printf("\n Please choose one of the above options: "); scanf("%1d", &prog); fflush(stdin); switch(prog) { case 1 : prog1(); break; case 2 : prog2(); break; case 3 : prog3(); break; case 4 : prog4(); break; case 5 : prog5(); break; case 6 : goto end; default: invalid_data(); goto start; } goto start; end: textcolor(WHITE); cprintf("\n\nThank you for using this program!\r"); cprintf("\nFor more information, please visit "); textcolor(LIGHTBLUE); cprintf("http://www.polynomial-technologies.com \n\r"); textcolor(WHITE); cprintf("Have a nice day! ^_^\n"); getchar(); } /*main*/ void file_error() { printf("SORRY! The file is not found.\n"); printf("Please press any key to return."); getchar(); exit(1); } /*file_error*/ void no_data() { printf("\nData not found!\n"); printf("Please press ENTER to continue..."); i=41; getchar(); } /*no_data*/ void invalid_data() { printf("\nYou have entered an invalid data. Please try again...\n"); } /*invalid_data*/ void print_details() { printf("\n\tName : %s",students[i].name); printf("\n\tID : %s",students[i].id); printf("\n\tDate of Birth : %02d/%02d/%04d",students[i].dob.day,students[i].dob.month,students[i].dob.year); printf("\n\tGender : %s",students[i].gender); printf("\n\tSubject 1 : %s",students[i].subcode1); printf("\n\tSubject 2 : %s",students[i].subcode2); printf("\n\tSubject 3 : %s",students[i].subcode3); } /*print_details*/ void print_names() { printf("\t%s\t\t%s",students[i].name,students[i].id); } /*print_names*/ void calc_date(int i,char *complete_date) { int day,month,year; day = students[i].dob.day; month = students[i].dob.month; year = students[i].dob.year; sprintf(complete_date,"04d/%02d/%02d",year,month,day); } /*calc_date*/ void date_sorting() { STUDENTS temp; char complete_date1[11]; char complete_date2[11]; for(i=40;--i>-1;) { for(j=0;j0) { temp = students[j]; students[j] = students[j+1]; students[j+1] = temp; } /*if*/ } /*for*/ } /*for*/ } /*date_sorting*/ void prog1() { start1: clrscr(); char std_id[20]; char std_name[25]; file1 = fopen("database.dat","r"); if (file1 == NULL) { file_error(); } /*if*/ else { printf("\nPlease choose to search for students based on their:\n\n"); printf("\t1. Student ID or \n\t2. Student name.\n\n\t"); scanf("%d",&a); switch (a) { case 1: printf("\nPlease enter the student's ID: "); scanf("%s",&std_id); fflush(stdin); for(i=0;i<40;i++) { fscanf(file1,"%[^\n]s",&students[i].name); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].id); fscanf(file1,"\n"); fscanf(file1,"%d",&students[i].dob.day); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.month); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.year); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].gender); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode1); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode2); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode3); fscanf(file1,"\n"); if(strcmp(std_id,students[i].id)==0) { printf("\n\n\tBelow are the details of the student:\n"); print_details(); getchar(); i=41; } /*if*/ else if(i==39) { no_data(); } /*else*/ } /*for*/ break; case 2: printf("\nPlease enter the student's name (Case sensitive): "); fflush(stdin); gets(std_name); printf("\n"); fflush(stdin); for(i=0;i<40;i++) { fscanf(file1,"%[^\n]s",&students[i].name); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].id); fscanf(file1,"\n"); fscanf(file1,"%d",&students[i].dob.day); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.month); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.year); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].gender); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode1); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode2); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode3); fscanf(file1,"\n"); if(strcmp(std_name,students[i].name)==0) { printf("\n\n\tBelow are the details of the student:\n"); print_details(); getchar(); i = 41; } /*if*/ else if(i==39) { no_data(); } /*else*/ } /*for*/ break; default: invalid_data(); goto start1; } /*switch*/ decision1: printf("\n\nDo you want to:\n"); printf("1. Continue using program 1.\n"); printf("2. Return to main menu.\n\n"); scanf("%1d", &b); printf("\n"); fflush(stdin); if (b == 1) goto start1; else if (b == 2) goto end1; else if (b != 1 || b != 2) { invalid_data(); goto decision1; } /*else if*/ } /*else*/ end1: fclose(file1); } /*prog1*/ void prog2() { start2: clrscr(); void ascending(); void descending(); printf("\n\nPlease choose to sort the database:\n\n"); printf("\t1. In ascending order.\n"); printf("\t2. In descending order.\n\n\t"); scanf("%1d", &a); fflush(stdin); switch (a) { case 1 : ascending() ; break; case 2 : descending(); break; default: invalid_data(); goto start2; } /*switch*/ decision2: printf("\n\nDo you want to:\n"); printf("1. Continue using program 2.\n"); printf("2. Return to main menu.\n\n"); scanf("%1d", &b); printf("\n"); fflush(stdin); if (b == 1) goto start2; else if (b == 2) printf(" "); else if (b != 1 || b != 2) { invalid_data(); goto decision2; } /*else if*/ } /*prog2*/ void ascending() { start_ascending: clrscr(); char complete_date1[11]; char complete_date2[11]; STUDENTS temp; file1 = fopen("database.dat","r"); if (file1 == NULL) { file_error(); } /*if*/ for(i=0;i<40;i++) { fscanf(file1,"%[^\n]s",&students[i].name); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].id); fscanf(file1,"\n"); fscanf(file1,"%d",&students[i].dob.day); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.month); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.year); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].gender); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode1); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode2); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode3); fscanf(file1,"\n"); } /*for*/ printf("\nPlease choose any field u'd like to sort from:\n\n"); printf("\t1) Student ID\n\t2) Student name\n\t3) Student age\n\n\t"); scanf("%1d",&a); fflush(stdin); printf("\nBelow are the details of the students:\n"); switch(a) { case 1: for(i=40;--i>-1;) { for(j=0;j-1;) { for(j=0;j-1;) { for(j=0;j-1;) { for(j=0;j0) { temp = students[j]; students[j] = students[j+1]; students[j+1] = temp; } /*if*/ } /*for*/ textcolor(CYAN); cprintf("\r------------------------------------------------\r"); print_details(); cprintf("\n\r------------------------------------------------\r"); getchar(); } /*for*/ break; case 2: for(i=40;--i>-1;) { for(j=0;j0) { temp = students[j]; students[j] = students[j+1]; students[j+1] = temp; } /*if*/ } /*for*/ textcolor(CYAN); cprintf("\r------------------------------------------------\r"); print_details(); cprintf("\n\r------------------------------------------------\r"); getchar(); } /*for*/ break; case 3: for(i=40;--i>-1;) { for(j=0;j0) { temp = students[j]; students[j] = students[j+1]; students[j+1] = temp; } /*if*/ } /*for*/ textcolor(CYAN); cprintf("\r------------------------------------------------\r"); print_details(); cprintf("\n\r------------------------------------------------\r"); getchar(); } /*for*/ break; default: invalid_data(); goto start_descending; } /*switch*/ decision_descending: printf("\n\nDo you want to:\n"); printf("1. Continue to sort the database in descending order.\n"); printf("2. Return to program 2.\n\n"); scanf("%1d", &b); fflush(stdin); if (b==1) goto start_descending; else if (b==2) fclose(file1); else if (b!=1 || b!=2) { invalid_data(); goto decision_descending; } /*else if*/ } /*descending*/ void prog3() { start3: int dec; clrscr(); void names(); void details(); printf("\n\tPlease choose to display:\n\n"); printf("\t1. The names and ID of the students only.\n"); printf("\t2. The full details of the students.\n\n\t"); scanf("%1d", &dec); fflush(stdin); switch (dec) { case 1 : names(); break; case 2 : details(); break; default: invalid_data(); goto start3; } /*switch*/ decision3: printf("\n\nDo you want to:\n"); printf("1. Continue using program 3.\n"); printf("2. Return to main menu.\n\n"); scanf("%1d", &b); fflush(stdin); if (b == 1) goto start3; else if (b == 2) printf(" "); else if (b != 1 || b != 2) { invalid_data(); goto decision3; } /*else if*/ } /*prog3*/ void names() { start_names: file1 = fopen("database.dat","r"); if (file1 == NULL) { file_error(); } /*if*/ else { printf("\nPlease choose one of these subject codes to list out "); printf("the names of \nthe students who have been offered the course.\n\n"); printf("\t1. TCP1231\n"); printf("\t2. TCE1111\n"); printf("\t3. TMG1111\n"); printf("\t4. TMT1111\n"); printf("\t5. TMT1171\n"); printf("\t6. PES1011\n\n\t"); scanf("%d",&a); fflush(stdin); printf("\n\nBelow are the students who have been offered the course:\n\n"); textcolor(YELLOW); cprintf("\r---------------------------------------------------\n\r"); printf("\tName\t\t\t ID\n"); cprintf("---------------------------------------------------\n\r"); switch (a) { case 1: for(i=0;i<40;i++) { fscanf(file1,"%[^\n]s",&students[i].name); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].id); fscanf(file1,"\n"); fscanf(file1,"%d",&students[i].dob.day); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.month); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.year); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].gender); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode1); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode2); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode3); fscanf(file1,"\n"); if((strcmp(students[i].subcode1,"TCP1231")==0) || (strcmp(students[i].subcode2,"TCP1231")==0) || (strcmp(students[i].subcode3,"TCP1231")==0)) { print_names(); getchar(); } /*if*/ } /*for*/ break; case 2: for(i=0;i<40;i++) { fscanf(file1,"%[^\n]s",&students[i].name); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].id); fscanf(file1,"\n"); fscanf(file1,"%d",&students[i].dob.day); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.month); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.year); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].gender); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode1); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode2); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode3); fscanf(file1,"\n"); if((strcmp(students[i].subcode1,"TCE1111")==0) || (strcmp(students[i].subcode2,"TCE1111")==0) || (strcmp(students[i].subcode3,"TCE1111")==0)) { print_names(); getchar(); } /*if*/ } /*for*/ break; case 3: for(i=0;i<40;i++) { fscanf(file1,"%[^\n]s",&students[i].name); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].id); fscanf(file1,"\n"); fscanf(file1,"%d",&students[i].dob.day); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.month); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.year); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].gender); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode1); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode2); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode3); fscanf(file1,"\n"); if((strcmp(students[i].subcode1,"TMG1111")==0) || (strcmp(students[i].subcode2,"TMG1111")==0) || (strcmp(students[i].subcode3,"TMG1111")==0)) { print_names(); getchar(); } /*if*/ } /*for*/ break; case 4: for(i=0;i<40;i++) { fscanf(file1,"%[^\n]s",&students[i].name); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].id); fscanf(file1,"\n"); fscanf(file1,"%d",&students[i].dob.day); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.month); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.year); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].gender); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode1); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode2); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode3); fscanf(file1,"\n"); if((strcmp(students[i].subcode1,"TMT1111")==0) || (strcmp(students[i].subcode2,"TMT1111")==0) || (strcmp(students[i].subcode3,"TMT1111")==0)) { print_names(); getchar(); } /*if*/ } /*for*/ break; case 5: for(i=0;i<40;i++) { fscanf(file1,"%[^\n]s",&students[i].name); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].id); fscanf(file1,"\n"); fscanf(file1,"%d",&students[i].dob.day); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.month); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.year); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].gender); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode1); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode2); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode3); fscanf(file1,"\n"); if((strcmp(students[i].subcode1,"TMT1171")==0) || (strcmp(students[i].subcode2,"TMT1171")==0) || (strcmp(students[i].subcode3,"TMT1171")==0)) { print_names(); getchar(); } /*if*/ } /*for*/ break; case 6: for(i=0;i<40;i++) { fscanf(file1,"%[^\n]s",&students[i].name); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].id); fscanf(file1,"\n"); fscanf(file1,"%d",&students[i].dob.day); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.month); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.year); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].gender); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode1); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode2); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode3); fscanf(file1,"\n"); if((strcmp(students[i].subcode1,"PES1011")==0) || (strcmp(students[i].subcode2,"PES1011")==0) || (strcmp(students[i].subcode3,"PES1011")==0)) { print_names(); getchar(); } /*if*/ } /*for*/ break; default: invalid_data(); goto start_names; } /*switch*/ decision_names: printf("\n\nDo you want to:\n"); printf("1. Continue to list down the names of the students that were \n"); printf(" offered a particular course.\n"); printf("2. Return to program 3.\n\n"); scanf("%1d", &b); fflush(stdin); if (b==1) goto start_names; else if (b==2) fclose(file1); else if (b!=1 || b!=2) { invalid_data(); goto decision_names; } /*else if*/ } /*else*/ } /*names*/ void details() { start_details: file1 = fopen("database.dat","r"); if (file1 == NULL) { file_error(); } /*if*/ else { printf("\nPlease choose one of these subject codes to list out "); printf("the details of \nthe students who have been offered the course.\n\n"); printf("\t1. TCP1231\n"); printf("\t2. TCE1111\n"); printf("\t3. TMG1111\n"); printf("\t4. TMT1111\n"); printf("\t5. TMT1171\n"); printf("\t6. PES1011\n\n\t"); scanf("%d",&a); fflush(stdin); printf("\n\n\tBelow are details of the students:\n"); switch (a) { case 1: for(i=0;i<40;i++) { fscanf(file1,"%[^\n]s",&students[i].name); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].id); fscanf(file1,"\n"); fscanf(file1,"%d",&students[i].dob.day); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.month); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.year); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].gender); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode1); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode2); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode3); fscanf(file1,"\n"); if((strcmp(students[i].subcode1,"TCP1231")==0) || (strcmp(students[i].subcode2,"TCP1231")==0) || (strcmp(students[i].subcode3,"TCP1231")==0)) { textcolor(CYAN); cprintf("\r------------------------------------------------\r"); print_details(); cprintf("\n\r------------------------------------------------\r"); getchar(); } /*if*/ } /*for*/ break; case 2: for(i=0;i<40;i++) { fscanf(file1,"%[^\n]s",&students[i].name); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].id); fscanf(file1,"\n"); fscanf(file1,"%d",&students[i].dob.day); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.month); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.year); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].gender); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode1); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode2); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode3); fscanf(file1,"\n"); if((strcmp(students[i].subcode1,"TCE1111")==0) || (strcmp(students[i].subcode2,"TCE1111")==0) || (strcmp(students[i].subcode3,"TCE1111")==0)) { textcolor(CYAN); cprintf("\r------------------------------------------------\r"); print_details(); cprintf("\n\r------------------------------------------------\r"); getchar(); } /*if*/ } /*for*/ break; case 3: for(i=0;i<40;i++) { fscanf(file1,"%[^\n]s",&students[i].name); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].id); fscanf(file1,"\n"); fscanf(file1,"%d",&students[i].dob.day); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.month); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.year); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].gender); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode1); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode2); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode3); fscanf(file1,"\n"); if((strcmp(students[i].subcode1,"TMG1111")==0) || (strcmp(students[i].subcode2,"TMG1111")==0) || (strcmp(students[i].subcode3,"TMG1111")==0)) { textcolor(CYAN); cprintf("\r------------------------------------------------\r"); print_details(); cprintf("\n\r------------------------------------------------\r"); getchar(); } /*if*/ } /*for*/ break; case 4: for(i=0;i<40;i++) { fscanf(file1,"%[^\n]s",&students[i].name); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].id); fscanf(file1,"\n"); fscanf(file1,"%d",&students[i].dob.day); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.month); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.year); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].gender); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode1); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode2); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode3); fscanf(file1,"\n"); if((strcmp(students[i].subcode1,"TMT1111")==0) || (strcmp(students[i].subcode2,"TMT1111")==0) || (strcmp(students[i].subcode3,"TMT1111")==0)) { textcolor(CYAN); cprintf("\r------------------------------------------------\r"); print_details(); cprintf("\n\r------------------------------------------------\r"); getchar(); } /*if*/ } /*for*/ break; case 5: for(i=0;i<40;i++) { fscanf(file1,"%[^\n]s",&students[i].name); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].id); fscanf(file1,"\n"); fscanf(file1,"%d",&students[i].dob.day); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.month); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.year); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].gender); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode1); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode2); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode3); fscanf(file1,"\n"); if((strcmp(students[i].subcode1,"TMT1171")==0) || (strcmp(students[i].subcode2,"TMT1171")==0) || (strcmp(students[i].subcode3,"TMT1171")==0)) { textcolor(CYAN); cprintf("\r------------------------------------------------\r"); print_details(); cprintf("\n\r------------------------------------------------\r"); getchar(); } /*if*/ } /*for*/ break; case 6: for(i=0;i<40;i++) { fscanf(file1,"%[^\n]s",&students[i].name); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].id); fscanf(file1,"\n"); fscanf(file1,"%d",&students[i].dob.day); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.month); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.year); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].gender); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode1); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode2); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode3); fscanf(file1,"\n"); if((strcmp(students[i].subcode1,"PES1011")==0) || (strcmp(students[i].subcode2,"PES1011")==0) || (strcmp(students[i].subcode3,"PES1011")==0)) { textcolor(CYAN); cprintf("\r------------------------------------------------\r"); print_details(); cprintf("\n\r------------------------------------------------\r"); getchar(); } /*if*/ } /*for*/ break; default: invalid_data(); goto start_details; } /*switch*/ decision_details: printf("\n\nDo you want to:\n"); printf("1. Continue to list down the details of the students that were \n"); printf(" offered a particular course.\n"); printf("2. Return to program 3.\n\n"); scanf("%1d", &b); fflush(stdin); if (b==1) goto start_details; else if (b==2) fclose(file1); else if (b!=1 || b!=2) { invalid_data(); goto decision_details; } /*else if*/ } /*else*/ } /*details*/ void prog4() { start4: clrscr(); file1 = fopen("database.dat","r"); if (file1 == NULL) { file_error(); } /*if*/ else { for(i=0;i<40;i++) { fscanf(file1,"%[^\n]s",&students[i].name); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].id); fscanf(file1,"\n"); fscanf(file1,"%d",&students[i].dob.day); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.month); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.year); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].gender); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode1); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode2); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode3); fscanf(file1,"\n"); } /*for*/ printf("\nPlease select your choice either to display the:\n\n"); printf("\t1. Most senior student.\n\t2. Most junior student.\n\n\t"); scanf("%d",&a); fflush(stdin); switch(a) { case 1: date_sorting(); printf("\nThe most senior student is %s.",students[0].name); getchar(); break; case 2: date_sorting(); printf("\nThe most junior student is %s.",students[39].name); getchar(); break; default : invalid_data(); getchar(); goto start4; }/*switch*/ decision4: printf("\n\nDo you want to:\n"); printf("1. Continue using program 4.\n"); printf("2. Return to main menu.\n\n"); scanf("%1d", &b); fflush(stdin); if (b == 1) goto start4; else if (b == 2) fclose(file1); else if (b != 1 || b != 2) { invalid_data(); goto decision4; } /*else if*/ } /*else*/ } /*prog4*/ void prog5() { start5: clrscr(); void names5(); void details5(); printf("\nPlease choose to display:\n"); printf("1. The names and ID of the students only.\n"); printf("2. The full details of the students.\n\n"); scanf("%1d", &a); fflush(stdin); switch (a) { case 1 : names5(); break; case 2 : details5(); break; default: invalid_data(); goto start5; } /*switch*/ decision5: printf("\n\nDo you want to:\n"); printf("1. Continue using program 5.\n"); printf("2. Return to main menu.\n\n"); scanf("%1d", &b); fflush(stdin); if (b == 1) goto start5; else if (b == 2) printf(" "); else if (b != 1 || b != 2) { printf("\nINVALID INPUT! Please try again..."); goto decision5; } /*else if*/ } /*prog5*/ void names5() { start_names5: file1 = fopen("database.dat","r"); if (file1 == NULL) { file_error(); } /*if*/ else { printf("\nPlease choose to list out Male or Female students:\n"); printf("\n\t1. Male\n\t2. Female\n\n\t"); scanf("%d",&a); fflush(stdin); printf("\n\n\tBelow are the list of students:\n\n"); textcolor(YELLOW); cprintf("---------------------------------------------------\n\r"); printf("\tName\t\t\t ID\n"); cprintf("---------------------------------------------------\n\r"); switch (a) { case 1: for(i=0;i<40;i++) { fscanf(file1,"%[^\n]s",&students[i].name); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].id); fscanf(file1,"\n"); fscanf(file1,"%d",&students[i].dob.day); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.month); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.year); fscanf(file1,"\n"); fscanf(file1,"%[^\n]c",&students[i].gender); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode1); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode2); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode3); fscanf(file1,"\n"); if(strcmp(students[i].gender,"Male")==0) { print_names(); getchar(); } /*if*/ } /*for*/ break; case 2: for(i=0;i<40;i++) { fscanf(file1,"%[^\n]s",&students[i].name); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].id); fscanf(file1,"\n"); fscanf(file1,"%d",&students[i].dob.day); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.month); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.year); fscanf(file1,"\n"); fscanf(file1,"%[^\n]c",&students[i].gender); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode1); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode2); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode3); fscanf(file1,"\n"); if(strcmp(students[i].gender,"Female")==0) { print_names(); getchar(); } /*if*/ } /*for*/ break; default: invalid_data(); goto start_names5; } /*switch*/ decision_names5: printf("\n\nDo you want to:\n"); printf("1. Continue to list down the names of Male and Female students seperately.\n"); printf("2. Return to program 5.\n\n"); scanf("%1d", &b); fflush(stdin); if (b==1) goto start_names5; else if (b==2) fclose(file1); else if (b!=1 || b!=2) { invalid_data(); goto decision_names5; } /*else if*/ } /*else*/ } /*names5*/ void details5() { start_details5: file1 = fopen("database.dat","r"); if (file1 == NULL) { file_error(); } /*if*/ else { printf("\nPlease choose to list out the details of Male or Female students:\n"); printf("\n\t1. Male\n\t2. Female\n\n\t"); scanf("%d",&a); fflush(stdin); printf("\n\nBelow are the details of the students:\n\n"); switch (a) { case 1: for(i=0;i<40;i++) { fscanf(file1,"%[^\n]s",&students[i].name); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].id); fscanf(file1,"\n"); fscanf(file1,"%d",&students[i].dob.day); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.month); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.year); fscanf(file1,"\n"); fscanf(file1,"%[^\n]c",&students[i].gender); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode1); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode2); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode3); fscanf(file1,"\n"); if(strcmp(students[i].gender,"Male")==0) { textcolor(CYAN); cprintf("\r------------------------------------------------\r"); print_details(); cprintf("\n\r------------------------------------------------\r"); getchar(); } /*if*/ } /*for*/ break; case 2: for(i=0;i<40;i++) { fscanf(file1,"%[^\n]s",&students[i].name); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].id); fscanf(file1,"\n"); fscanf(file1,"%d",&students[i].dob.day); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.month); fscanf(file1,"/"); fscanf(file1,"%d",&students[i].dob.year); fscanf(file1,"\n"); fscanf(file1,"%[^\n]c",&students[i].gender); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode1); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode2); fscanf(file1,"\n"); fscanf(file1,"%[^\n]s",&students[i].subcode3); fscanf(file1,"\n"); if(strcmp(students[i].gender,"Female")==0) { textcolor(CYAN); cprintf("\r---------------------------------------------\r"); print_details(); cprintf("\n\r---------------------------------------------\r"); getchar(); } /*if*/ } /*for*/ break; default: invalid_data(); goto start_details5; } /*switch*/ decision_details5: printf("\n\nDo you want to:\n"); printf("1. Continue to list down the details of Male and Female students seperately.\n"); printf("2. Return to program 5.\n\n"); scanf("%1d", &b); fflush(stdin); if (b==1) goto start_details5; else if (b==2) fclose(file1); else if (b!=1 || b!=2) { invalid_data(); goto decision_details5; } /*else if*/ } /*else*/ } /*details5*/