Code:
#include <stdio.h>
#include <string.h>
typedef struct student_profile{
long long int stud_num;
char name[50];
char bday[50];
char course[50];
} STUDENT;
void login(char username[], char password[]);
char admin(void);
void add_student(STUDENT array[20]);
void display_students(STUDENT array[20]);
void modify_student(STUDENT array[20]);
//void delete_student(STUDENT array[20]);
//void delete_all(STUDENT array[20]);
//*******************************************************************
int main(void)
{
STUDENT array[20];
char username[50];
char password[50];
char option;
int i;
for(i = 0; i < 20; i++)
{
array[i].stud_num = 0;
}
clrscr();
while(strcmp(username,"quit") != 0 || strcmp(password,"quit") != 0)
{
login(username, password);
if(strcmp(username, "ADMIN") == 0 && strcmp(password, "admin") == 0)
{
option = '0';
while(option != '7')
{
option = admin();
switch(option)
{
case '1' :
{
gotoxy(14,48); printf("Redirecting to [Add Student] Function --->...");
getche();
add_student(array);
break;
} //end of case '1'
case '2' :
{
gotoxy(14,48); printf("Redirecting to [Modify Student Account] Function --->...");
getche();
modify_student(array);
break;
} //end of case '2'
case '4' :
{
gotoxy(14,48); printf("Redirecting to [Display all Accounts] Function --->...");
getche();
display_students(array);
break;
} //end of case '4'
case '6' :
{
gotoxy(14,50); printf("Logging out...");
getche();
option = '7';
break;
} //end of case '5'
case '7' :
{ gotoxy(14,48); printf("Terminating Program...");
getche();
return 0;
} //end of case '6'
default :
{ printf("\n\nInvalid option");
} //end of default
} //end of switch
} //end of while(option != '6')
} //end of while(strcmp...)
/*else if(ang account kay student)
{
}*/
else
{
if(strcmp(username,"quit") != 0 && strcmp(password,"quit") != 0)
{
gotoxy(19,30); printf("Invalid username or password.");
}
}
} //end of super big loop! XD haha
gotoxy(19,31); printf("Terminating Program...");
getche();
return 0;
}
//*******************************************************************
void login(char username[], char password[])
{
clrscr();
gotoxy(19,5); printf("********* ******** *** *** *********");
gotoxy(19,6); printf("** *** ** *** *** *** ** ***");
gotoxy(19,7); printf("** ** ** *** *** *** ** **");
gotoxy(19,8); printf("*** ** *** **** **** *** ");
gotoxy(19,9); printf("******** ******* ** *** ** ******** ");
gotoxy(19,10); printf(" ******** ** *** ** *** ** ********");
gotoxy(19,11); printf(" *** ** ** ** * ** ***");
gotoxy(19,12); printf("** ** ** ** ** ** ** **");
gotoxy(19,13); printf("*** ** ** ** ** ** *** **");
gotoxy(19,14); printf("********* *** *** **** **** *********");
gotoxy(45,40); printf("Just type 'quit' as username");
gotoxy(45,41); printf("and 'quit' also as password");
gotoxy(45,42); printf("to terminate program.");
gotoxy(45,45); printf("Student Record Management System");
gotoxy(19,22); printf("Enter username:");
gotoxy(35,22); gets(username);
gotoxy(19,24); printf("Enter password:");
gotoxy(35,24); gets(password);
}
//*******************************************************************
char admin(void)
{
char option;
clrscr();
gotoxy(14,2); printf("===================================================");
gotoxy(14,4); printf(" Administrator's Menu");
gotoxy(14,6); printf("===================================================");
gotoxy(14,10); printf("[1] --- Add a Student");
gotoxy(14,12); printf("[2] --- Modify a Student Account.");
gotoxy(14,14); printf("[3] --- Delete a Student Account.");
gotoxy(14,16); printf("[4] --- Display all Student Account Entries.");
gotoxy(14,18); printf("[5] --- Delete all Student Account Enrries.");
gotoxy(14,20); printf("[6] --- Logout");
gotoxy(14,22); printf("[7] --- Terminate Program.");
gotoxy(14,26); printf("===================================================");
gotoxy(14,30); printf("Please choose the task you want to perform.");
gotoxy(14,32); scanf("%c", &option);
return option;
}
//*******************************************************************
void add_student(STUDENT array[20])
{
int i = 0;
int empty;
char opt = 'y';
while(opt == 'y' && i < 19){
for(i = 0; i < 20; i++)
{
if(array[i].stud_num == 0)
{
empty = i;
break;
}
}
clrscr();
if(i >= 19)
{
gotoxy(14,2); printf("===================================================");
gotoxy(14,4); printf(" Enter account information");
gotoxy(14,6); printf("===================================================");
gotoxy(14,22); printf("===================================================");
gotoxy(14,32); printf("There are currently no free slots.");
gotoxy(14,26); printf("===================================================");
}
else
{
gotoxy(14,2); printf("===================================================");
gotoxy(14,4); printf(" Enter account information");
gotoxy(14,6); printf("===================================================");
gotoxy(14,22); printf("===================================================");
gotoxy(14,26); printf("===================================================");
gotoxy(16,9); printf("Student Number [Username]:");
gotoxy(16,13); printf("Name:");
gotoxy(16,15); printf("Birthdate:");
gotoxy(16,17); printf("Course:");
gotoxy(32,11); scanf("%lld", &array[empty].stud_num);
gotoxy(32,13); gets(array[empty].name); //try unya ang fgets(); if sakto na...
gotoxy(32,13); gets(array[empty].name);
gotoxy(32,15); gets(array[empty].bday);
gotoxy(32,17); gets(array[empty].course);
gotoxy(14,24); printf(" --- Account successfully created ---");
if(i >= 19)
{
clrscr();
gotoxy(14,2); printf("===================================================");
gotoxy(14,4); printf(" Enter account information");
gotoxy(14,6); printf("===================================================");
gotoxy(14,22); printf("===================================================");
gotoxy(14,24); printf("There are currently no free slots.");
gotoxy(14,26); printf("===================================================");
}
else
{
gotoxy(14,32); printf("Do you want to enter another account?");
gotoxy(14,33); printf("[y for yes, else no]");
gotoxy(14,35); opt = getche();
}
}
} // end of while loop
gotoxy(14,48); printf("<--- Redirecting to the Administrator's page...");
getche();
}
//*******************************************************************
void display_students(STUDENT array[20])
{
int i, j;
long long int temp;
clrscr();
gotoxy(6,2); printf("=====================================================================");
gotoxy(6,4); printf("STUDENT NUMBER");
gotoxy(25,4); printf("NAME");
gotoxy(45,4); printf("BIRTHDATE");
gotoxy(65,4); printf("COURSE");
gotoxy(6,6); printf("=====================================================================");
//for(i = 1; i <= 20 - 1; i++) /*passes*/
//{
// for(j = 0; j <= 20-2; j++) /*one pass*/
// {
// if(array[j].stud_num > array[j + 1].stud_num) /*one comparison*/
// {
// temp = array[j].stud_num; /*one swap*/
// array[j].stud_num = array[j + 1].stud_num;
// array[j + 1].stud_num = temp;
// }
// }
//}
for(j = 10, i = 0; array[i].stud_num != 0; j++, i++)
{
if(array[i].stud_num > 0)
{
gotoxy(6,j); printf("%lld", array[i].stud_num);
gotoxy(25,j); puts(array[i].name);
gotoxy(45,j); puts(array[i].bday);
gotoxy(65,j); puts(array[i].course);
}
}
gotoxy(6,j+2); printf("\=====================================================================");
gotoxy(6,48); printf("<----- Redirecting to the Administrator's Page...");
getche();
}
//*******************************************************************
void modify_student(STUDENT array[20])
{
int i;
long long int stud_num;
clrscr();
printf("\n\nPlease enter the student number of the account to be modified:\n\n");
scanf("%lld", &stud_num);
printf("\n\nSearching Student Account with Student Number %lld...", stud_num);
for(i = 0; i < 20; i++)
{
if(stud_num == array[i].stud_num)
break;
}
if(i >= 19)
{
printf("\n\nThe given student number did not match any of the existing accounts.\n");
printf("\n\nRedirecting to Administrator's Page...");
getche();
}
else
{
gotoxy(1,10); printf("=====================================================");
gotoxy(1,12); printf("Modifying the account of %s", array[i].name);
gotoxy(1,14); printf("=====================================================");
gotoxy(1,16); printf("Current Student Number: %lld", array[i].stud_num);
gotoxy(40,16); printf("New Student Number:");
scanf("%lld", &array[i].stud_num);
gotoxy(1,18); printf("Current Name: %s", array[i].name);
gotoxy(40,18); printf("New Name: ");
gets(array[i].name);
gets(array[i].name);
gotoxy(1,20); printf("Current Birthdate: %s", array[i].bday);
gotoxy(40,20); printf("New birthdate: ");
gets(array[i].bday);
gotoxy(1,22); printf("Current Course: %s", array[i].course);
gotoxy(40,22); printf("New Course: ");
gets(array[i].course);
printf("\n\n=====================================================");
printf("\n\nStudent account modified...");
printf("\n\nRedirecting to Administrator's Page...");
printf("\n\n=====================================================");
getche();
}
}
//*******************************************************************
/*void delete_student(STUDENT array[20])
{
printf("\n\nEnter the ");
}*/
//********************************************************************
/*void delete_all(STUDENT array[20])
{
}*/
//*******************************************************************