/*Computer Science Internal Assesment
David Gardner Grade 13-c
Ms. A. Jones
Karate Registration System
Last Modification Date: 01/03/10 01:39*/
#include <stdio.h>//Standard library files for standard input and output functions
#include <conio.h>/*Common Input and Output functions & Functions for
manipulating strings#include <stdio.h>*/
#include <stdlib.h>//other miscellanous standard library functtions
#include <string.h>//standard libraray functions for strings
#define MAX 25//define array length for structures
#define size 90000000//define max number of characters something can store
int i;//global variable used as a counter variable
int numstud;
struct student//structure to hold student non numerical data
{
char fname[25],midname[25],lname[25],gender[10],bltrank[10];
}stu[MAX];
struct numdata//structure to hold student numerical data
{
int age,year,id,gen,quu;//gen variable used to hold numerical input for gender[see regmode()
}num[MAX];
void header();//function to create a header in the screen display
void login();//function to request password from user
void menu();//funtion to list the main menu of the program
void regmode();//function used to input data of registering students
void viewmode();//funtion used to view the stored data of the organization
void setup();//function used to set the password and for the I.D. funtion to word
int idnum(int x);//creates an I.D. number for each entry
main(void)//start of the program
{
header();
printf("\n\tWelcome to the Jamaica Karate Club Registration System.");
login();
system("cls");//function in stdlib.h to clear the screen
menu();
getch();
}
void header()
{// "\t" used for tab
printf("\n\t\t\t||~~~~~~~~~~~~~~~~~~~~~~~~~||\n");
printf("\t\t\t||~~FUTURE LEADERS EAGLES~~||\n");
printf("\t\t\t||~~~~KARATE CLUB & GYM~~~~||\n");
printf("\t\t\t||~~~~~~~~~~~~~~~~~~~~~~~~~||\n");
}
void login()
{
char pwrd[20],xwrd[20];
FILE *passcheck;//using a pointer to reference to a file
passcheck = fopen("syspass","r");//opening the file in READ mode
if(passcheck==NULL)//Checking if the file is empty
{
system("cls");
menu();
}
else//if file contains data do.....
{
printf("\nEnter Password: ");
scanf("%s",&pwrd);
fscanf(passcheck,"%s",xwrd);//scans data from file into a variable
int z=3;
while(strcmp(pwrd,xwrd)!=0)/*strcmp used to cpmare the input data with
the data from the file...while they are not
the same (!=0) do.....*/
{
printf("\nIncorrect Password...try again\n");
scanf("%s",&pwrd);
z-=1;
if(z == 0)//password login attempts are used up
{
printf("\nAccess Denied\n");
system("pause");
exit(0);
}
}
system("cls");
menu();
}
fclose(passcheck);//closing the file
}
void menu()
{
int q;
header();
printf("\n\nMenu Selection Items:");
printf("\n\t~[1]Register\n\t~[2]View\n\t~[3]Setup\n\t~[4]Exit\n");
scanf("%d",&q);
system("cls");
switch (q)//C function used to choose a specific operation per input
{
case 1: printf("\n\t\t\t||Registration Mode||\n\n");
regmode();//launch regmode
break;
case 2: viewmode();//launch viewmode
break;
case 3: printf("\n\t\t\t||Setup Mode||\n\n");
setup();//launch setup
break;
case 4: printf("\n\t\t\tTermination Mode\n\n\t\tGoodbye\n\n");
system("pause");
exit(0);//closes program
break;
default: printf("\n\nInvalid Code...Try Again\n\n");
system("pause");
break;//if input is not 1,2,3 or 4....input again
}
}
void regmode()
{
int fcnt=0,mcnt=0,save;
header();
printf("\n How many students are you registering?\n");
scanf("%d",&numstud);//user inputs the number of students to register and program loops to that number
for(i=0;i<numstud;i++)
{
system("cls");
header();
printf("\n\tStudent # %d\n\n",i+1);
printf("Enter Name [Format: First Middle Last] \n");
scanf("%s %s %s",&stu[i].fname,&stu[i].midname,&stu[i].lname);
printf("\nStudent's Age: ");
scanf("%d",&num[i].age);
num[i].quu=3;//assign quu a value...if below conditions are met quu value is decreased
if(num[i].age>20)
{
num[i].quu-=2;
}
if(num[i].age<20 && num[i].age>12)
{
num[i].quu-=1;
}
printf("\nGender Male[1],Female[2] ");
scanf("%d",&num[i].gen);
while(num[i].gen>2||num[i].gen<1)//if statement to propmt user to re enter code if number does not match
{
printf("\nIncorrect input...try again\n");
scanf("%d",&num[i].gen);
}
if(num[i].gen==1)
{
strcpy(stu[i].gender,"Male");/*strcpy allows for a string to be coppied into
into string variable based on input*/
mcnt=mcnt + 1;//male count to keep record of number of males registered per session
}
if(num[i].gen==2)
{
strcpy(stu[i].gender,"Female");
fcnt= fcnt + 1;//fcnt: female count to keep record of number of female inputs during registration
}
printf("\nCurrent Belt Rank: ");
scanf("%s",&stu[i].bltrank);
printf("\nYear Training Comenced: ");
scanf("%d",&num[i].year);
system("cls");
header();
printf("\n\nIdentification: JKC%d\n",idnum(num[i-1].id));
printf("\nStudent Name: %s, %s %s",stu[i].lname,stu[i].fname,stu[i].midname);
printf("\nStudent's Age: %d",num[i].age);
printf("\nQuu: %d",num[i].quu);
printf("\nGender: %s",stu[i].gender);
printf("\nBelt Rank: %s",stu[i].bltrank);
printf("\nYear Training Comenced: %d",num[i].year);
printf("\n\nSave:[1]\tStart Over[2]");
scanf("\n%d", &save);
while(save<1||save>2)
{
printf("\nPlease Choose 1 or 2");
scanf("%d",&save);
}
if(save==1)
{//save the data input to a file
FILE *ptr;
ptr=fopen("student_data.txt","a+");
fprintf(ptr,"Identification: JKC%d\n",idnum(num[i].id));
fprintf(ptr,"\nName: %s %s %s\n",stu[i].lname, stu[i].fname, stu[i].midname);
fprintf(ptr,"Age: %d\n",num[i].age);
fprintf(ptr,"Gender: %s\n",stu[i].gender);
fprintf(ptr,"Belt Rank: %s\n",stu[i].bltrank);
fprintf(ptr,"QUU Level: %d\n",num[i].quu);
fprintf(ptr,"Year Training Commenced: %d\n\n",num[i].year);
fclose(ptr);
system("cls");
}
else if(save ==2)
{
system("pause");
system("cls");
regmode();
}
}
printf("\n\nRegistration Complete....For Now =>");
printf("\nTotal Number Of Males Registered: %d",mcnt);
printf("\nTotal Number Of Females Registered: %d",fcnt);
printf("\nThank You & Please Enjoy Your Day\n\n");
FILE *femct;//file pointer to store number of females in system
femct=fopen("female.txt","r");
if(femct==NULL)//if the file is empty, the number will simply be added to it.
{
femct=fopen("female.txt","w");
fprintf(femct,"%d",fcnt);
}
else
{
int fem;
femct=fopen("female.txt","r");
fscanf(femct,"%d",&fem);
fcnt=fcnt+fem;
femct=fopen("female.txt","w");
fprintf(femct,"%d",fcnt);
}
fclose(femct);
FILE *memct;//file pointer to store number of males in system
memct=fopen("male.txt","r");
if(memct==NULL)//if the file is empty, the number will simply be added to it.
{
memct=fopen("male.txt","w");
fprintf(memct,"%d",mcnt);
}
else
{
int mem;
memct=fopen("male.txt","r");
fscanf(memct,"%d",&mem);
mcnt=mcnt+mem;
memct=fopen("male.txt","w");
fprintf(memct,"%d",mcnt);
}
fclose(memct);
system("pause");
system("cls");
menu();
}
void viewmode()
{
header();
int vchoice;
printf("\n\t\t\t||View Mode Options||\n");
printf("\n~[1]Full Database\n~[2]Search Student\n~[3]Back To Menu\n");
scanf("%d",&vchoice);
system("cls");
switch(vchoice)
{
case 1: printf("\n\t\t\t||Full Database||\n\n");
char page[size+1];//enables file characters to be stored due to size constant
FILE *vptr;//file pointer to: fptr
vptr=fopen("student_data.txt","r");//opens file student_data.txt in different pointer in read only mode
if(vptr==NULL)
{
/*"\a" below listed to make terminal beep...
this IF statement is to alert user incase there is no file*/
printf("\n\n\a\t\tNo File Listed---->Create File First\n");
system("pause");
system("cls");
header();
menu();
}
while(!feof(vptr))
{
fgets(page,size,vptr);
printf("\t%s",page);
}
system("pause");
system("cls");
menu();
break;
case 2: printf("\n\nEnter Last Name:\n");
printf("\nComing soon");//incomplete function
viewmode();
break;
case 3: menu();
break;
default: printf("\n\nInvalid Code...Try Again\n\n");
system("pause");
break;
}
}
int idnum(int x)
{
int idset = 0 ,d;
FILE *idrun;
idrun=fopen("id.txt","r");
fscanf(idrun,"%d",&idset);//scans the number in the id.txt into variable.
d=idset;
x = 1040+d;
idset++;
idrun=fopen("id.txt","w");
fprintf(idrun,"%d",idset);
fclose(idrun);
return x;
}
void setup()
{
int select;
header();
printf("\n\n~[1]New Password\n~[2]I.D. Setup\n~[3]Back To Menu\n");
scanf("%d",&select);
system("cls");
switch(select)
{
case 1:
header();
char pword[20],pword2[20];
printf("\n\nNew Password: ");
scanf("%s",&pword);
system("cls");
printf("\nEnter Password Again ");
scanf("%s",&pword2);
if(strcmp(pword,pword2)==0)
{
FILE *password;
password = fopen("syspass","w");
fprintf(password,"%s",pword);
fclose(password);
system("cls");
printf("\nPassword Accepted\n");
system("pause");
system("cls");
menu();
}
else
{
printf("Inconsistent Data Entered....try again\n");
system("pause");
system("cls");
setup();
}
break;
case 2:header();//must be the 1st thing done when system is implimented
printf("\nIdentification Code Setup Function\n");
int setid;
FILE *idcheck;
idcheck=fopen("id.txt","r");
if(idcheck==NULL)
{
printf("Identification Code Needed\n Press 1 or 0\n");
scanf("%d",&setid);
idcheck=fopen("id.txt","w");
fprintf(idcheck,"%d",setid);
fclose(idcheck);
}
system("pause");
menu();
break;
case 3: menu();
break;
default: printf("\nInvalid Code....Please try Again\n");
system("pause");
system("cls");
setup();
break;
}
}