ics 103 project

32
ICS 103 – Project Title: Personal Scheduler Management System 1. Project Description In this project, the student will develop a modular based application using C language. The application should be protected by a password since it will have records of a personal memoranda. The application starts by shown a menu with its maximum functionality as following: - Set Password ( appears only the first time the system runs ) - Edit Password - Add new Memoranda o Add new record o Edit record o View all contents (table form) o Delete record ( needs password – approval) - View Previous Memoranda o Open By date o Open By Order - Exit Note: The above list is tentative, so we may need to add or remove from it as needed. The first item in the menu list is appears only if the program being used for the first time by the super-user (administrator). So, if the application is run for the second time that item list should not appear. The super-user can create user-names and passwords for new users (only if the system is multi-user). The memoranda are stored as separate text files. Each file, will contain several records as needed by the user of the application. Several operations can be performed by the application on memoranda such as adding, editing, viewing and deleting. Pervious memoranda can be searched using dates or order.

Upload: hashem-zaitooni

Post on 09-Feb-2017

18 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: ICS 103 Project

ICS 103 – Project Title: Personal Scheduler Management System 1. Project Description In this project, the student will develop a modular based application using C language. The application should be protected by a password since it will have records of a personal memoranda. The application starts by shown a menu with its maximum functionality as following: - Set Password ( appears only the first time the system runs )

- Edit Password

- Add new Memoranda

o Add new record

o Edit record

o View all contents (table form)

o Delete record ( needs password – approval) - View Previous Memoranda

o Open By date

o Open By Order - Exit Note: The above list is tentative, so we may need to add or remove from it as needed.

The first item in the menu list is appears only if the program being used for the first time by the

super-user (administrator). So, if the application is run for the second time that item list should not

appear. The super-user can create user-names and passwords for new users (only if the system is

multi-user). The memoranda are stored as separate text files. Each file, will contain several records as

needed by the user of the application. Several operations can be performed by the application on

memoranda such as adding, editing, viewing and deleting. Pervious memoranda can be searched using

dates or order.

Page 2: ICS 103 Project

Program Code: #include<stdio.h>

#include<stdlib.h>

#include<conio.h>

#include<string.h>

#define SIZE 20

#define TITLES 20

#define PLACES 15

#define TIMES 22

#define DESS 100

void main_menu (void);

void set_password(void);

void edit_Password(void);

void add_new_schedule(void);

void view_previous_schedule(void);

void help(void);

void entering_username_and_password(void);

void cheking_username_and_password(void);

void choosing_among_main_menu_and_main_menu_after_setting_username_and_password(void);

void main_menu_after_setting_password(void);

void addRec(char file[],int size);

void editRec (char namesch [],int size);

void delRec (char namesch [],int size);

void vRec (char namesch [],int size);

void bydate ();

void byorder ();

void calling();

Page 3: ICS 103 Project

int main(){

cheking_username_and_password();

getch();

return 0;

}

void main_menu (void){

char c;

printf(" .=====================================================.\n");

printf(" THIS PROGRAM IS KEEPING PERSONAL RECORD OF ITS USERS\n");

printf(" .=====================================================.\n");

printf("\n\n\n Main menu:\n");

printf(" ----------\n");

printf(" Set Password [1]\n");

printf(" Edit Password [2]\n");

printf(" Add New Schedule [3]\n");

printf(" View Previous Schedule [4]\n");

printf(" Help [5]\n");

printf(" Exit [6]\n");

printf("\n\n please select from the list(1,2,3,4,5 or 6):[ ]\b\b");

Page 4: ICS 103 Project

c = getch();

printf("%c",c);

printf("\n\n \t \t");

system("pause");

system("cls");

switch(c){

case '1': set_password();

break;

case '2': edit_Password();

break;

case '3': add_new_schedule();

break;

case '4': view_previous_schedule();

break;

case '5': help();

break;

case '6': exit(0);

break;

default:

{

printf("\nWrong input! please choose again\n");

system("pause");

system("cls");

main_menu();

}

}

Page 5: ICS 103 Project

}

void set_password(void) {

FILE *username,*password;

char U[SIZE],P1[SIZE],P2[SIZE], c;

int i, f,a=3,P[SIZE];

username = fopen("UN.txt","w");

password = fopen("PW.txt","w");

for(i=0 ; a != 0 ; i++){

printf("\nEnter the username :\n");

scanf("%s",&U);

system("cls");

fprintf(username,"%s",U);

printf("\nEnter the password:\n");

for(f=0;f<SIZE;f++)

{

P1[f]=getch();

if(P1[f]==13)

{

P1[f]='\0';

break;

}

else

Page 6: ICS 103 Project

{

printf("*");

}

}

system("cls");

fprintf(password,"%s",P1);

fclose(password);

printf("\nRe enter the password:\n");

for(f=0;f<SIZE;f++)

{

P2[f]=getch();

if(P2[f]==13)

{

P2[f]='\0';

break;

}

else

{

printf("*");

}

}

system("cls");

fprintf(password,"%s",P2);

fclose(username);

a = strcmp(P1,P2);

if(a == 0) {

Page 7: ICS 103 Project

printf("\nusername and password are set secsussfully\n");

main_menu_after_setting_password();

}

else printf("\nThe inputs does not match! try again\n");

}

}

void edit_Password(void) {

int a=1,b,c,d,i,f;

char UN[SIZE],OP[SIZE],NP[SIZE],NP2[SIZE],SUN[SIZE],SOP[SIZE];

FILE *username,*password;

username = fopen("UN.txt","r");

password = fopen("PW.txt","r");

if(username == NULL || password == NULL){set_password();}

else {

for(i=0 ; a!=0 || b!=0 || c!=0 || d==0 ; i++){

printf("\nEnter the username:\n");

Page 8: ICS 103 Project

scanf("%s",&UN);

printf("\nEnter the old password:\n");

for(f=0;f<SIZE;f++)

{

OP[f]=getch();

if(OP[f]==13)

{

OP[f]='\0';

break;

}

else

{

printf("*");

}

}

printf("\nEnter the new password:\n");

for(f=0;f<SIZE;f++)

{

NP[f]=getch();

if(NP[f]==13)

{

NP[f]='\0';

break;

}

else

{

Page 9: ICS 103 Project

printf("*");

}

}

printf("\nRe enter the new password:\n");

for(f=0;f<SIZE;f++)

{

NP2[f]=getch();

if(NP2[f]==13)

{

NP2[f]='\0';

break;

}

else

{

printf("*");

}

}

fscanf(username,"%s",&SUN);

fscanf(password,"%s",&SOP);

a=strcmp(UN,SUN);

b=strcmp(OP,SOP);

c=strcmp(NP,NP2);

d=strcmp(OP,NP);

Page 10: ICS 103 Project

fclose(username);

fclose(password);

if(a!=0 && b!=0){printf("\nBoth the username and the password you entered are not correct! please try

again\n");}

else if(a!=0){printf("\nThe username entered is incorrect! please try again\n");}

else if(b!=0){printf("\nThe password entered is incorrect! please try again\n");}

else if(c!=0){printf("\nThe two passwords does not match! please try again\n");}

else if(d==0){printf("\nThe new password matches the old one! please try again\n");}

else{ printf("\nThe password has changed secsussfully\n");password = fopen("PW.txt","w");

fprintf(password,"%s",NP); fclose(password);}

system("pause");

system("cls");

}

main_menu_after_setting_password();

}}

void add_new_schedule(void) {

char c , filename[30];

Page 11: ICS 103 Project

do{

printf("\n\n .=====================================================.\n");

printf(" THIS PROGRAM IS KEEPING PERSONAL RECORD OF ITS USERS\n");

printf(" .=====================================================.\n");

printf("\n\n\n Add New Schedule:\n");

printf(" ---------------\n");

printf(" Add new record [1]\n");

printf(" Edit record [2]\n");

printf(" View all contents [3]\n");

printf(" Delete record [4]\n");

printf(" Back [5]\n");

printf("\n\n please select from the list(1,2,3,4,5 or 6):[ ]\b\b");

c = getch();

printf("%c",c);

printf("\n\n \t \t");

system("pause");

system("cls");

switch(c){

case '1': addRec(filename,30);

break;

case '2': editRec(filename,30);

break;

case '3': vRec(filename,30);

break;

case '4': delRec(filename,30);

break;

Page 12: ICS 103 Project

case '5':

choosing_among_main_menu_and_main_menu_after_setting_username_and_password();

break;

default:

{

printf("\nWrong input! please choose again\n");

system("pause");

system("cls");

calling();

}

}

}

while(c>=0);

}

void view_previous_schedule(void) {

char c;

do{

printf("\n\n .=====================================================.\n");

printf(" THIS PROGRAM IS KEEPING PERSONAL RECORD OF ITS USERS\n");

printf(" .=====================================================.\n");

printf("\n\n\n View Previous Schedule:\n");

printf(" -----------------\n");

printf(" Open by data [1]\n");

printf(" Open by order [2]\n");

printf(" Back [3]\n");

Page 13: ICS 103 Project

printf("\n\n please select from the list(1,2,3,4,5 or 6):[ ]\b\b");

c = getch();

printf("%c",c);

printf("\n\n \t \t");

system("pause");

system("cls");

switch(c){

case '1': bydate();

break;

case '2': byorder ();

break;

case '3':

choosing_among_main_menu_and_main_menu_after_setting_username_and_password();

break;

default:

{

printf("\nWrong input! please choose again\n");

system("pause");

system("cls");

view_previous_schedule();

}

}

}

while(c>=0);

}

void help(void) {

Page 14: ICS 103 Project

printf("\n\n*About the programmer: Name: hashem zaitooni, Email:

[email protected]\n\nAdress: KSA, eastern province, Dhahran, KFUPM, BLDG:851,

ROOM:231.");

printf("\n\n*About the program:\n\nTitle:Personal Scheduler Management System\n\nFunctionality:In

this program, the user will enjoy using\na modular based application that saves all records of personal

chronicles.\n\n");

printf("\n ------_\n");

printf(" | -.\n");

printf(" | _-\n");

printf(" ZTN__-\n");

printf(" |\n");

printf(" ____|\n");

printf("\n\nPress any key to return to main menu...\n\n");

system("pause");

system("cls");

choosing_among_main_menu_and_main_menu_after_setting_username_and_password();

}

void entering_username_and_password(void){

int a,b,i,j,c,f;

char U[SIZE],P[SIZE],US[SIZE],PS[SIZE];

FILE *check1,*check2;

b=1;

Page 15: ICS 103 Project

j=4;

for(i=0;a != 0 || b !=0 ;i++){

check1 = fopen("UN.txt","r");

fscanf(check1,"%s",&US);

printf("\nEnter the username:\n");

for(f=0; f<SIZE ;f++){

scanf("%c",&U[f]);

if(U[f] == 't' || U[f] == 'T'){exit(1);}

else if(U[f] == '\n'){

U[f]='\0';

break;}}

a = strcmp(US,U);

system("cls");

check2 = fopen("PW.txt","r");

fscanf(check2,"%s",&PS);

printf("\nEnter the password:\n");

for(f=0;f<SIZE;f++){

P[f]=getch();

Page 16: ICS 103 Project

if(P[f]==13){

P[f]='\0';

break;}

else{printf("*");}}

system("cls");

b = strcmp(PS,P);

if((a != 0 || b != 0) && (j != 1))printf("\nwrong username or password! %d attempts left <T to

terminate>\n",j-1);

j--;

if(j==0) exit(1);

else if(a==0 && b==0) main_menu_after_setting_password();

}}

void cheking_username_and_password(void){

char U[SIZE],P[SIZE];

FILE *check1,*check2;

check1 = fopen("UN.txt","r");

check2 = fopen("PW.txt","r");

fscanf(check1,"%s",&U);

fscanf(check2,"%s",&P);

Page 17: ICS 103 Project

if(check1 == NULL || check1 == NULL)

main_menu();

else

entering_username_and_password();

}

void main_menu_after_setting_password(void){

char c;

printf("\n\n .=====================================================.\n");

printf(" THIS PROGRAM IS KEEPING PERSONAL RECORD OF ITS USERS\n");

printf(" .=====================================================.\n");

printf(" Edit Password [1]\n");

printf(" Add New Schedule [2]\n");

printf(" View Previous Schedule [3]\n");

printf(" Help [4]\n");

printf(" Exit [5]\n");

printf("\n\n please select from the list(1,2,3,4,5 or 6):[ ]\b\b");

c = getch();

printf("%c",c);

printf("\n\n \t \t");

system("pause");

Page 18: ICS 103 Project

system("cls");

switch(c){

case '1': edit_Password();

break;

case '2': add_new_schedule();

break;

case '3': view_previous_schedule();

break;

case '4': help();

break;

case '5': exit(0);

break;

default:

{

printf("\nWrong input! please choose again\n");

system("pause");

system("cls");

main_menu_after_setting_password();

}

}

}

void choosing_among_main_menu_and_main_menu_after_setting_username_and_password(void){

char U[SIZE],P[SIZE];

Page 19: ICS 103 Project

FILE *check1,*check2;

check1 = fopen("UN.txt","r");

check2 = fopen("PW.txt","r");

fscanf(check1,"%s",&U);

fscanf(check2,"%s",&P);

if(check1 == NULL || check1 == NULL) {main_menu();}

else {main_menu_after_setting_password();}

}

void addRec(char file[],int size){

int i,x;

char title[TITLES],place[PLACES],time[TIMES],des[DESS],ext[4]={".txt"};

FILE *outfile,*schname;

fseek(stdin,0,SEEK_END);

do{

system("cls");

printf("Enter the schedual name like (12-31-2015)\n");

gets(file);

strcat(file,ext);

}while(strstr(file,".txt")==NULL);

outfile=fopen(file,"a");

schname=fopen("schname.txt","a");

fprintf(schname,"%s\n",file);

fclose(schname);

Page 20: ICS 103 Project

do{

system("cls");

i=0;

printf("Enter the title:\n");

fseek(stdin,0,SEEK_END);

gets(title);

system("cls");

++i;

printf("Enter the place:\n");

gets(place);

system("cls");

++i;

printf("Enter the time:\n");

gets(time);

system("cls");

++i;

printf("Enter the description:\n");

gets(des);

system("cls");

++i;

i=0;

fprintf(outfile,"%s\t",title);

fprintf(outfile,"%s\t",place);

fprintf(outfile,"%s\t",time);

fprintf(outfile,"%s\t",des);

fprintf(outfile,"\n");

Page 21: ICS 103 Project

printf("Enter -1 to go back or any other value to continue\n");

scanf("%d",&x);

}while (x!=-1);

fclose(outfile);

}

void editRec (char namesch [],int size){

FILE *infile,*outfile;

int i=0,k=0,j=0,numline;

char *p, *status,title[100][TITLES],place[100][PLACES],time[100][TIMES],des[100][DESS],

file[100][200];

infile=fopen(namesch,"r");

if(infile!=NULL){

for (status = fgets(file[j], 200, infile); status != NULL; status =

fgets(file[j], 200, infile))

++j;

system("cls");

p = strtok(file[0],"\t");

strcpy(title[0],p);

while ( p!=NULL ){

Page 22: ICS 103 Project

p=strtok(NULL,"\t");

strcpy(place[i],p);

p=strtok(NULL,"\t");

strcpy(time[i],p);

p=strtok(NULL,"\t");

strcpy(des[i],p);

i++;

if (i < j)

p = strtok(file[i],"\t");

else

break;

strcpy(title[i],p);

}

printf ("\tNum Title\t\t\tPlace\t\tTime\t\t\ Description\n");

for(k=0;k<i;k++){

printf("\t%-3d %-20s\t%-15s%-22s%-100s\n",k+1,title[k],place[k],time[k],des[k]);

}

do{

printf("\n\nPlease enter the number of the line you you want to edit(or -1 to go back)\n");

scanf ("%d",&numline);

}while(!((numline>0&&numline<=j)||numline==-1));

if (numline!=-1){

Page 23: ICS 103 Project

printf("Enter the title:\n");

fseek(stdin,0,SEEK_END);

gets(title[numline-1]);

printf("Enter the place:\n");

gets(place[numline-1]);

printf("Enter the time:\n");

gets(time[numline-1]);

printf("Enter the description:\n");

gets(des[numline-1]);

outfile=fopen(namesch,"w");

for(i=0;i<j;i++){

fprintf(outfile,"%s\t",title[i]);

fprintf(outfile,"%s\t",place[i]);

fprintf(outfile,"%s\t",time[i]);

fprintf(outfile,"%s\t\n",des[i]);

}

system("cls");

fclose(outfile);

fclose (infile);

}

}

}

void delRec (char namesch [],int size){

FILE *infile,*outfile;

Page 24: ICS 103 Project

int i=0,k=0,j=0,numline;

char *p, *status,title[100][TITLES],place[100][PLACES],time[100][TIMES],des[100][DESS],

file[100][200];

infile=fopen(namesch,"r");

if(infile!=NULL){

for (status = fgets(file[j], 200, infile); status != NULL; status =

fgets(file[j], 200, infile))

++j;

system("cls");

p = strtok(file[0],"\t");

strcpy(title[0],p);

while ( p!=NULL ){

p=strtok(NULL,"\t");

strcpy(place[i],p);

p=strtok(NULL,"\t");

strcpy(time[i],p);

p=strtok(NULL,"\t");

strcpy(des[i],p);

i++;

if (i < j)

p = strtok(file[i],"\t");

Page 25: ICS 103 Project

else

break;

strcpy(title[i],p);

}

printf ("\tNum Title\t\t\tPlace\t\tTime\t\t\Description\n");

for(k=0;k<i;k++){

printf("\t%-3d %-20s\t%-15s%-22s%-100s\n",k+1,title[k],place[k],time[k],des[k]);

}

do{

printf("\n\nPlease enter the number of the line you you want to delete(or -1 to go back)\n");

scanf ("%d",&numline);

}while(!((numline>0&&numline<=j)||numline==-1));

if (numline!=-1){

outfile=fopen(namesch,"w");

for(i=0;i<j;i++){

if (i!=(numline-1)){

fprintf(outfile,"%s\t",title[i]);

fprintf(outfile,"%s\t",place[i]);

fprintf(outfile,"%s\t",time[i]);

fprintf(outfile,"%s\t",des[i]);

fprintf(outfile,"\n");

}

}

Page 26: ICS 103 Project

fclose(outfile);

fclose (infile);

printf("\nPress any key to go to the previous menu");

getch();

system("cls");

}

}

}

void vRec (char namesch [],int size){

FILE *infile,*outfile;

int i=0,k=0,j=0,numline;

char *p, *status,title[100][TITLES],place[100][PLACES],time[100][TIMES],des[100][DESS],

file[100][200];

infile=fopen(namesch,"r");

if(infile!=NULL){

for (status = fgets(file[j], 200, infile); status != NULL; status =

fgets(file[j], 200, infile))

++j;

system("cls");

p = strtok(file[0],"\t");

strcpy(title[0],p);

Page 27: ICS 103 Project

while ( p!=NULL ){

p=strtok(NULL,"\t");

strcpy(place[i],p);

p=strtok(NULL,"\t");

strcpy(time[i],p);

p=strtok(NULL,"\t");

strcpy(des[i],p);

i++;

if (i < j)

p = strtok(file[i],"\t");

else

break;

strcpy(title[i],p);

}

printf ("\tNum Title\t\t\tPlace\t\tTime\t\t\ Description\n");

for(k=0;k<j;k++){

printf("\t%-3d %-20s\t%-15s%-22s%-100s\n",k+1,title[k],place[k],time[k],des[k]);

}

printf("\nPress any key to go to the previous menu");

getch();

system("cls");

Page 28: ICS 103 Project

}

}

int viewPreSch (){

int x;

do{

system("cls");

printf("\n\n\n

.======================================================.\n");

printf(" THIS PROGRAM IS KEEPING PERSONAL RECORDS OF ITS

USERS\n") ;

printf("

.======================================================.\n\n\n");

printf(" View Previous Schedule:\n");

printf(" ----------------------\n");

printf(" open by date [1]\n");

printf(" open by order [2]\n");

printf(" Back [3]\n\n");

printf(" Please select from the list <1,2 or 3>: [ ]\b\b\b");

scanf("%d", &x);

switch(x)

{

case 1:bydate();

Page 29: ICS 103 Project

break;

case 2:byorder ();

break;

case 3:

break;

}

}while(x!=3);

}

void bydate (){

FILE *infile=fopen("schname.txt","r"),*insch;

char schname [100][30];

int i=0,j=0,x;

while (fscanf(infile,"%s",schname[i])!=EOF)

i++;

system("cls");

printf("\tNum\tSchedual\n");

for(j=0;j<i;j++){

printf("\t%d\t",j+1);

puts(schname[j]);

}

printf("\nEnter the numeber of the schedule you want to view : ");

do{

Page 30: ICS 103 Project

scanf("%d",&x);

}while (!(x>0&&x<=i));

system("cls");

vRec(schname[x-1],j);

fclose(infile);

}

void byorder (){

FILE *infile=fopen("schname.txt","r"),*insch;

char *temp,*status,schname [100][30],file[100][200],*sort[100];

int x,max,k,tempo,i,fill,schnum=0,j=0,recnum=0,order[100];

while (fscanf(infile,"%s",schname[schnum])!=EOF)

schnum++;

fclose(infile);

for (j=0;j<schnum;j++){

recnum=0;

infile=fopen(schname[j],"r");

for (status = fgets(file[recnum], 200, infile); status != NULL; status

= fgets(file[recnum], 200, infile))

++recnum;

order[j]=recnum;

}

for(k=0;k<schnum;k++){

Page 31: ICS 103 Project

sort[k]=schname[k];

}

for (fill=0;fill<schnum-1;fill++){

max=fill;

for(i=fill+1;i<=schnum-1;i++){

if(order[i]>order[max])

max=i;

}

if(max!=fill){

tempo=order[max];

order[max]=order[fill];

order[fill]=tempo;

temp=sort[max];

sort[max]=sort[fill];

sort[fill]=temp;

}

}

system ("cls");

printf("\tNum\t\tSchedual\t\tRecords\n");

for(k=0;k<schnum;k++)

printf("\t%d\t\t%s\t\t%d\n",k+1,sort[k],order[k]);

printf("Select the schedual you want to view : ");

scanf("%d",&x);

vRec(sort[x],order[x]);

}

void calling(){

Page 32: ICS 103 Project

add_new_schedule();

}