
| Turbo C - Database Program 3 |
|
#include<stdio.h> #include<conio.h> #include<string.h> /* Programmed by Harvey Losin */ /* http://www.bikoy.com/harvey */ /* webmaster@bikoy.com */ int count=0, entry=0; struct stude{ char name[30]; char id_no[10]; char course[10]; char year[10]; }whois[10]; main() { int choice, a; again: clrscr(); printf("n ============="); printf("n Menu:"); printf("n ============="); printf("n [1] Add"); printf("n [2] Browse"); printf("n [3] Change"); printf("n [4] Exit"); printf("n choice: "); choice=getch(); switch(choice) { case '1': add(); break; case '2': browse(); break; case '3': change(); break; case '4': printf("nnn Thank you for using my program!!!"); getch(); exit(); default: printf("nnn Invalid Choice!!! Try again..."); getch(); goto again; } } add() { clrscr(); printf("n ADD A RECORD: "); printf("nn You will be adding entry %d",count+1); printf("n Name: "); gets(whois[count].name); printf(" ID No.: "); gets(whois[count].id_no); printf(" Course: "); gets(whois[count].course); printf(" Year: "); gets(whois[count].year); printf("nn press any key to save..."); getch(); count=count+1; main(); } browse() { int option_browse, x; again: clrscr(); printf("n BROWSE RECORDS:"); printf("n [1] View All"); printf("n [2] By entry"); printf("n choice: "); option_browse=getch(); switch(option_browse) { case '1': { clrscr(); printf("n BROWSE ALL RECORDS:"); gotoxy(2,5); printf("NAME"); gotoxy(32,5); printf("ID NO."); gotoxy(42,5); printf("COURSE"); gotoxy(52,5); printf("YEAR"); for(x=0;x<10;x++) { gotoxy(2,7+x); printf("%s",whois[x].name); gotoxy(32,7+x); printf("%s",whois[x].id_no); gotoxy(42,7+x); printf("%s",whois[x].course); gotoxy(52,7+x); printf("%s",whois[x].year); } printf("nn press any key to go back to main menu..."); getch(); main(); } case '2': { int s, hits; char option, search[20]; hits=0; repeat: clrscr(); printf("n BROWSE INDIVIDUAL RECORDS"); printf("nn Browse by: "); printf("n [1] Name"); printf("n [2] ID Number"); printf("n > "); option=getch(); switch(option) { case '1': printf("nn Enter name to browse: "); gets(search); for(s=0;s<10;s++) { if(!strcmp(search,whois[s].name)) { printf("nn Entry %d:",s+1); printf("n Name : %s",whois[s].name); printf("n ID No.: %s",whois[s].id_no); printf("n Course: %s",whois[s].course); printf("n Year : %s",whois[s].year); hits=hits++; } } if(hits==0) { printf("nn No result found. n Press any key to go to Main Menu..."); getch(); main(); } getch(); main(); case '2': printf("nn Enter ID Number to browse: "); gets(search); for(s=0;s<10;s++) { if(!strcmp(search,whois[s].id_no)) { printf("nn Entry %d:",s+1); printf("n Name : %s",whois[s].name); textattr(14); printf("n ID No.: %s",whois[s].id_no); textattr(15); printf("n Course: %s",whois[s].course); printf("n Year : %s",whois[s].year); hits=hits++; } } if(hits==0) { printf("nn No result found. n Press any key to go to Main Menu..."); getch(); main(); } getch(); main(); default: goto repeat; } } default: goto again; } } change() { clrscr(); printf("n CHANGE A RECORD:"); printf("nn Enter entry no.: "); scanf("%d",&entry); entry=entry-1; |