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]);
//*******************************************************************
int main(void)
{
STUDENT array[20];
char username[50];
char password[50];
char option = '0';
char option2;
int i;
for(i = 0; i < 20; i++)
{
array[i].stud_num = 0;
}
clrscr();
login(username, password); //<------------------******HERE HERE HERE HERE*****
if(strcmp(username, "ADMIN") == 0 && strcmp(password, "admin") == 0)
{
while(option != '6')
{
option = admin();
switch(option)
{
case '1' :
{ clrscr();
printf("\n\nAdd Student Function is chosen.");
getche();
add_student(array);
break;
} //end of case '1'
case '4' :
{
clrscr();
printf("\n\nDisplay all Student Entries Function is chosen.");
getche();
display_students(array);
break;
} //end of case '4'
case '5' :
{
//******SUPPOSED TO BE LOGOUT******
}
case '6' :
{ printf("\n\nTerminating Program...");
break;
} //end of case '6'
default :
{ printf("\n\nInvalid option");
} //end of default
}
}
}
else if(strcmp(username, "quit") == 0 || strcmp(password, "quit") == 0)
{
gotoxy(19,24); printf("Terminating Program...");
getche();
return 0;
}
else
{
gotoxy(19,24); printf("Invalid username or password.");
}
//fclose(file);
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("to terminate program.");
gotoxy(45,45); printf("Student Record Management System");
gotoxy(19,18); printf("Enter username:");
gotoxy(35,18); gets(username);
gotoxy(19,20); printf("Enter password:");
gotoxy(35,20); gets(password);
}
//*******************************************************************
char admin(void)
{
char option;
clrscr();
printf("\n\n-----Welcome Administrator!!!-----\n");
printf("\n[1] --- Add a Student");
printf("\n[2] --- Modify a Student Account.");
printf("\n[3] --- Delete a Student Account.");
printf("\n[4] --- Display all Student Acount Entries.");
printf("\n[5] --- Logout");
printf("\n[6] --- Terminate Program.\n");
printf("\n\nPlease choose the task you want to perform.\n\n");
scanf("%c", &option);
return option;
}
//*******************************************************************
void add_student(STUDENT array[20])
{
int i;
int empty;
char opt = 'y';
while(opt == 'y'){
for(i = 0; i < 20; i++)
{
if(array[i].stud_num == 0)
{
empty = i;
break;
}
}
clrscr();
printf("\n==========================================");
printf("\n\nEnter profile information\n\n");
printf("==========================================");
printf("\n\nStudent Number [Username]:\t");
scanf("%lld", &array[empty].stud_num);
printf("\nName:\t\t");
gets(array[empty].name);
gets(array[empty].name);
printf("\nBirthdate:\t");
gets(array[empty].bday);
printf("\nCourse:\t\t");
gets(array[empty].course);
printf("\n\n=========================================");
printf("\n\nAccount created successfully.\n");
printf("\n=========================================");
printf("\n\nDo you want to enter another account?: [y for yes, else no]\n\n");
opt = getche(); }
printf("\n\nRedirecting to the Administrator's page...\n");
getche();
}
//*******************************************************************
void display_students(STUDENT array[20])
{
int i;
int j;
clrscr();
gotoxy(1,2); printf("=====================================================================");
gotoxy(1,4); printf("STUDENT NUMBER");
gotoxy(20,4); printf("NAME");
gotoxy(40,4); printf("BIRTHDATE");
gotoxy(60,4); printf("COURSE");
gotoxy(1,6); printf("=====================================================================");
for(j = 8, i = 0; array[i].stud_num != 0; j = j+2, i++)
{
gotoxy(1,j); printf("%lld", array[i].stud_num);
gotoxy(20,j); puts(array[i].name);
gotoxy(40,j); puts(array[i].bday);
gotoxy(60,j); puts(array[i].course);
}
printf("\n\n=====================================================================");
printf("\n\nRedirecting to the Administrator's Page...\n");
getche();
}
//*******************************************************************